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";
|
2020-07-04 14:43:52 +00:00
|
|
|
import { strom } from "../src";
|
|
|
|
const { duplex } = strom();
|
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);
|
|
|
|
},
|
|
|
|
);
|