Allow installing hidden modules for tests in Nightwatch test scripts

Created on 18 July 2024, 4 months ago
Updated 23 July 2024, 4 months ago

Problem/Motivation

Drupal Nightwatch tests are very limited in making changes for tests, compared to PHPUnit Browser tests, because we have no access to the Drupal Kernel at all.

Therefore, a popular workaround for this limitation is creating a special helper module to implement the PHP part for specific tests.
We already have such modules in Drupal Core even for PHPUnit tests, for example, modules/action/tests/action_form_ajax_test.

But the problem is that we can't install them in Nightwatch tests, because it requires a specific setting to be enabled in the settings.php:

$settings['extension_discovery_scan_tests'] = TRUE;

Steps to reproduce

1. Make a custom module, and mark it as hidden in the info.yaml file:

name: My module Test Helper
type: module
package: Testing
hidden: true

2. Try to install this module in a Nightwatch test.

You will see an error that this module is missing in the list of modules to install.

Proposed resolution

Set the setting to show all hidden modules to true in the Nightwatch command drupalInstall() by default.

Or add a separate parameter to control this setting.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Closed: works as designed

Version

11.0 πŸ”₯

Component
JavascriptΒ  β†’

Last updated 2 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

  • Issue created by @murz
  • Status changed to Needs review 4 months ago
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    I found a place where we can enable hidden modules for functional tests and made an MR https://git.drupalcode.org/project/drupal/-/merge_requests/8836

    If this approach is okay, I can write a test to check this feature.

  • Pipeline finished with Success
    4 months ago
    Total: 471s
    #228632
  • Status changed to RTBC 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Makes 100% sense to me to be able to install test modules.

  • Status changed to Needs work 4 months ago
  • πŸ‡«πŸ‡·France nod_ Lille

    That makes sense to me, do we have a use case for this today? if it helps existing tests we should convert at least one to showcase this.

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

    That makes sense to me, do we have a use case for this today? if it helps existing tests we should convert at least one to showcase this.

    There are no use cases for now because installing the hidden modules from Nightwatch tests is impossible.
    So, for now, all of the tests that use hidden modules, are written with PHPUnit.

    I can write a new separate Nigtwatch test to reproduce and check this feature, but I think it will be just spending time on our pipelines.

  • Status changed to Needs review 4 months ago
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Seems we have another way to hide modules, intended only for tests - instead of using the parameter:
    hidden: true
    we can put all test modules into the tests subdirectory of the module.
    Then, they will be visible only in the test environment, and work well for Nightwatch tests too.

    Example: https://git.drupalcode.org/project/search_api/-/tree/8.x-1.x/tests/modul...

    So, seems that marking test modules as hidden, is an outdated approach.

    Therefore, instead of allowing hidden modules in tests, let's update the documentation at the page https://www.drupal.org/docs/develop/creating-modules/let-drupal-know-abo... β†’ then? I updated the documentation now by adding:

    For modules, intended only for tests, it's better to place them into the tests/modules subdirectory, instead of making them as hidden.

    If it sounds okay for you, let's close the issue then?

  • Status changed to Closed: works as designed 4 months ago
  • πŸ‡«πŸ‡·France nod_ Lille

    works for me, thanks!

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    +1 to closing this as works as designed. Maybe some docs are missing. The fix in the MR would change settings.php for all test environments which would not be the correct fix here - but yeah there is no fix to do here :)

Production build 0.71.5 2024