2019-08-15 21:06:54 +00:00
|
|
|
import * as cp from "child_process";
|
|
|
|
import { Readable } from "stream";
|
|
|
|
import test from "ava";
|
|
|
|
import { expect } from "chai";
|
2019-12-02 21:02:40 +00:00
|
|
|
import mhysa from "../src";
|
|
|
|
const { duplex } = mhysa();
|
2019-08-15 21:06:54 +00:00
|
|
|
|
|
|
|
test.cb(
|
|
|
|
"duplex() combines a writable and readable stream into a ReadWrite stream",
|
|
|
|
t => {
|
|
|
|
t.plan(1);
|
|
|
|
const source = new Readable();
|
|
|
|
const catProcess = cp.exec("cat");
|
|
|
|
let out = "";
|
|
|
|
source
|
|
|
|
.pipe(duplex(catProcess.stdin!, catProcess.stdout!))
|
|
|
|
.on("data", chunk => (out += chunk))
|
|
|
|
.on("error", t.end)
|
|
|
|
.on("end", () => {
|
|
|
|
expect(out).to.equal("abcdef");
|
|
|
|
t.pass();
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
source.push("ab");
|
|
|
|
source.push("cd");
|
|
|
|
source.push("ef");
|
|
|
|
source.push(null);
|
|
|
|
},
|
|
|
|
);
|