Skip to content

Commit 6a7cea2

Browse files
rubennortefacebook-github-bot
authored andcommitted
Fix reporting of errors during test setup (#51704)
Summary: Pull Request resolved: #51704 Changelog: [internal] If you create a Fantom test that throws an error during its setup (not during the execution of specific tests), Fantom fails with an error saying there are no tests defined, which isn't useful. This fixes the problem and shows where the error in the test setup happened exactly. Reviewed By: javache Differential Revision: D75689283 fbshipit-source-id: 54dd2382868dda0d284f46743ed94ba94aa3afdc
1 parent 96fe4a5 commit 6a7cea2

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

  • packages/react-native-fantom/runtime

packages/react-native-fantom/runtime/setup.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,13 @@ global.jest = {
190190

191191
global.expect = expect;
192192

193+
let testSetupError: ?Error;
194+
193195
function runWithGuard(fn: () => void) {
194196
try {
195197
fn();
196198
} catch (error) {
197-
let reportedError =
198-
error instanceof Error ? error : new Error(String(error));
199-
reportTestSuiteResult({
200-
error: {
201-
message: reportedError.message,
202-
stack: reportedError.stack,
203-
},
204-
});
199+
testSetupError = error instanceof Error ? error : new Error(String(error));
205200
}
206201
}
207202

@@ -400,9 +395,18 @@ function validateEmptyMessageQueue(): void {
400395
}
401396

402397
global.$$RunTests$$ = () => {
403-
reportTestSuiteResult({
404-
testResults: runSuite(currentContext),
405-
});
398+
if (testSetupError != null) {
399+
reportTestSuiteResult({
400+
error: {
401+
message: testSetupError.message,
402+
stack: testSetupError.stack,
403+
},
404+
});
405+
} else {
406+
reportTestSuiteResult({
407+
testResults: runSuite(currentContext),
408+
});
409+
}
406410
};
407411

408412
export function registerTest(

0 commit comments

Comments
 (0)