Skip to content

Commit db6bbb4

Browse files
committed
fix: catch sync top-level errors in workerd:bundle
1 parent 058422e commit db6bbb4

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

bin/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,15 @@ if (options.pure) {
716716
const wrapperContent = `
717717
export default {
718718
async test(ctrl, env, ctx) {
719-
await import('./' + ${JSON.stringify(jsRelativePath)});
720-
if (typeof globalThis.EXODUS_TEST_RUN !== 'function') throw new Error('node:test not loaded');
721-
const exitCode = await globalThis.EXODUS_TEST_RUN();
722-
if (exitCode !== 0) throw new Error(\`Tests failed with exit code \${exitCode}\`);
719+
await import('./' + ${JSON.stringify(jsRelativePath)})
720+
let exitCode = EXODUS_TEST_PROCESS.exitCode // can fail early
721+
if (exitCode === 0) {
722+
if (typeof globalThis.EXODUS_TEST_RUN !== 'function') throw new Error('node:test not loaded')
723+
exitCode = await globalThis.EXODUS_TEST_RUN()
724+
}
725+
if (exitCode !== 0) throw new Error(\`Tests failed with exit code \${exitCode}\`)
723726
}
724-
};`
727+
}`
725728
await writeFile(bundled.fileWrapper, wrapperContent)
726729
const configContent = `
727730
using Workerd = import "/workerd/workerd.capnp";

0 commit comments

Comments
 (0)