diff --git a/packages/babel-node/src/babel-node.js b/packages/babel-node/src/babel-node.js index bbd64140b9..a9c9c74c63 100755 --- a/packages/babel-node/src/babel-node.js +++ b/packages/babel-node/src/babel-node.js @@ -96,6 +96,7 @@ getV8Flags(async function (err, v8Flags) { } }); }); + proc.on("message", message => process.send && process.send(message)); process.on("SIGINT", () => proc.kill("SIGINT")); } }); diff --git a/packages/babel-node/test/fixtures/misc/child.js b/packages/babel-node/test/fixtures/misc/child.js new file mode 100644 index 0000000000..664224a509 --- /dev/null +++ b/packages/babel-node/test/fixtures/misc/child.js @@ -0,0 +1 @@ +process.send("hello"); diff --git a/packages/babel-node/test/index.js b/packages/babel-node/test/index.js new file mode 100644 index 0000000000..00742f0d00 --- /dev/null +++ b/packages/babel-node/test/index.js @@ -0,0 +1,27 @@ +import { spawn } from "child_process"; +import path from "path"; +import { fileURLToPath } from "url"; + +const dirname = path.dirname(fileURLToPath(import.meta.url)); +const binLoc = path.join(dirname, "../bin/babel-node.js"); +const childLoc = path.join(dirname, "fixtures/misc/child.js"); + +describe("babel-node", () => { + it("ipc works with spawned babel-node process", done => { + expect.assertions(1); + + const child = spawn(process.execPath, [binLoc, childLoc], { + stdio: ["inherit", "inherit", "inherit", "ipc"], + }); + + child.on("message", msg => { + expect(msg).toBe("hello"); + done(); + }); + child.on("error", error => { + console.error(error); + done(); + }); + child.on("exit", () => done()); + }, /* timeout */ 20_000); +});