Allow specifying timeout in tests via third argument (#29006)
Sebastian Silbermann committed
May 7, 2024 at 17:15 UTC
0fc9c84e63622026b5977557900c9cfe204552d3
1 file changed
+24
-13
scripts/jest/setupTests.js
+24
-13
@@ -206,44 +206,55 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
206
};
207
208
const gatedErrorMessage = 'Gated test was expected to fail, but it passed.';
209
- global._test_gate = (gateFn, testName, callback) => {
209
+ global._test_gate = (gateFn, testName, callback, timeoutMS) => {
210
let shouldPass;
211
try {
212
const flags = getTestFlags();
213
shouldPass = gateFn(flags);
214
} catch (e) {
215
- test(testName, () => {
216
- throw e;
217
- });
215
+ test(
216
+ testName,
217
+ () => {
218
+ throw e;
219
+ },
220
+ timeoutMS
221
+ );
222
return;
223
}
224
if (shouldPass) {
221
- test(testName, callback);
225
+ test(testName, callback, timeoutMS);
226
} else {
227
const error = new Error(gatedErrorMessage);
228
Error.captureStackTrace(error, global._test_gate);
229
test(`[GATED, SHOULD FAIL] ${testName}`, () =>
226
- expectTestToFail(callback, error));
230
+ expectTestToFail(callback, error, timeoutMS));
231
}
232
};
229
- global._test_gate_focus = (gateFn, testName, callback) => {
233
+ global._test_gate_focus = (gateFn, testName, callback, timeoutMS) => {
234
let shouldPass;
235
try {
236
const flags = getTestFlags();
237
shouldPass = gateFn(flags);
238
} catch (e) {
235
- test.only(testName, () => {
236
- throw e;
237
- });
239
+ test.only(
240
+ testName,
241
+ () => {
242
+ throw e;
243
+ },
244
+ timeoutMS
245
+ );
246
return;
247
}
248
if (shouldPass) {
241
- test.only(testName, callback);
249
+ test.only(testName, callback, timeoutMS);
250
} else {
251
const error = new Error(gatedErrorMessage);
252
Error.captureStackTrace(error, global._test_gate_focus);
245
- test.only(`[GATED, SHOULD FAIL] ${testName}`, () =>
246
- expectTestToFail(callback, error));
253
+ test.only(
254
+ `[GATED, SHOULD FAIL] ${testName}`,
255
+ () => expectTestToFail(callback, error),
256
+ timeoutMS
257
+ );
258
}
259
};
260