drupalLogout.js 887 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { execSync } from 'child_process';
  2. import { URL } from 'url';
  3. /**
  4. * Logs out from a Drupal site.
  5. *
  6. * @param {object} [settings={}]
  7. * The settings object.
  8. * @param {boolean} [settings.silent=false]
  9. * If the command should be run silently.
  10. * @param {function} callback
  11. * A callback which will be called, when the logout is finished.
  12. * @return {object}
  13. * The drupalLogout command.
  14. */
  15. exports.command = function drupalLogout({ silent = false } = {}, callback) {
  16. const self = this;
  17. this.drupalRelativeURL('/user/logout');
  18. this.drupalUserIsLoggedIn(sessionExists => {
  19. if (silent) {
  20. if (sessionExists) {
  21. throw new Error('Logging out failed.');
  22. }
  23. } else {
  24. this.assert.equal(sessionExists, false, 'The user was logged out.');
  25. }
  26. });
  27. if (typeof callback === 'function') {
  28. callback.call(self);
  29. }
  30. return this;
  31. };