Skip to content

Commit de0a3a2

Browse files
eps1lonAndyPengc12
authored andcommitted
Improve stack trace when gated test fails (facebook#28374)
1 parent 23a7843 commit de0a3a2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

scripts/jest/setupTests.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
241241
global.Error = ErrorProxy;
242242
}
243243

244-
const expectTestToFail = async (callback, errorMsg) => {
244+
const expectTestToFail = async (callback, error) => {
245245
if (callback.length > 0) {
246246
throw Error(
247247
'Gated test helpers do not support the `done` callback. Return a ' +
@@ -261,12 +261,12 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
261261
// `afterEach` like we normally do. `afterEach` is too late because if it
262262
// throws, we won't have captured it.
263263
flushAllUnexpectedConsoleCalls();
264-
} catch (error) {
264+
} catch (testError) {
265265
// Failed as expected
266266
resetAllUnexpectedConsoleCalls();
267267
return;
268268
}
269-
throw Error(errorMsg);
269+
throw error;
270270
};
271271

272272
const gatedErrorMessage = 'Gated test was expected to fail, but it passed.';
@@ -284,8 +284,10 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
284284
if (shouldPass) {
285285
test(testName, callback);
286286
} else {
287+
const error = new Error(gatedErrorMessage);
288+
Error.captureStackTrace(error, global._test_gate);
287289
test(`[GATED, SHOULD FAIL] ${testName}`, () =>
288-
expectTestToFail(callback, gatedErrorMessage));
290+
expectTestToFail(callback, error));
289291
}
290292
};
291293
global._test_gate_focus = (gateFn, testName, callback) => {
@@ -302,8 +304,10 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
302304
if (shouldPass) {
303305
test.only(testName, callback);
304306
} else {
307+
const error = new Error(gatedErrorMessage);
308+
Error.captureStackTrace(error, global._test_gate_focus);
305309
test.only(`[GATED, SHOULD FAIL] ${testName}`, () =>
306-
expectTestToFail(callback, gatedErrorMessage));
310+
expectTestToFail(callback, error));
307311
}
308312
};
309313

0 commit comments

Comments
 (0)