diff options
author | 2023-10-17 01:31:14 +0300 | |
---|---|---|
committer | 2023-10-16 15:31:14 -0700 | |
commit | f1658e2e58acb1fcdb3181e8238c50b961b822f6 (patch) | |
tree | b715ab7d02e5f8731d9d83db7581db7b10b49666 | |
parent | 90d7f335223d95cb0e603d95fd995dcfb7e6cefa (diff) | |
download | bun-f1658e2e58acb1fcdb3181e8238c50b961b822f6.tar.gz bun-f1658e2e58acb1fcdb3181e8238c50b961b822f6.tar.zst bun-f1658e2e58acb1fcdb3181e8238c50b961b822f6.zip |
fix-subprocess-argument-missing (#6407)
* fix-subprocess-argument-missing
* fix-tests
* nitpick, these should === not just be undefined
---------
Co-authored-by: dave caruso <me@paperdave.net>
-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(); + }); + }); }); }); } |