drupalUninstall.js 1.3 KB

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