aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/js/node/child_process/child_process.test.ts22
-rw-r--r--test/js/node/child_process/fixtures/child-process-exit-event.js13
2 files changed, 35 insertions, 0 deletions
diff --git a/test/js/node/child_process/child_process.test.ts b/test/js/node/child_process/child_process.test.ts
index baf422bc9..8c24ef55e 100644
--- a/test/js/node/child_process/child_process.test.ts
+++ b/test/js/node/child_process/child_process.test.ts
@@ -2,6 +2,8 @@ import { describe, it, expect } from "bun:test";
import { ChildProcess, spawn, execFile, exec, fork, spawnSync, execFileSync, execSync } from "node:child_process";
import { tmpdir } from "node:os";
import { promisify } from "node:util";
+import { bunExe, bunEnv } from "harness";
+import path from "path";
const debug = process.env.DEBUG ? console.log : () => {};
@@ -308,3 +310,23 @@ describe("Bun.spawn()", () => {
// expect(child.pid).toBe(undefined);
// });
});
+
+it("should call close and exit before process exits", async () => {
+ const proc = Bun.spawn({
+ cmd: [bunExe(), path.join("fixtures", "child-process-exit-event.js")],
+ cwd: import.meta.dir,
+ env: bunEnv,
+ stdout: "pipe",
+ });
+ await proc.exited;
+ expect(proc.exitCode).toBe(0);
+ let data = "";
+ const reader = proc.stdout.getReader();
+ while (true) {
+ const { done, value } = await reader.read();
+ if (done) break;
+ data += new TextDecoder().decode(value);
+ }
+ expect(data).toContain("closeHandler called");
+ expect(data).toContain("exithHandler called");
+});
diff --git a/test/js/node/child_process/fixtures/child-process-exit-event.js b/test/js/node/child_process/fixtures/child-process-exit-event.js
new file mode 100644
index 000000000..4400ace1b
--- /dev/null
+++ b/test/js/node/child_process/fixtures/child-process-exit-event.js
@@ -0,0 +1,13 @@
+const { spawn } = require("node:child_process");
+
+function exitHandler() {
+ console.log("exithHandler called");
+}
+function closeHandler() {
+ console.log("closeHandler called");
+}
+
+const p = spawn("bun", ["--version"]);
+
+p.on("exit", exitHandler);
+p.on("close", closeHandler);