Nightwatch tests cannot run within lando environment

Created on 16 September 2024, 2 months ago

Problem/Motivation

Nightwatch will not run tests in a lando/docker environment because docker does not have `sudo`

Steps to reproduce

Follow Lando-docker-nightwatch setup:
Insert into lando.yml

appserver:
    webroot: docroot
    build_as_root:
      # Nightwatch config
      - curl -sL https://deb.nodesource.com/setup_18.x | bash -
      - apt-get install -y nodejs
      - npm install -g yarn
    run:
      - mkdir -p private/browsertest_output
      - yarn add @nightwatch/vrt --cwd /app/docroot/core
      - yarn install --non-interactive --cwd /app/docroot/core
    overrides:
      environment:
        # Support debugging CLI with Xdebug.
        PHP_IDE_CONFIG: "serverName=appserver"
        # nightwatch config
        SIMPLETEST_BASE_URL: "http://mysite.lndo.site/"
        SIMPLETEST_DB: "sqlite://localhost/tmp/db.sqlite"
        BROWSERTEST_OUTPUT_DIRECTORY: '/app/docroot/sites/simpletest/browser_output'
        BROWSERTEST_OUTPUT_BASE_URL: 'http://mysite.lndo.site'
        MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless"]}}, "http://chrome:9515"]'        # Nightwatch
        DRUPAL_TEST_BASE_URL: 'http://mysite.lndo.site'
        DRUPAL_TEST_DB_URL: 'mysql://drupal10:drupal10@database:3306/drupal10'
        DRUPAL_TEST_WEBDRIVER_HOSTNAME: chrome
        DRUPAL_TEST_WEBDRIVER_PORT: 9515
        DRUPAL_TEST_CHROMEDRIVER_AUTOSTART: 'false'
        DRUPAL_TEST_WEBDRIVER_CHROME_ARGS: "--disable-gpu --headless --no-sandbox"
        DRUPAL_NIGHTWATCH_OUTPUT: reports/nightwatch
        DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES: node_modules,vendor,.*,sites/*/files,sites/*/private,sites/simpletest
  chrome:
    type: compose
    scanner: false
    app_mount: false
    services:
      image: drupalci/chromedriver:production
      expose:
        - "9515"
        - "4444"
      volumes:
        - /dev/shm:/dev/shm
      security_opt:
        - seccomp:unconfined
      command: ["chromedriver",  "--log-path=/tmp/chromedriver.log", "--verbose", "--allowed-ips=", "--allowed-origins=*", "--whitelisted-ips="]
# Custom Lando commands
tooling:
  npm:
    service: appserver
  node:
    service: appserver
  gulp:
    service: appserver
  yarn:
    service: appserver
    cmd: yarn

In docroot/core copy and rename .env.example to .env and set appropriate variables if desired.

In terminal move to core directory cd docroot/core
Install modules lando yarn install

Run a single test `lando yarn test:nightwatch tests/Drupal/Nightwatch/Tests/loginTest.js`

Expected results

test would not error with /bin/sh: 1: sudo: not found

Proposed resolution

Add variable to .env and boolean to let user decide if they would like to run tests within a docker environment.
DRUPAL_TEST_DOCKER=FALSE

Add boolean check to `/core/tests/Drupal/Nightwatch/global.js` line 7
if (process.env.DRUPAL_TEST_WEBSERVER_USER) {
becomes:
if (process.env.DRUPAL_TEST_WEBSERVER_USER && process.env.DRUPAL_TEST_DOCKER) {

πŸ› Bug report
Status

Active

Version

10.4 ✨

Component
OtherΒ  β†’

Last updated 39 minutes ago

Created by

πŸ‡ΊπŸ‡ΈUnited States cpierce42

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @cpierce42
  • Status changed to Needs review 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cpierce42

    Uploaded patch with proposed solution.

  • Pipeline finished with Failed
    2 months ago
    Total: 174s
    #284843
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    You run apt install nodejs, so why not install sudo in the container as well?

  • Status changed to Needs work 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thanks @longwave for taking a look.

    Moving to NW for #4 and the MR is throwing errors.

  • πŸ‡ͺπŸ‡ͺEstonia tormi Tallinn

    Use custom dockerfile instead of build_as_root for caching Lando build steps.

    .lando.yml:

    services:
      appserver:
        overrides:
          build:
            context: ./.lando
            dockerfile: appserver.Dockerfile
    

    .lando/appserver.Dockerfile:

    # Overrride Lando's PHP service.
    FROM devwithlando/php:8.3-fpm-4
    
    # Install vim, sudo, node 20, and npm globally
    RUN apt-get update && \
        apt-get install -y --no-install-recommends \
        gnupg2 \
        sudo \
        vim \
        wget \
        && wget -qO- https://deb.nodesource.com/setup_20.x | bash - && \
        apt-get install -y nodejs \
        && apt-get clean \
        && rm -rf /var/lib/apt/lists/*
    
    # Verify installation
    RUN node -v && npm -v
    
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

    We use the phpunit component for testing issues, so updating that.

Production build 0.71.5 2024