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
Issue fork drupal-3469607
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3469607-nightwatch-tests-from
changes, plain diff MR !9292
1 hidden branch
Issue fork drupalci-3469607
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Issue fork gitlab_templates-3469607
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3469607-nightwatch-follow-symlinks
compare
Comments
Comment #2
murzMoving to the right module.
Comment #3
murzActually, it's an issue in the Drupal Core, not the Drupal CI, so moving the issue to the Drupal Core module.
Comment #6
murzI created a merge request with this fix https://git.drupalcode.org/project/drupal/-/merge_requests/9292 - please review.
Comment #7
smustgrave commentedSeems pretty straight forward and didn't break existing tests
Not sure if we need an example of a nightwatch submodule in core?
Comment #8
nod_This makes sense to me but I don't have an idea about potential security issues opened by this.
Comment #16
catchI also thought this would be fine but wanted to rule out path traversal, pinged the security team channel and at the same time realised that anyone could commit this change (or worse) to any MR they wanted do, so it should be completely fine. got a +1 from mcdruid, greggles and @drumm so crediting here.
Committed/pushed to 11.x and cherry-picked back through to 10.3.x, thanks!
Comment #18
gregglesCommenting to confirm catch's statement in #16. This doesn't open up any more access than already exists in the context of the d.o tests.