summaryrefslogtreecommitdiff
path: root/spec/frontend/environment.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/environment.js')
-rw-r--r--spec/frontend/environment.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js
index c055702d832..d1bc11538a3 100644
--- a/spec/frontend/environment.js
+++ b/spec/frontend/environment.js
@@ -1,8 +1,12 @@
/* eslint-disable import/no-commonjs, max-classes-per-file */
const path = require('path');
-const { ErrorWithStack } = require('jest-util');
const JSDOMEnvironment = require('jest-environment-jsdom');
+const { ErrorWithStack } = require('jest-util');
+const {
+ setGlobalDateToFakeDate,
+ setGlobalDateToRealDate,
+} = require('./__helpers__/fake_date/fake_date');
const { TEST_HOST } = require('./__helpers__/test_constants');
const ROOT_PATH = path.resolve(__dirname, '../..');
@@ -12,6 +16,10 @@ class CustomEnvironment extends JSDOMEnvironment {
// Setup testURL so that window.location is setup properly
super({ ...config, testURL: TEST_HOST }, context);
+ // Fake the `Date` for `jsdom` which fixes things like document.cookie
+ // https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39496#note_503084332
+ setGlobalDateToFakeDate();
+
Object.assign(context.console, {
error(...args) {
throw new ErrorWithStack(
@@ -69,6 +77,9 @@ class CustomEnvironment extends JSDOMEnvironment {
}
async teardown() {
+ // Reset `Date` so that Jest can report timing accurately *roll eyes*...
+ setGlobalDateToRealDate();
+
await new Promise(setImmediate);
if (this.rejectedPromises.length > 0) {