Skip to content

Commit

Permalink
Allow specifying timeout in tests via third argument (#29006)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored May 7, 2024
1 parent afe54bf commit 0fc9c84
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions scripts/jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
};

Expand Down

0 comments on commit 0fc9c84

Please sign in to comment.