1 import { execSync } from 'child_process';
2 import { URL } from 'url';
3 import { commandAsWebserver } from '../globals';
6 * Installs a Drupal test site.
8 * @param {oject} [settings={}]
10 * @param {string} [settings.setupFile='']
11 * Setup file used by TestSiteApplicationTest
12 * @param {function} callback
13 * A callback which will be called, when the installation is finished.
15 * The 'browser' object.
17 exports.command = function drupalInstall({ setupFile = '' } = {}, callback) {
21 setupFile = setupFile ? `--setup-file "${setupFile}"` : '';
23 process.env.DRUPAL_TEST_DB_URL.length > 0
24 ? `--db-url ${process.env.DRUPAL_TEST_DB_URL}`
26 const install = execSync(
28 `php ./scripts/test-site.php install ${setupFile} --base-url ${
29 process.env.DRUPAL_TEST_BASE_URL
30 } ${dbOption} --json`,
33 const installData = JSON.parse(install.toString());
34 this.drupalDbPrefix = installData.db_prefix;
35 this.drupalSitePath = installData.site_path;
36 const url = new URL(process.env.DRUPAL_TEST_BASE_URL);
37 this.url(process.env.DRUPAL_TEST_BASE_URL).setCookie({
38 name: 'SIMPLETEST_USER_AGENT',
39 // Colons need to be URL encoded to be valid.
40 value: encodeURIComponent(installData.user_agent),
45 this.assert.fail(error);
48 // Nightwatch doesn't like it when no actions are added in a command file.
49 // https://github.com/nightwatchjs/nightwatch/issues/1792
52 if (typeof callback === 'function') {