Nightwatch pipeline started to fail if the module contains Nightwatch commands

Issue information

From user: murz

Related to !297 (merged)

Contribution record

Fork management

Problem/Motivation

After fixing the issue #3475974: Preserve environment variables when running testing jobs I faced a new issue - any Drupal module that contains Nightwatch commands started to fail with an error:

    Error   unhandledRejection: Error while loading the API commands: the command .myNightwatchCommand() is already defined.
TypeError: Error while loading the API commands: the command .myNightwatchCommand() is already defined.
    at CommandLoader.validateMethod (/builds/project/test_helpers/web/core/node_modules/nightwatch/lib/api/_loaders/_command-loader.js:54:19)
    at CommandLoader.define (/builds/project/test_helpers/web/core/node_modules/nightwatch/lib/api/_loaders/_base-loader.js:330:10)
    at ApiLoader.addCommandDefinitionAsync (/builds/project/test_helpers/web/core/node_modules/nightwatch/lib/api/index.js:367:42)
    at async Promise.all (index 29)

Steps to reproduce

A job reproducing the issue: https://git.drupalcode.org/project/test_helpers/-/jobs/3506124

Proposed resolution

This happens because before fixing the "missing environment variables" issue we have the empty value of the environment variable DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY, but now it got the "right" value:

DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY=../

This leads to scanning the module root directory for available Nightwatch tests by a glob pattern:

globSync('**/tests/**/Nightwatch/**/*.js', {

- see https://git.drupalcode.org/project/drupal/-/blob/10.3.x/core/tests/Drupal/Nightwatch/nightwatch.conf.js?ref_type=heads#L16

But, because we use symlinks to make a "copy" of the module in the web/modules/custom/MODULENAME directory, this leads to finding the Nightwatch commands directory with the same commands twice.

The quick solution is to set the DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY to the empty string, but it looks not so right.

So, any ideas on how to fix this right?

Remaining tasks

User interface changes

API changes

Data model changes

Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information