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:
authorWinnie Hellmann <winnie@gitlab.com>2019-03-08 17:07:44 +0300
committerLuke Bennett <lbennett@gitlab.com>2019-03-08 19:21:10 +0300
commitf0666830710568398119cc3251016d633387d29e (patch)
tree730a7a08de8bce221d4969ac35f1105b8d66dac1 /spec/frontend/helpers
parent26477f388952f9b8d02fcca6ac4395915e48218c (diff)
Add setTestTimeout for Jest tests
Allows contributors to set the timeout for individual jest tests.
Diffstat (limited to 'spec/frontend/helpers')
-rw-r--r--spec/frontend/helpers/timeout.js24
1 files changed, 24 insertions, 0 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)!`);
+ }
+ });
+};