-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make sure ipc with json serialization still works when bun is parent …
…and not the child (#14756) Co-authored-by: Jarred Sumner <[email protected]>
- Loading branch information
1 parent
f9de8be
commit 11feeff
Showing
7 changed files
with
97 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
console.log("c start"); | ||
process.on("message", message => { | ||
console.log("c", message); | ||
process.send(message); | ||
process.exit(0); | ||
}); | ||
console.log("c end"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
console.log("c start"); | ||
process.on("message", message => { | ||
console.log("c", message); | ||
process.send(message); | ||
process.exit(0); | ||
}); | ||
console.log("c end"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require("node:path"); | ||
|
||
console.log("p start"); | ||
const child = Bun.spawn(["node", path.resolve(import.meta.dir, "ipc-child-node.js")], { | ||
ipc(message) { | ||
console.log("p", message); | ||
process.exit(0); | ||
}, | ||
stdio: ["ignore", "inherit", "inherit"], | ||
serialization: "json", | ||
}); | ||
|
||
child.send("I am your father"); | ||
console.log("p end"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const path = require("node:path"); | ||
const child_process = require("node:child_process"); | ||
|
||
console.log("p start"); | ||
|
||
const child = child_process.spawn(process.argv[2], [path.resolve(__dirname, "ipc-child-bun.js")], { | ||
stdio: ["ignore", "inherit", "inherit", "ipc"], | ||
}); | ||
child.on("message", message => { | ||
console.log("p", message); | ||
process.exit(0); | ||
}); | ||
|
||
child.send("I am your father"); | ||
console.log("p end"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { spawn } from "bun"; | ||
import { test, expect, it } from "bun:test"; | ||
import { bunExe } from "harness"; | ||
import path from "path"; | ||
|
||
test("ipc with json serialization still works when bun is parent and not the child", async () => { | ||
const child = Bun.spawn([bunExe(), path.resolve(import.meta.dir, "fixtures", "ipc-parent-bun.js")], { | ||
stdio: ["ignore", "pipe", "pipe"], | ||
}); | ||
await child.exited; | ||
expect(await new Response(child.stdout).text()).toEqual( | ||
`p start | ||
p end | ||
c start | ||
c end | ||
c I am your father | ||
p I am your father | ||
`, | ||
); | ||
expect(await new Response(child.stderr).text()).toEqual(""); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { spawn } from "bun"; | ||
import { test, expect, it } from "bun:test"; | ||
import { bunExe, nodeExe } from "harness"; | ||
import path from "path"; | ||
|
||
test("ipc with json serialization still works when bun is not the parent and the child", async () => { | ||
// prettier-ignore | ||
const child = Bun.spawn(["node", "--no-warnings", path.resolve(import.meta.dir, "fixtures", "ipc-parent-node.js"), bunExe()], { | ||
stdio: ["ignore", "pipe", "pipe"], | ||
}); | ||
await child.exited; | ||
expect(await new Response(child.stderr).text()).toEqual(""); | ||
expect(await new Response(child.stdout).text()).toEqual( | ||
`p start | ||
p end | ||
c start | ||
c end | ||
c I am your father | ||
p I am your father | ||
`, | ||
); | ||
}); |