mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Allow specifying timeout in tests via third argument (#29006)
This commit is contained in:
committed by
GitHub
parent
c4e0e2e9d3
commit
8cfb073dca
+24
-13
@@ -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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user