Skip to content

Commit 19900a5

Browse files
committed
Allow specifying timeout in tests via third argument
1 parent 9b13002 commit 19900a5

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

scripts/jest/setupTests.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,44 +206,55 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
206206
};
207207

208208
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) => {
210210
let shouldPass;
211211
try {
212212
const flags = getTestFlags();
213213
shouldPass = gateFn(flags);
214214
} catch (e) {
215-
test(testName, () => {
216-
throw e;
217-
});
215+
test(
216+
testName,
217+
() => {
218+
throw e;
219+
},
220+
timeoutMS
221+
);
218222
return;
219223
}
220224
if (shouldPass) {
221-
test(testName, callback);
225+
test(testName, callback, timeoutMS);
222226
} else {
223227
const error = new Error(gatedErrorMessage);
224228
Error.captureStackTrace(error, global._test_gate);
225229
test(`[GATED, SHOULD FAIL] ${testName}`, () =>
226-
expectTestToFail(callback, error));
230+
expectTestToFail(callback, error, timeoutMS));
227231
}
228232
};
229-
global._test_gate_focus = (gateFn, testName, callback) => {
233+
global._test_gate_focus = (gateFn, testName, callback, timeoutMS) => {
230234
let shouldPass;
231235
try {
232236
const flags = getTestFlags();
233237
shouldPass = gateFn(flags);
234238
} catch (e) {
235-
test.only(testName, () => {
236-
throw e;
237-
});
239+
test.only(
240+
testName,
241+
() => {
242+
throw e;
243+
},
244+
timeoutMS
245+
);
238246
return;
239247
}
240248
if (shouldPass) {
241-
test.only(testName, callback);
249+
test.only(testName, callback, timeoutMS);
242250
} else {
243251
const error = new Error(gatedErrorMessage);
244252
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+
);
247258
}
248259
};
249260

0 commit comments

Comments
 (0)