Chris@17: import { execSync } from 'child_process'; Chris@17: import { commandAsWebserver } from '../globals'; Chris@17: Chris@17: /** Chris@17: * Uninstalls a test Drupal site. Chris@17: * Chris@17: * @param {function} callback Chris@17: * A callback which will be called, when the uninstallation is finished. Chris@17: * @return {object} Chris@17: * The 'browser' object. Chris@17: */ Chris@17: exports.command = function drupalUninstal(callback) { Chris@17: const self = this; Chris@17: const prefix = self.drupalDbPrefix; Chris@17: Chris@17: // Check for any existing errors, because running this will cause Nightwatch to hang. Chris@17: if (!this.currentTest.results.errors && !this.currentTest.results.failed) { Chris@17: const dbOption = Chris@17: process.env.DRUPAL_TEST_DB_URL.length > 0 Chris@17: ? `--db-url ${process.env.DRUPAL_TEST_DB_URL}` Chris@17: : ''; Chris@17: try { Chris@17: if (!prefix || !prefix.length) { Chris@17: throw new Error( Chris@17: 'Missing database prefix parameter, unable to uninstall Drupal (the initial install was probably unsuccessful).', Chris@17: ); Chris@17: } Chris@17: execSync( Chris@17: commandAsWebserver( Chris@17: `php ./scripts/test-site.php tear-down ${prefix} ${dbOption}`, Chris@17: ), Chris@17: ); Chris@17: } catch (error) { Chris@17: this.assert.fail(error); Chris@17: } Chris@17: } Chris@17: Chris@17: // Nightwatch doesn't like it when no actions are added in a command file. Chris@17: // https://github.com/nightwatchjs/nightwatch/issues/1792 Chris@17: this.pause(1); Chris@17: Chris@17: if (typeof callback === 'function') { Chris@17: callback.call(self); Chris@17: } Chris@17: return this; Chris@17: };