Drush in Nightwatch tests can't detect the Simpletest site path

Created on 3 February 2025, 2 days ago

Problem/Motivation

I need to run drush commands from Nightwatch tests to interact with the test instance of Drupal.

But when I just run the drush command, on the local setup it applies to the current website (installed locally), not to the instance created by the simpletest.

And in the cloud CI, it just doesn't see the test database.

Steps to reproduce

1. Execute a drush command from a Nightwatch test, for example drush cache:clear

2. See that it doesn't use the simpletest site path, and fails on the database connection in CI, and locally - clears the cache of the local Drupal setup instead of the test instance's database.

Proposed resolution

To resolve this, we should set the environment variable for drush with the simpletest site id, to make it know about the test website environment.

Here is an example of how we can set it manually from the Nightwatch test context:

  'Run drush with ENV': (browser) => {
    browser
      .drupalRelativeURL('/')
      .perform(async () => {
        const simpletestUserAgentCookieObject = await browser.cookies.get(
          'SIMPLETEST_USER_AGENT',
        );
        const simpletestUserAgentCookie = decodeURIComponent(
          simpletestUserAgentCookieObject.value,
        );
        const drushCommand = `HTTP_USER_AGENT="${simpletestUserAgentCookie}" drush status`;
        console.log(drushCommand);
        const result = execSync(drushCommand);
        console.log(result.toString());
      });
  },

But it's better to make this from the pipeline scripts instead of this.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Component

gitlab-ci

Created by

🇦🇲Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024