fix: make @babel/node spawned process bubble msg (#13037)

* Add ipc test

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
KevinMolotov 2021-03-22 16:26:33 +01:00 committed by Nicolò Ribaudo
parent afef4f85ff
commit b360d8d614
3 changed files with 29 additions and 0 deletions

View File

@ -96,6 +96,7 @@ getV8Flags(async function (err, v8Flags) {
} }
}); });
}); });
proc.on("message", message => process.send && process.send(message));
process.on("SIGINT", () => proc.kill("SIGINT")); process.on("SIGINT", () => proc.kill("SIGINT"));
} }
}); });

View File

@ -0,0 +1 @@
process.send("hello");

View File

@ -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);
});