From 79c0b614ee04d06d9565cd52450b0de1f58fa87e Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Mon, 23 Jan 2023 15:59:45 -0800 Subject: fix child process node test hang (#1884) * fix test hang from skipped tests * add error target --- test/bun.js/child_process-node.test.js | 16 ++++++++++------ test/bun.js/spawned-child.js | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'test/bun.js') diff --git a/test/bun.js/child_process-node.test.js b/test/bun.js/child_process-node.test.js index 664fc8f8b..a225172ce 100644 --- a/test/bun.js/child_process-node.test.js +++ b/test/bun.js/child_process-node.test.js @@ -170,7 +170,7 @@ describe("ChildProcess spawn bad stdio", () => { // Monkey patch spawn() to create a child process normally, but destroy the // stdout and stderr streams. This replicates the conditions where the streams // cannot be properly created. - function createChild(options, callback, done) { + function createChild(options, callback, done, target) { var __originalSpawn = ChildProcess.prototype.spawn; ChildProcess.prototype.spawn = function () { const err = __originalSpawn.apply(this, arguments); @@ -182,13 +182,14 @@ describe("ChildProcess spawn bad stdio", () => { }; const { mustCall } = createCallCheckCtx(done); - const cmd = `bun ${__dirname}/spawned-child.js`; + let cmd = `bun ${import.meta.dir}/spawned-child.js`; + if (target) cmd += " " + target; const child = exec(cmd, options, mustCall(callback)); ChildProcess.prototype.spawn = __originalSpawn; return child; } - it.skip("should handle normal execution of child process", (done) => { + it("should handle normal execution of child process", (done) => { createChild( {}, (err, stdout, stderr) => { @@ -200,16 +201,19 @@ describe("ChildProcess spawn bad stdio", () => { ); }); - it.skip("should handle error event of child process", (done) => { - const error = new Error("foo"); + it("should handle error event of child process", (done) => { + const error = new Error( + `Command failed: bun ${import.meta.dir}/spawned-child.js ERROR`, + ); createChild( {}, (err, stdout, stderr) => { - strictEqual(err, error); + strictEqual(err.message, error.message); strictEqual(stdout, ""); strictEqual(stderr, ""); }, done, + "ERROR", ); }); diff --git a/test/bun.js/spawned-child.js b/test/bun.js/spawned-child.js index d39131933..738d42f7e 100644 --- a/test/bun.js/spawned-child.js +++ b/test/bun.js/spawned-child.js @@ -22,6 +22,8 @@ if (TARGET === "STDIN") { }); } else if (TARGET === "STDOUT") { process.stdout.write("stdout_test"); +} else if (TARGET === "ERROR") { + console.log("oops"); } else { - console.log("unknown target! you messed up..."); + // nothing } -- cgit v1.2.3