From 19900a5ae58be124b3f60e7e8f0e9528ece8094c Mon Sep 17 00:00:00 2001 From: eps1lon Date: Mon, 6 May 2024 22:08:49 +0200 Subject: [PATCH] Allow specifying timeout in tests via third argument --- scripts/jest/setupTests.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/scripts/jest/setupTests.js b/scripts/jest/setupTests.js index c3fdefdf458b8..5aa238804b680 100644 --- a/scripts/jest/setupTests.js +++ b/scripts/jest/setupTests.js @@ -206,44 +206,55 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { }; const gatedErrorMessage = 'Gated test was expected to fail, but it passed.'; - global._test_gate = (gateFn, testName, callback) => { + global._test_gate = (gateFn, testName, callback, timeoutMS) => { let shouldPass; try { const flags = getTestFlags(); shouldPass = gateFn(flags); } catch (e) { - test(testName, () => { - throw e; - }); + test( + testName, + () => { + throw e; + }, + timeoutMS + ); return; } if (shouldPass) { - test(testName, callback); + test(testName, callback, timeoutMS); } else { const error = new Error(gatedErrorMessage); Error.captureStackTrace(error, global._test_gate); test(`[GATED, SHOULD FAIL] ${testName}`, () => - expectTestToFail(callback, error)); + expectTestToFail(callback, error, timeoutMS)); } }; - global._test_gate_focus = (gateFn, testName, callback) => { + global._test_gate_focus = (gateFn, testName, callback, timeoutMS) => { let shouldPass; try { const flags = getTestFlags(); shouldPass = gateFn(flags); } catch (e) { - test.only(testName, () => { - throw e; - }); + test.only( + testName, + () => { + throw e; + }, + timeoutMS + ); return; } if (shouldPass) { - test.only(testName, callback); + test.only(testName, callback, timeoutMS); } else { const error = new Error(gatedErrorMessage); Error.captureStackTrace(error, global._test_gate_focus); - test.only(`[GATED, SHOULD FAIL] ${testName}`, () => - expectTestToFail(callback, error)); + test.only( + `[GATED, SHOULD FAIL] ${testName}`, + () => expectTestToFail(callback, error), + timeoutMS + ); } };