Skip to content

Commit

Permalink
fix: make @babel/node spawned process bubble msg (#13037)
Browse files Browse the repository at this point in the history
* Add ipc test

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
  • Loading branch information
KevinMolotov and nicolo-ribaudo committed Mar 23, 2021
1 parent afef4f8 commit b360d8d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/babel-node/src/babel-node.js
Expand Up @@ -96,6 +96,7 @@ getV8Flags(async function (err, v8Flags) {
}
});
});
proc.on("message", message => process.send && process.send(message));
process.on("SIGINT", () => proc.kill("SIGINT"));
}
});
1 change: 1 addition & 0 deletions packages/babel-node/test/fixtures/misc/child.js
@@ -0,0 +1 @@
process.send("hello");
27 changes: 27 additions & 0 deletions 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);
});

0 comments on commit b360d8d

Please sign in to comment.