Compare commits

...

2 Commits

Author SHA1 Message Date
Derrick Farris
78d6743f58 fix(node-test-helpers): make sure to call done with any Errors thrown from wrapped fn 2023-01-11 20:54:40 -06:00
Derrick Farris
f8114d09fd test(child_process): fix assert -> assert.ok 2023-01-11 20:52:15 -06:00
2 changed files with 17 additions and 8 deletions

View File

@@ -180,7 +180,7 @@ describe("ChildProcess.spawn", () => {
// Test that we can call spawn
strictEqual(Object.hasOwn(child, "pid"), true);
assert(Number.isInteger(child.pid));
assert.ok(Number.isInteger(child.pid));
child.kill();
});
@@ -404,7 +404,7 @@ describe("child_process default options", () => {
// NOTE: Original test used child.on("exit"), but this is unreliable
// because the process can exit before the stream is closed and the data is read
child.stdout.on("close", () => {
expect(response.includes(`TMPDIR=${platformTmpDir}`)).toBe(true);
assert.ok(response.includes(`TMPDIR=${platformTmpDir}`));
done();
});
});

View File

@@ -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.