Nightwatch tests from submodules do not run in Gitlab CI because of missing option to follow symlinks

Created on 22 August 2024, 4 months ago

Problem/Motivation

I created a Nightwatch test in the submodule (the test path is like my_module/modules/my_submodule/tests/src/Nightwatch/Tests/myTest.js) and the Drupal CI can't find it with an error:

Error
No tests defined! using source folder: ../core/modules/ckeditor5/tests/src/Nightwatch/Tests,../core/modules/toolbar/tests/src/Nightwatch/Tests,../core/tests/Drupal/Nightwatch/Tests

Here is an example of the failed pipeline: https://git.drupalcode.org/project/test_helpers/-/jobs/2514818

But If I move the test to the root module (my_module/tests/src/Nightwatch/Tests/myTest.js) - it starts to work well - here is the successful pipeline: https://git.drupalcode.org/project/test_helpers/-/jobs/2514887

Steps to reproduce

1. Create a submodule in a module.
2. Create a Nightwatch test in the submodule, put it into the path like modules/my_submodule/tests/src/Nightwatch/Tests/myTest.js.
3. See that the Drupal CI pipeline fails with the error.

Proposed resolution

The root cause of the issue is the created symlinks for each module subdirectory in this step of the pipeline:
https://git.drupalcode.org/project/gitlab_templates/-/blob/1.5.5/include...

Here is the part of the PHP file that makes the symlinks for each file and subdirectory of the module:
https://git.drupalcode.org/project/gitlab_templates/-/blob/1.5.5/scripts...

Then, the Nightwatch scans the module directory with symlinks, using this glob pattern:
https://git.drupalcode.org/project/drupal/-/blob/11.0.1/core/tests/Drupa...

globSync('**/tests/**/Nightwatch/**/*.js', {
  cwd: path.resolve(process.cwd(), `../${searchDirectory}`),
  ignore: process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES
    ? process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES.split(',').concat(
        defaultIgnore,
      )
    : defaultIgnore,
})

But! This pattern doesn't follow the created symlinks, because of the missing parameter follow: true, here is the documentation: https://github.com/isaacs/node-glob

** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories, unless {follow:true} is passed in the options object. A pattern like a/b/** will only match a/b if it is a directory. Follows 1 symbolic link if not the first item in the pattern, or 0 if it is the first item, unless follow:true is set, in which case it follows all symbolic links.

So, to resolve this issue, we should simply add the follow: true argument to the glob function, like this

globSync('**/tests/**/Nightwatch/**/*.js', {
  cwd: path.resolve(process.cwd(), `../${searchDirectory}`),
  follow: true,
  ignore: process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES
    ? process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES.split(',').concat(
        defaultIgnore,
      )
    : defaultIgnore,
})

And here is a workaround for module developers, until the issue is fixed: override in the module's .gitlab-ci.yml file the included .nightwatch-base before_script with adding a step that adds this line, like this:

.nightwatch-base:
  before_script:
    - apt-get update && apt-get install -y wget unzip
    - wget https://chromedriver.storage.googleapis.com/91.0.4472.101/chromedriver_linux64.zip
    - unzip chromedriver_linux64.zip
    - mv chromedriver /usr/local/bin/
    - chmod +x /usr/local/bin/chromedriver
    - npm install -g nightwatch
    - 'sed -i "/  ignore: process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES/i\  follow: true," web/core/tests/Drupal/Nightwatch/nightwatch.conf.js'
    - cat web/core/tests/Drupal/Nightwatch/nightwatch.conf.js

I will prepare a MR to fix this in the Drupal CI.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

11.0

Component
JavascriptΒ  β†’

Last updated 3 days ago

Created by

πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024