diff options
author | 2023-01-11 20:54:40 -0600 | |
---|---|---|
committer | 2023-01-11 20:54:40 -0600 | |
commit | 78d6743f58959d175b94a341cbbe4b4906bb6536 (patch) | |
tree | 9d028409f0cc06637ba8f0ed440a285900ec6a75 | |
parent | f8114d09fdd76d6783fabf49cbeacdde3ad4d6b5 (diff) | |
download | bun-78d6743f58959d175b94a341cbbe4b4906bb6536.tar.gz bun-78d6743f58959d175b94a341cbbe4b4906bb6536.tar.zst bun-78d6743f58959d175b94a341cbbe4b4906bb6536.zip |
fix(node-test-helpers): make sure to call done with any Errors thrown from wrapped fnderrick/fix/node-tests
-rw-r--r-- | test/bun.js/node-test-helpers.ts | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/test/bun.js/node-test-helpers.ts b/test/bun.js/node-test-helpers.ts index ff7b8ece3..25051e3a0 100644 --- a/test/bun.js/node-test-helpers.ts +++ b/test/bun.js/node-test-helpers.ts @@ -128,13 +128,22 @@ export const createCallCheckCtx = (done: DoneCb) => { // mustCallChecks.push(context); const done = createDone(); const _return = (...args) => { - // @ts-ignore - const result = fn.apply(this, args); - actual++; - if (actual >= expected) { - done(); + try { + // @ts-ignore + const result = fn.apply(this, args); + actual++; + if (actual >= expected) { + done(); + } + return result; + } catch (err) { + if (err instanceof Error) done(err); + else if (err?.toString) done(new Error(err?.toString())); + else { + console.error("Unknown error", err); + done(new Error("Unknown error")); + } } - return result; }; // Function instances have own properties that may be relevant. // Let's replicate those properties to the returned function. |