diff options
-rw-r--r-- | src/bun.js/api/bun/subprocess.zig | 2 | ||||
-rw-r--r-- | test/js/bun/spawn/bun-ipc-child-respond.js | 4 | ||||
-rw-r--r-- | test/js/bun/spawn/bun-ipc-child.js | 1 | ||||
-rw-r--r-- | test/js/bun/spawn/spawn.test.ts | 35 |
4 files changed, 40 insertions, 2 deletions
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index b6e27d287..1bed014f4 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -2060,7 +2060,7 @@ pub const Subprocess = struct { const result = cb.callWithThis( this.globalThis, this.this_jsvalue, - &[_]JSValue{data}, + &[_]JSValue{ data, this.this_jsvalue }, ); data.ensureStillAlive(); if (result.isAnyError()) { diff --git a/test/js/bun/spawn/bun-ipc-child-respond.js b/test/js/bun/spawn/bun-ipc-child-respond.js new file mode 100644 index 000000000..5cf3ce97f --- /dev/null +++ b/test/js/bun/spawn/bun-ipc-child-respond.js @@ -0,0 +1,4 @@ + +process.on("message", (message) => { + process.send("pong:" + message); +});
\ No newline at end of file diff --git a/test/js/bun/spawn/bun-ipc-child.js b/test/js/bun/spawn/bun-ipc-child.js new file mode 100644 index 000000000..5bad9f49a --- /dev/null +++ b/test/js/bun/spawn/bun-ipc-child.js @@ -0,0 +1 @@ +process.send("hello");
\ No newline at end of file diff --git a/test/js/bun/spawn/spawn.test.ts b/test/js/bun/spawn/spawn.test.ts index 897a16635..139eddb33 100644 --- a/test/js/bun/spawn/spawn.test.ts +++ b/test/js/bun/spawn/spawn.test.ts @@ -1,7 +1,8 @@ import { ArrayBufferSink, readableStreamToText, spawn, spawnSync, write } from "bun"; import { describe, expect, it } from "bun:test"; -import { gcTick as _gcTick, bunEnv } from "harness"; +import { gcTick as _gcTick, bunExe } from "harness"; import { rmSync, writeFileSync } from "node:fs"; +import path from "path"; for (let [gcTick, label] of [ [_gcTick, "gcTick"], @@ -440,6 +441,38 @@ for (let [gcTick, label] of [ }); } }); + + describe("ipc", () => { + it("the subprocess should be defined and the child should send", done => { + gcTick(); + const returned_subprocess = spawn([bunExe(), path.join(__dirname, "bun-ipc-child.js")], { + ipc: (message, subProcess) => { + expect(subProcess).toBe(returned_subprocess); + expect(message).toBe("hello"); + subProcess.kill(); + done(); + gcTick(); + }, + }); + }); + + it("the subprocess should receive the parent message and respond back", done => { + gcTick(); + + const parentMessage = "I am your father"; + const childProc = spawn([bunExe(), path.join(__dirname, "bun-ipc-child-respond.js")], { + ipc: (message, subProcess) => { + expect(message).toBe(`pong:${parentMessage}`); + subProcess.kill(); + done(); + gcTick(); + }, + }); + + childProc.send(parentMessage); + gcTick(); + }); + }); }); }); } |