summaryrefslogtreecommitdiff
path: root/spec/frontend/helpers/timeout.js
diff options
context:
space:
mode:
authorMartin Hanzel <mhanzel@gitlab.com>2019-06-05 21:28:40 +0000
committerMike Greiling <mike@pixelcog.com>2019-06-05 21:28:40 +0000
commitc0e743bf0cad24bad590328925a32e9eee9810b2 (patch)
tree8d16844e84b73658abf76c3ac22ca06e94742196 /spec/frontend/helpers/timeout.js
parentfabca7abc1d33ddbc069eb2441874a3c03e14d5e (diff)
downloadgitlab-ce-c0e743bf0cad24bad590328925a32e9eee9810b2.tar.gz
Migrate old notes app test from Karma to Jest
Diffstat (limited to 'spec/frontend/helpers/timeout.js')
-rw-r--r--spec/frontend/helpers/timeout.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/spec/frontend/helpers/timeout.js b/spec/frontend/helpers/timeout.js
index b30b7f1ce1e..e74598ae20a 100644
--- a/spec/frontend/helpers/timeout.js
+++ b/spec/frontend/helpers/timeout.js
@@ -1,5 +1,6 @@
const NS_PER_SEC = 1e9;
const NS_PER_MS = 1e6;
+const IS_DEBUGGING = process.execArgv.join(' ').includes('--inspect-brk');
let testTimeoutNS;
@@ -8,6 +9,13 @@ export const setTestTimeout = newTimeoutMS => {
jest.setTimeout(newTimeoutMS);
};
+// Allows slow tests to set their own timeout.
+// Useful for tests with jQuery, which is very slow in big DOMs.
+let temporaryTimeoutNS = null;
+export const setTestTimeoutOnce = newTimeoutMS => {
+ temporaryTimeoutNS = newTimeoutMS * NS_PER_MS;
+};
+
export const initializeTestTimeout = defaultTimeoutMS => {
setTestTimeout(defaultTimeoutMS);
@@ -19,12 +27,20 @@ export const initializeTestTimeout = defaultTimeoutMS => {
});
afterEach(() => {
+ let timeoutNS = testTimeoutNS;
+ if (Number.isFinite(temporaryTimeoutNS)) {
+ timeoutNS = temporaryTimeoutNS;
+ temporaryTimeoutNS = null;
+ }
+
const [seconds, remainingNs] = process.hrtime(testStartTime);
const elapsedNS = seconds * NS_PER_SEC + remainingNs;
- if (elapsedNS > testTimeoutNS) {
+ // Disable the timeout error when debugging. It is meaningless because
+ // debugging always takes longer than the test timeout.
+ if (elapsedNS > timeoutNS && !IS_DEBUGGING) {
throw new Error(
- `Test took too long (${elapsedNS / NS_PER_MS}ms > ${testTimeoutNS / NS_PER_MS}ms)!`,
+ `Test took too long (${elapsedNS / NS_PER_MS}ms > ${timeoutNS / NS_PER_MS}ms)!`,
);
}
});