Commit f0666830 authored by Winnie Hellmann's avatar Winnie Hellmann Committed by Luke Bennett

Add setTestTimeout for Jest tests

Allows contributors to set the timeout
for individual jest tests.
parent 26477f38
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)!`);
}
});
};
import Vue from 'vue'; import Vue from 'vue';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { initializeTestTimeout } from './helpers/timeout';
const testTimeoutInMs = 300; initializeTestTimeout(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)!`);
}
});
// fail tests for unmocked requests // fail tests for unmocked requests
beforeEach(done => { beforeEach(done => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment