Skip to content

Commit 9640d63

Browse files
authored
Fix node-tests package to propagate errors (#276)
* Fix node-tests asserts being swallowed * Add script to run mocha-remote and metro alone
1 parent b1d0dde commit 9640d63

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

apps/test-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"android": "react-native run-android --no-packager --active-arch-only",
88
"ios": "react-native run-ios --no-packager",
99
"pod-install": "cd ios && pod install",
10+
"mocha-and-metro": "mocha-remote --exit-on-error -- node --run metro",
1011
"test:android": "mocha-remote --exit-on-error -- concurrently --kill-others-on-fail --passthrough-arguments npm:metro 'npm:android -- {@}' --",
1112
"test:android:allTests": "MOCHA_REMOTE_CONTEXT=allTests node --run test:android -- ",
1213
"test:android:nodeAddonExamples": "MOCHA_REMOTE_CONTEXT=nodeAddonExamples node --run test:android -- ",

packages/node-tests/rolldown.config.mts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ function testSuiteConfig(suitePath: string): RolldownOptions[] {
6464
delimiters: ["", ""],
6565
},
6666
),
67+
replacePlugin(
68+
{
69+
// Replace the default export to return a function instead of initializing the addon immediately
70+
// This allows the test runner to intercept any errors which would normally be thrown when importing
71+
// to work around Metro's `guardedLoadModule` swallowing errors during module initialization
72+
// See https://github.com/facebook/metro/blob/34bb8913ec4b5b02690b39d2246599faf094f721/packages/metro-runtime/src/polyfills/require.js#L348-L353
73+
"export default require_test();": "export default require_test;",
74+
},
75+
{
76+
delimiters: ["", ""],
77+
},
78+
),
6779
aliasPlugin({
6880
entries: [
6981
{

packages/node-tests/scripts/generate-entrypoint.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function suiteToString(suite: TestSuite, indent = 1): string {
3636
return Object.entries(suite)
3737
.map(([key, value]) => {
3838
if (typeof value === "string") {
39-
return `${padding}"${key}": () => require("./${value}")`;
39+
return `${padding}"${key}": require("./${value}")`;
4040
} else {
4141
return `${padding}"${key}": {\n${suiteToString(
4242
value,

0 commit comments

Comments
 (0)