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

Command icon 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 drupalci-3469607

Command icon 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:

    Command icon 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:

    Comments

    murz created an issue. See original summary.

    murz’s picture

    Project: DrupalCI: Drupal.org Testing Infrastructure » GitLab Templates
    Component: Code » gitlab-ci

    Moving to the right module.

    murz’s picture

    Project: GitLab Templates » Drupal core
    Version: » 11.x-dev
    Component: gitlab-ci » javascript

    Actually, it's an issue in the Drupal Core, not the Drupal CI, so moving the issue to the Drupal Core module.

    murz changed the visibility of the branch 3469607-nightwatch-follow-symlinks to hidden.

    murz’s picture

    Status: Active » Needs review

    I created a merge request with this fix https://git.drupalcode.org/project/drupal/-/merge_requests/9292 - please review.

    smustgrave’s picture

    Status: Needs review » Reviewed & tested by the community
    Issue tags: +Needs Review Queue Initiative

    Seems pretty straight forward and didn't break existing tests

    Not sure if we need an example of a nightwatch submodule in core?

    nod_’s picture

    Issue tags: +Needs security review

    This makes sense to me but I don't have an idea about potential security issues opened by this.

    • catch committed 08d6f5e8 on 10.3.x
      Issue #3469607 by murz, drumm, mcdruid, greggles: Nightwatch tests from...

    • catch committed c65accc2 on 10.4.x
      Issue #3469607 by murz, drumm, mcdruid, greggles: Nightwatch tests from...

    • catch committed b98bd47e on 11.0.x
      Issue #3469607 by murz, drumm, mcdruid, greggles: Nightwatch tests from...

    • catch committed 8da192a5 on 11.x
      Issue #3469607 by murz, drumm, mcdruid, greggles: Nightwatch tests from...

    catch credited drumm.

    catch credited greggles.

    catch credited mcdruid.

    catch’s picture

    Version: 11.x-dev » 10.3.x-dev
    Status: Reviewed & tested by the community » Fixed

    I 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!

    greggles’s picture

    Commenting 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.

    Status: Fixed » Closed (fixed)

    Automatically closed - issue fixed for 2 weeks with no activity.