diff --git a/apps/test-app/package.json b/apps/test-app/package.json index 10c33840..08f55a35 100644 --- a/apps/test-app/package.json +++ b/apps/test-app/package.json @@ -7,6 +7,7 @@ "android": "react-native run-android --no-packager --active-arch-only", "ios": "react-native run-ios --no-packager", "pod-install": "cd ios && pod install", + "mocha-and-metro": "mocha-remote --exit-on-error -- node --run metro", "test:android": "mocha-remote --exit-on-error -- concurrently --kill-others-on-fail --passthrough-arguments npm:metro 'npm:android -- {@}' --", "test:android:allTests": "MOCHA_REMOTE_CONTEXT=allTests node --run test:android -- ", "test:android:nodeAddonExamples": "MOCHA_REMOTE_CONTEXT=nodeAddonExamples node --run test:android -- ", diff --git a/packages/node-tests/rolldown.config.mts b/packages/node-tests/rolldown.config.mts index c1b7f327..884b18c7 100644 --- a/packages/node-tests/rolldown.config.mts +++ b/packages/node-tests/rolldown.config.mts @@ -64,6 +64,18 @@ function testSuiteConfig(suitePath: string): RolldownOptions[] { delimiters: ["", ""], }, ), + replacePlugin( + { + // Replace the default export to return a function instead of initializing the addon immediately + // This allows the test runner to intercept any errors which would normally be thrown when importing + // to work around Metro's `guardedLoadModule` swallowing errors during module initialization + // See https://github.com/facebook/metro/blob/34bb8913ec4b5b02690b39d2246599faf094f721/packages/metro-runtime/src/polyfills/require.js#L348-L353 + "export default require_test();": "export default require_test;", + }, + { + delimiters: ["", ""], + }, + ), aliasPlugin({ entries: [ { diff --git a/packages/node-tests/scripts/generate-entrypoint.mts b/packages/node-tests/scripts/generate-entrypoint.mts index a0cf8c8d..49e6478a 100644 --- a/packages/node-tests/scripts/generate-entrypoint.mts +++ b/packages/node-tests/scripts/generate-entrypoint.mts @@ -36,7 +36,7 @@ function suiteToString(suite: TestSuite, indent = 1): string { return Object.entries(suite) .map(([key, value]) => { if (typeof value === "string") { - return `${padding}"${key}": () => require("./${value}")`; + return `${padding}"${key}": require("./${value}")`; } else { return `${padding}"${key}": {\n${suiteToString( value,