Archived
1
0

Add stdio sources (#17)

This commit is contained in:
Kyle Carberry
2019-01-23 11:52:58 -06:00
parent 704a0defc9
commit 4cd6bed8d2
10 changed files with 157 additions and 47 deletions

View File

@ -1,3 +1,4 @@
import * as cp from "child_process";
import * as net from "net";
import * as os from "os";
import * as path from "path";
@ -8,7 +9,15 @@ import { createClient } from "./helpers";
(<any>global).TextEncoder = TextEncoder;
describe("spawn", () => {
const client = createClient();
const client = createClient({
dataDirectory: "",
workingDirectory: "",
forkProvider: (msg) => {
return cp.spawn(msg.getCommand(), msg.getArgsList(), {
stdio: [null, null, null, "pipe"],
});
},
});
it("should execute command and return output", (done) => {
const proc = client.spawn("echo", ["test"]);
@ -124,11 +133,13 @@ describe("spawn", () => {
proc.on("exit", () => done());
});
it("should fork", (done) => {
it("should fork and echo messages", (done) => {
const proc = client.fork(path.join(__dirname, "forker.js"));
proc.stdout.on("data", (data) => {
expect(data).toEqual("test");
proc.on("message", (msg) => {
expect(msg.bananas).toBeTruthy();
proc.kill();
});
proc.send({ bananas: true }, true);
proc.on("exit", () => done());
});
});

View File

@ -1 +1,3 @@
console.log("test");
process.on("message", (data) => {
process.send(data);
});