未验证 提交 f0666830 编写于 作者: W Winnie Hellmann 提交者: Luke Bennett

Add setTestTimeout for Jest tests

Allows contributors to set the timeout
for individual jest tests.
上级 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 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 => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册