diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2018-09-06 20:36:04 +0300 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2018-12-11 15:06:19 +0300 |
commit | fac4d54f3d4a7ce2e992c490c9a1164ae4ff17ac (patch) | |
tree | 3c1b3d7d4541af2cdd28f0564827fa72e833af12 | |
parent | ca3603de56445862b47cbc9b8eec50cbf82d71c3 (diff) |
Fail long running tests
-rw-r--r-- | jest.config.js | 1 | ||||
-rw-r--r-- | spec/frontend/test_setup.js | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/jest.config.js b/jest.config.js index 0a7b2aedb42..8e4f207af64 100644 --- a/jest.config.js +++ b/jest.config.js @@ -24,4 +24,5 @@ module.exports = { cacheDirectory: '<rootDir>/tmp/cache/jest', modulePathIgnorePatterns: ['<rootDir>/.yarn-cache/'], reporters, + setupTestFrameworkScriptFile: '<rootDir>/spec/frontend/test_setup.js', }; diff --git a/spec/frontend/test_setup.js b/spec/frontend/test_setup.js new file mode 100644 index 00000000000..742ea60ecbd --- /dev/null +++ b/spec/frontend/test_setup.js @@ -0,0 +1,16 @@ +const testTimeoutInMs = 0; +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)!`); + } +}); |