summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2019-05-16 21:59:01 +0000
committerFatih Acet <acetfatih@gmail.com>2019-05-16 21:59:01 +0000
commit04794fb476a6071c1e1f782ae1c81801ff2410c3 (patch)
tree74f5f5f3f6d429e0cfd8af0bdf392dd79c8168ef
parent913bc9649b012b178ef1acb9ef254fcc565be248 (diff)
parentad7d62e1ac9ee06edfdd8eac7e0ab3fac868f336 (diff)
downloadgitlab-ce-04794fb476a6071c1e1f782ae1c81801ff2410c3.tar.gz
Merge branch 'fe-use-process-timer-in-jest-timeout' into 'master'
Use process timer for jest timeout testing See merge request gitlab-org/gitlab-ce!28209
-rw-r--r--spec/frontend/helpers/timeout.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/spec/frontend/helpers/timeout.js b/spec/frontend/helpers/timeout.js
index 318593a48a4..b30b7f1ce1e 100644
--- a/spec/frontend/helpers/timeout.js
+++ b/spec/frontend/helpers/timeout.js
@@ -1,24 +1,31 @@
-let testTimeoutInMs;
+const NS_PER_SEC = 1e9;
+const NS_PER_MS = 1e6;
-export const setTestTimeout = newTimeoutInMs => {
- testTimeoutInMs = newTimeoutInMs;
- jest.setTimeout(newTimeoutInMs);
+let testTimeoutNS;
+
+export const setTestTimeout = newTimeoutMS => {
+ testTimeoutNS = newTimeoutMS * NS_PER_MS;
+ jest.setTimeout(newTimeoutMS);
};
-export const initializeTestTimeout = defaultTimeoutInMs => {
- setTestTimeout(defaultTimeoutInMs);
+export const initializeTestTimeout = defaultTimeoutMS => {
+ setTestTimeout(defaultTimeoutMS);
let testStartTime;
// https://github.com/facebook/jest/issues/6947
beforeEach(() => {
- testStartTime = Date.now();
+ testStartTime = process.hrtime();
});
afterEach(() => {
- const elapsedTimeInMs = Date.now() - testStartTime;
- if (elapsedTimeInMs > testTimeoutInMs) {
- throw new Error(`Test took too long (${elapsedTimeInMs}ms > ${testTimeoutInMs}ms)!`);
+ const [seconds, remainingNs] = process.hrtime(testStartTime);
+ const elapsedNS = seconds * NS_PER_SEC + remainingNs;
+
+ if (elapsedNS > testTimeoutNS) {
+ throw new Error(
+ `Test took too long (${elapsedNS / NS_PER_MS}ms > ${testTimeoutNS / NS_PER_MS}ms)!`,
+ );
}
});
};