6766cdcb1efe1cebe60fad51d293a24b19a1b9fa
[yaffs-website] / web / core / tests / Drupal / Nightwatch / Commands / drupalUninstall.js
1 import { execSync } from 'child_process';
2 import { commandAsWebserver } from '../globals';
3
4 /**
5  * Uninstalls a test Drupal site.
6  *
7  * @param {function} callback
8  *   A callback which will be called, when the uninstallation is finished.
9  * @return {object}
10  *   The 'browser' object.
11  */
12 exports.command = function drupalUninstal(callback) {
13   const self = this;
14   const prefix = self.drupalDbPrefix;
15
16   // Check for any existing errors, because running this will cause Nightwatch to hang.
17   if (!this.currentTest.results.errors && !this.currentTest.results.failed) {
18     const dbOption =
19       process.env.DRUPAL_TEST_DB_URL.length > 0
20         ? `--db-url ${process.env.DRUPAL_TEST_DB_URL}`
21         : '';
22     try {
23       if (!prefix || !prefix.length) {
24         throw new Error(
25           'Missing database prefix parameter, unable to uninstall Drupal (the initial install was probably unsuccessful).',
26         );
27       }
28       execSync(
29         commandAsWebserver(
30           `php ./scripts/test-site.php tear-down ${prefix} ${dbOption}`,
31         ),
32       );
33     } catch (error) {
34       this.assert.fail(error);
35     }
36   }
37
38   // Nightwatch doesn't like it when no actions are added in a command file.
39   // https://github.com/nightwatchjs/nightwatch/issues/1792
40   this.pause(1);
41
42   if (typeof callback === 'function') {
43     callback.call(self);
44   }
45   return this;
46 };