Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Nightwatch / Commands / drupalUserIsLoggedIn.js
diff --git a/web/core/tests/Drupal/Nightwatch/Commands/drupalUserIsLoggedIn.js b/web/core/tests/Drupal/Nightwatch/Commands/drupalUserIsLoggedIn.js
new file mode 100644 (file)
index 0000000..47ca4f7
--- /dev/null
@@ -0,0 +1,21 @@
+/**
+ * Checks if a user is logged in.
+ *
+ * @param {function} callback
+ *   A callback which will be called, when the login status has been checked.
+ * @return {object}
+ *   The drupalUserIsLoggedIn command.
+ */
+exports.command = function drupalUserIsLoggedIn(callback) {
+  if (typeof callback === 'function') {
+    this.getCookies(cookies => {
+      const sessionExists = cookies.value.some(cookie =>
+        cookie.name.match(/^SESS/),
+      );
+
+      callback.call(this, sessionExists);
+    });
+  }
+
+  return this;
+};