summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jest.config.js1
-rw-r--r--spec/frontend/test_setup.js16
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)!`);
+ }
+});