annotate core/tests/Drupal/Nightwatch/Commands/drupalInstall.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@17 1 import { execSync } from 'child_process';
Chris@17 2 import { URL } from 'url';
Chris@17 3 import { commandAsWebserver } from '../globals';
Chris@17 4
Chris@17 5 /**
Chris@17 6 * Installs a Drupal test site.
Chris@17 7 *
Chris@17 8 * @param {oject} [settings={}]
Chris@17 9 * Settings object
Chris@17 10 * @param {string} [settings.setupFile='']
Chris@17 11 * Setup file used by TestSiteApplicationTest
Chris@17 12 * @param {function} callback
Chris@17 13 * A callback which will be called, when the installation is finished.
Chris@17 14 * @return {object}
Chris@17 15 * The 'browser' object.
Chris@17 16 */
Chris@17 17 exports.command = function drupalInstall({ setupFile = '' } = {}, callback) {
Chris@17 18 const self = this;
Chris@17 19
Chris@17 20 try {
Chris@17 21 setupFile = setupFile ? `--setup-file "${setupFile}"` : '';
Chris@17 22 const dbOption =
Chris@17 23 process.env.DRUPAL_TEST_DB_URL.length > 0
Chris@17 24 ? `--db-url ${process.env.DRUPAL_TEST_DB_URL}`
Chris@17 25 : '';
Chris@17 26 const install = execSync(
Chris@17 27 commandAsWebserver(
Chris@17 28 `php ./scripts/test-site.php install ${setupFile} --base-url ${
Chris@17 29 process.env.DRUPAL_TEST_BASE_URL
Chris@17 30 } ${dbOption} --json`,
Chris@17 31 ),
Chris@17 32 );
Chris@17 33 const installData = JSON.parse(install.toString());
Chris@17 34 this.drupalDbPrefix = installData.db_prefix;
Chris@17 35 this.drupalSitePath = installData.site_path;
Chris@17 36 const url = new URL(process.env.DRUPAL_TEST_BASE_URL);
Chris@17 37 this.url(process.env.DRUPAL_TEST_BASE_URL).setCookie({
Chris@17 38 name: 'SIMPLETEST_USER_AGENT',
Chris@17 39 // Colons need to be URL encoded to be valid.
Chris@17 40 value: encodeURIComponent(installData.user_agent),
Chris@17 41 path: url.pathname,
Chris@17 42 domain: url.host,
Chris@17 43 });
Chris@17 44 } catch (error) {
Chris@17 45 this.assert.fail(error);
Chris@17 46 }
Chris@17 47
Chris@17 48 // Nightwatch doesn't like it when no actions are added in a command file.
Chris@17 49 // https://github.com/nightwatchjs/nightwatch/issues/1792
Chris@17 50 this.pause(1);
Chris@17 51
Chris@17 52 if (typeof callback === 'function') {
Chris@17 53 callback.call(self);
Chris@17 54 }
Chris@17 55
Chris@17 56 return this;
Chris@17 57 };