Skip to content

Commit eea275b

Browse files
committed
Fix node-tests asserts being swallowed
1 parent 0419678 commit eea275b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/node-tests/rolldown.config.mts

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

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)