aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Derrick Farris <mr.dcfarris@gmail.com> 2022-11-08 17:33:47 -0600
committerGravatar GitHub <noreply@github.com> 2022-11-08 15:33:47 -0800
commit9ccc455f8d71e46b8bd967317a2e0e907db27012 (patch)
tree8f3585457438de35ffc1662b44e0f9a7184233c8 /src
parent8b0a3c75cb98f5026de668b3a23d2e42f94e5d1a (diff)
downloadbun-9ccc455f8d71e46b8bd967317a2e0e907db27012.tar.gz
bun-9ccc455f8d71e46b8bd967317a2e0e907db27012.tar.zst
bun-9ccc455f8d71e46b8bd967317a2e0e907db27012.zip
Fix child_process tests (#1471)
* test(child_process): fix broken tests, add our-assert pkg for testing * test(child_process): replace console.log with debug() * test(child_process): rename our-assert -> node-test-helpers, use Bun.peek for subproc.exited
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/child_process.exports.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/bun.js/child_process.exports.js b/src/bun.js/child_process.exports.js
index 9219e3ab6..eff7bfca0 100644
--- a/src/bun.js/child_process.exports.js
+++ b/src/bun.js/child_process.exports.js
@@ -9,6 +9,10 @@ const {
const MAX_BUFFER = 1024 * 1024;
const debug = process.env.DEBUG ? console.log : () => {};
+const platformTmpDir = `${process.platform === "darwin" ? "/private" : ""}${
+ process.env.TMPDIR
+}`.slice(0, -1); // remove trailing slash
+
// Sections:
// 1. Exported child_process functions
// 2. child_process helpers
@@ -253,8 +257,7 @@ export function execFile(file, args, options, callback) {
stderr = BufferConcat(_stderr);
}
- // TODO: Make this check code === 0 when Bun.spawn fixes exit code issue
- if (!ex && code >= 0 && signal === null) {
+ if (!ex && code === 0 && signal === null) {
callback(null, stdout, stderr);
return;
}
@@ -843,6 +846,7 @@ function checkExecSyncError(ret, args, cmd) {
//------------------------------------------------------------------------------
export class ChildProcess extends EventEmitter {
#handle;
+ #handleExited;
#exited = false;
#closesNeeded = 1;
#closesGot = 0;
@@ -865,12 +869,12 @@ export class ChildProcess extends EventEmitter {
// this.#handle[owner_symbol] = this;
// }
- #handleOnExit(exitCode, signalCode) {
+ async #handleOnExit(exitCode, signalCode) {
if (this.#exited) return;
if (signalCode) {
this.signalCode = signalCode;
} else {
- this.exitCode = exitCode;
+ this.exitCode = this.#handle.exitCode;
}
if (this.stdin) {
@@ -890,6 +894,12 @@ export class ChildProcess extends EventEmitter {
err.spawnargs = ArrayPrototypeSlice.call(this.spawnargs, 1);
this.emit("error", err);
} else {
+ const maybeExited = Bun.peek(this.#handleExited);
+ if (maybeExited === this.#handleExited) {
+ this.exitCode = await this.#handleExited;
+ } else {
+ this.exitCode = maybeExited;
+ }
this.emit("exit", this.exitCode, this.signalCode);
}
@@ -979,6 +989,7 @@ export class ChildProcess extends EventEmitter {
env: options.envPairs || undefined,
onExit: this.#handleOnExit.bind(this),
});
+ this.#handleExited = this.#handle.exited;
this.stdio = this.#getBunSpawnIo(bunStdio, options);
this.stdin = this.stdio[0];