use fromArray

This commit is contained in:
Jerry Kurian 2020-01-27 09:29:59 -05:00
parent 11ed6f81e7
commit 2b1308a605

View File

@ -5,7 +5,7 @@ import { Writable } from "stream";
const sinon = require("sinon"); const sinon = require("sinon");
const { sleep } = require("../src/helpers"); const { sleep } = require("../src/helpers");
import { performance } from "perf_hooks"; import { performance } from "perf_hooks";
const { demux, map } = mhysa({ objectMode: true }); const { demux, map, fromArray } = mhysa({ objectMode: true });
interface Test { interface Test {
key: string; key: string;
@ -41,8 +41,7 @@ test.cb("demux() constructor should be called once per key", t => {
t.end(); t.end();
}); });
input.forEach(event => demuxed.write(event)); fromArray(input).pipe(demuxed);
demuxed.end();
}); });
test.cb("demux() should send input through correct pipeline", t => { test.cb("demux() should send input through correct pipeline", t => {
@ -84,8 +83,7 @@ test.cb("demux() should send input through correct pipeline", t => {
t.end(); t.end();
}); });
input.forEach(event => demuxed.write(event)); fromArray(input).pipe(demuxed);
demuxed.end();
}); });
test.cb("demux() constructor should be called once per key using keyBy", t => { test.cb("demux() constructor should be called once per key using keyBy", t => {
@ -108,7 +106,9 @@ test.cb("demux() constructor should be called once per key using keyBy", t => {
return dest; return dest;
}); });
const demuxed = demux(construct, item => item.key, { objectMode: true }); const demuxed = demux(construct, item => item.key, {
objectMode: true,
});
demuxed.on("finish", () => { demuxed.on("finish", () => {
expect(construct.withArgs("a").callCount).to.equal(1); expect(construct.withArgs("a").callCount).to.equal(1);
@ -118,8 +118,7 @@ test.cb("demux() constructor should be called once per key using keyBy", t => {
t.end(); t.end();
}); });
input.forEach(event => demuxed.write(event)); fromArray(input).pipe(demuxed);
demuxed.end();
}); });
test.cb("demux() should send input through correct pipeline using keyBy", t => { test.cb("demux() should send input through correct pipeline using keyBy", t => {
@ -161,8 +160,7 @@ test.cb("demux() should send input through correct pipeline using keyBy", t => {
t.end(); t.end();
}); });
input.forEach(event => demuxed.write(event)); fromArray(input).pipe(demuxed);
demuxed.end();
}); });
test("demux() write should return false after if it has >= highWaterMark items buffered and drain should be emitted", t => { test("demux() write should return false after if it has >= highWaterMark items buffered and drain should be emitted", t => {
@ -697,5 +695,5 @@ test.cb("Demux should remux to sink", t => {
remultiplex: remux, remultiplex: remux,
}); });
input.forEach(event => demuxed.write(event)); fromArray(input).pipe(demuxed);
}); });