Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2019-03-11 11:40:00 +0300
committerPhil Hughes <me@iamphill.com>2019-03-11 11:40:00 +0300
commit1e0354840390de9f4e85b69b3f8b40a18d9c3d5c (patch)
tree17798c5aee5521d70240aeb1cc47a96907692081
parent8a59c9fdba4572cdfd60be6630d96fd37dc35654 (diff)
parentf0666830710568398119cc3251016d633387d29e (diff)
Merge branch 'winh-jest-synchronous-timeout' into 'master'
Introduce setTestTimeout() for synchronous Jest tests Closes #58658 See merge request gitlab-org/gitlab-ce!25926
-rw-r--r--spec/frontend/helpers/timeout.js24
-rw-r--r--spec/frontend/test_setup.js18
2 files changed, 26 insertions, 16 deletions
diff --git a/spec/frontend/helpers/timeout.js b/spec/frontend/helpers/timeout.js
new file mode 100644
index 00000000000..318593a48a4
--- /dev/null
+++ b/spec/frontend/helpers/timeout.js
@@ -0,0 +1,24 @@
+let testTimeoutInMs;
+
+export const setTestTimeout = newTimeoutInMs => {
+ testTimeoutInMs = newTimeoutInMs;
+ jest.setTimeout(newTimeoutInMs);
+};
+
+export const initializeTestTimeout = defaultTimeoutInMs => {
+ setTestTimeout(defaultTimeoutInMs);
+
+ let testStartTime;
+
+ // https://github.com/facebook/jest/issues/6947
+ beforeEach(() => {
+ testStartTime = Date.now();
+ });
+
+ afterEach(() => {
+ const elapsedTimeInMs = Date.now() - testStartTime;
+ if (elapsedTimeInMs > testTimeoutInMs) {
+ throw new Error(`Test took too long (${elapsedTimeInMs}ms > ${testTimeoutInMs}ms)!`);
+ }
+ });
+};
diff --git a/spec/frontend/test_setup.js b/spec/frontend/test_setup.js
index d892889b98d..8c36d8ff49f 100644
--- a/spec/frontend/test_setup.js
+++ b/spec/frontend/test_setup.js
@@ -1,23 +1,9 @@
import Vue from 'vue';
import Translate from '~/vue_shared/translate';
import axios from '~/lib/utils/axios_utils';
+import { initializeTestTimeout } from './helpers/timeout';
-const testTimeoutInMs = 300;
-jest.setTimeout(testTimeoutInMs);
-
-let testStartTime;
-
-// https://github.com/facebook/jest/issues/6947
-beforeEach(() => {
- testStartTime = Date.now();
-});
-
-afterEach(() => {
- const elapsedTimeInMs = Date.now() - testStartTime;
- if (elapsedTimeInMs > testTimeoutInMs) {
- throw new Error(`Test took too long (${elapsedTimeInMs}ms > ${testTimeoutInMs}ms)!`);
- }
-});
+initializeTestTimeout(300);
// fail tests for unmocked requests
beforeEach(done => {