diff options
author | 2023-01-23 15:59:45 -0800 | |
---|---|---|
committer | 2023-01-23 15:59:45 -0800 | |
commit | 79c0b614ee04d06d9565cd52450b0de1f58fa87e (patch) | |
tree | 3bd01e49d3f6ecb3e04bf3ff71552b5c14bf0298 | |
parent | f5cda8ff1871571e3a6e655326fcda56e65e0dfb (diff) | |
download | bun-79c0b614ee04d06d9565cd52450b0de1f58fa87e.tar.gz bun-79c0b614ee04d06d9565cd52450b0de1f58fa87e.tar.zst bun-79c0b614ee04d06d9565cd52450b0de1f58fa87e.zip |
fix child process node test hang (#1884)
* fix test hang from skipped tests
* add error target
-rw-r--r-- | src/bun.js/child_process.exports.js | 4 | ||||
-rw-r--r-- | test/bun.js/child_process-node.test.js | 16 | ||||
-rw-r--r-- | test/bun.js/spawned-child.js | 4 |
3 files changed, 16 insertions, 8 deletions
diff --git a/src/bun.js/child_process.exports.js b/src/bun.js/child_process.exports.js index 7af8bdebd..71d97366a 100644 --- a/src/bun.js/child_process.exports.js +++ b/src/bun.js/child_process.exports.js @@ -290,7 +290,9 @@ export function execFile(file, args, options, callback) { if (args?.length) cmd += ` ${ArrayPrototypeJoin.call(args, " ")}`; if (!ex) { - ex = genericNodeError(`Command failed: ${cmd}\n${stderr}`, { + let message = `Command failed: ${cmd}`; + if (stderr) message += `\n${stderr}`; + ex = genericNodeError(message, { // code: code < 0 ? getSystemErrorName(code) : code, // TODO: Add getSystemErrorName code: code, killed: child.killed || killed, 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 } |