Add setTestTimeout for Jest tests
Allows contributors to set the timeout for individual jest tests.
This commit is contained in:
parent
26477f3889
commit
f066683071
2 changed files with 26 additions and 16 deletions
24
spec/frontend/helpers/timeout.js
Normal file
24
spec/frontend/helpers/timeout.js
Normal file
|
@ -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)!`);
|
||||
}
|
||||
});
|
||||
};
|
|
@ -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 => {
|
||||
|
|
Loading…
Reference in a new issue