Nightwatch tests in the test modules are not detected by Drupal CI

Created on 22 August 2024, 11 months ago
Updated 5 September 2024, 10 months ago

Problem/Motivation

In my module Test Helpers I have a submodule, created specifically for tests, so I put it into the path like tests/modules/my_test_submodule/tests/src/Nightwatch/Tests/myTest.js.

This location hides the module from installing on the non-test environments, preventing accidentally enabling them in production.

But the Drupal CI doesn't detect this test, because we have these glob patterns in the pipeline: https://git.drupalcode.org/project/gitlab_templates/-/blob/1.5.5/include...

.nightwatch-tests-exist-rule: &nightwatch-tests-exist-rule
  - exists:
      - tests/src/Nightwatch/**/*.js
      - modules/*/tests/src/Nightwatch/**/*.js
    when: on_success

Steps to reproduce

1. Create a test submodule in your custom module, and put it into the test modules directory like tests/modules/my_test_submodule.
2. Create a Nightwatch test in this submodule, put it into the path like tests/modules/my_test_submodule/tests/src/Nightwatch/Tests/myTest.js
3. Run the pipeline and see that the Nightwatch tests are not found in the module.
4. Move the module to the non-test submodules location like modules/my_test_submodule.
5. See that the pipeline starts to work well.

Proposed resolution

The solution for this problem is to add the tests/modules path to the "nightwatch-tests-exist-rule", like this:

.nightwatch-tests-exist-rule: &nightwatch-tests-exist-rule
  - exists:
      - tests/src/Nightwatch/**/*.js
      - modules/*/tests/src/Nightwatch/**/*.js
      - tests/modules/*/tests/src/Nightwatch/**/*.js
    when: on_success

And a workaround to fix this in custom modules, until the issue is resolved, is to add to the .gitlab-ci.yml file this block:

# A workaround for the issue https://www.drupal.org/project/gitlab_templates/issues/3469616 start.
.opt-in-current-rule: &opt-in-current-rule
  if: '$OPT_IN_TEST_CURRENT != "1"'
  when: never

.skip-nightwatch-rule: &skip-nightwatch-rule
  if: '$SKIP_NIGHTWATCH == "1"'
  when: never

.nightwatch-tests-exist-rule: &nightwatch-tests-exist-rule
  - exists:
      - tests/src/Nightwatch/**/*.js
      - modules/*/tests/src/Nightwatch/**/*.js
      # A fix for the issue https://www.drupal.org/project/gitlab_templates/issues/3469616.
      - tests/modules/*/tests/src/Nightwatch/**/*.js
    when: on_success

.nightwatch-base:
  rules:
    - *opt-in-current-rule
    - *skip-nightwatch-rule
    - *nightwatch-tests-exist-rule
# A workaround for the issue https://www.drupal.org/project/gitlab_templates/issues/3469616 end.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Component

gitlab-ci

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