From 74ce415118bb8921127ef1f03a8c113d949ee56f Mon Sep 17 00:00:00 2001 From: Lewis Diamond Date: Sat, 4 Jul 2020 10:43:52 -0400 Subject: [PATCH] Update tests make export a bit nicer --- src/functions/index.ts | 2 +- src/index.ts | 8 +--- tests/accumulator.spec.ts | 79 ++++++++++++++++++++++++++------- tests/batch.spec.ts | 4 +- tests/child.spec.ts | 4 +- tests/collect.spec.ts | 4 +- tests/compose.spec.ts | 83 +++++++++++------------------------ tests/concat.spec.ts | 4 +- tests/defaultOptions.spec.ts | 8 ++-- tests/demux.spec.ts | 8 ++-- tests/duplex.spec.ts | 4 +- tests/filter.spec.ts | 4 +- tests/flatMap.spec.ts | 4 +- tests/fromArray.spec.ts | 4 +- tests/join.spec.ts | 4 +- tests/last.spec.ts | 4 +- tests/map.spec.ts | 4 +- tests/merge.spec.ts | 4 +- tests/parallelMap.spec.ts | 4 +- tests/parse.spec.ts | 4 +- tests/rate.spec.ts | 4 +- tests/reduce.spec.ts | 4 +- tests/replace.spec.ts | 4 +- tests/split.spec.ts | 4 +- tests/stringify.spec.ts | 4 +- tests/unbatch.spec.ts | 4 +- tests/utils/collected.spec.ts | 4 +- 27 files changed, 141 insertions(+), 131 deletions(-) diff --git a/src/functions/index.ts b/src/functions/index.ts index 7ffd8d0..ac53414 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -28,7 +28,7 @@ import { unbatch } from "./unbatch"; import { compose } from "./compose"; import { demux } from "./demux"; -export default function strom(defaultOptions?: TransformOptions) { +export function strom(defaultOptions?: TransformOptions) { function withDefaultOptions( n: number, fn: (...args: T) => R, diff --git a/src/index.ts b/src/index.ts index 35da6da..d6124ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,2 @@ -import mhysa from "./functions"; -import * as _utils from "./utils"; -export default mhysa; - -// @TODO fix this with proper import export -export const utils = { ..._utils }; +export { strom } from "./functions"; +export * from "./utils"; diff --git a/tests/accumulator.spec.ts b/tests/accumulator.spec.ts index bb07a3b..467bf17 100644 --- a/tests/accumulator.spec.ts +++ b/tests/accumulator.spec.ts @@ -1,10 +1,10 @@ import test from "ava"; import { expect } from "chai"; import { Readable } from "stream"; -import mhysa from "../src"; +import { strom } from "../src"; import { FlushStrategy } from "../src/functions/accumulator"; import { performance } from "perf_hooks"; -const { accumulator, accumulatorBy } = mhysa({ objectMode: true }); +const { accumulator, accumulatorBy } = strom({ objectMode: true }); test.cb("accumulator() rolling", t => { t.plan(3); @@ -14,8 +14,14 @@ test.cb("accumulator() rolling", t => { key: string; } const source = new Readable({ objectMode: true }); - const firstFlush = [{ ts: 0, key: "a" }, { ts: 1, key: "b" }]; - const secondFlush = [{ ts: 2, key: "d" }, { ts: 3, key: "e" }]; + const firstFlush = [ + { ts: 0, key: "a" }, + { ts: 1, key: "b" }, + ]; + const secondFlush = [ + { ts: 2, key: "d" }, + { ts: 3, key: "e" }, + ]; const thirdFlush = [{ ts: 4, key: "f" }]; const flushes = [firstFlush, secondFlush, thirdFlush]; @@ -88,7 +94,10 @@ test.cb( "nonExistingKey", { objectMode: true }, ); - const input = [{ ts: 0, key: "a" }, { ts: 1, key: "b" }]; + const input = [ + { ts: 0, key: "a" }, + { ts: 1, key: "b" }, + ]; source .pipe(accumulatorStream) @@ -182,7 +191,10 @@ test.cb("accumulator() sliding", t => { { ts: 4, key: "d" }, ]; const firstFlush = [{ ts: 0, key: "a" }]; - const secondFlush = [{ ts: 0, key: "a" }, { ts: 1, key: "b" }]; + const secondFlush = [ + { ts: 0, key: "a" }, + { ts: 1, key: "b" }, + ]; const thirdFlush = [ { ts: 0, key: "a" }, { ts: 1, key: "b" }, @@ -232,7 +244,10 @@ test.cb("accumulator() sliding with key", t => { { ts: 6, key: "g" }, ]; const firstFlush = [{ ts: 0, key: "a" }]; - const secondFlush = [{ ts: 0, key: "a" }, { ts: 1, key: "b" }]; + const secondFlush = [ + { ts: 0, key: "a" }, + { ts: 1, key: "b" }, + ]; const thirdFlush = [ { ts: 0, key: "a" }, { ts: 1, key: "b" }, @@ -243,8 +258,14 @@ test.cb("accumulator() sliding with key", t => { { ts: 2, key: "c" }, { ts: 3, key: "d" }, ]; - const fifthFlush = [{ ts: 3, key: "d" }, { ts: 5, key: "f" }]; - const sixthFlush = [{ ts: 5, key: "f" }, { ts: 6, key: "g" }]; + const fifthFlush = [ + { ts: 3, key: "d" }, + { ts: 5, key: "f" }, + ]; + const sixthFlush = [ + { ts: 5, key: "f" }, + { ts: 6, key: "g" }, + ]; const flushes = [ firstFlush, @@ -286,7 +307,10 @@ test.cb( "nonExistingKey", { objectMode: true }, ); - const input = [{ ts: 0, key: "a" }, { ts: 1, key: "b" }]; + const input = [ + { ts: 0, key: "a" }, + { ts: 1, key: "b" }, + ]; source .pipe(accumulatorStream) @@ -334,10 +358,22 @@ test.cb( { ts: 6, key: "g" }, ]; const firstFlush = [{ ts: 0, key: "a" }]; - const secondFlush = [{ ts: 0, key: "a" }, { ts: 2, key: "c" }]; - const thirdFlush = [{ ts: 2, key: "c" }, { ts: 3, key: "d" }]; - const fourthFlush = [{ ts: 3, key: "d" }, { ts: 5, key: "f" }]; - const fifthFlush = [{ ts: 5, key: "f" }, { ts: 6, key: "g" }]; + const secondFlush = [ + { ts: 0, key: "a" }, + { ts: 2, key: "c" }, + ]; + const thirdFlush = [ + { ts: 2, key: "c" }, + { ts: 3, key: "d" }, + ]; + const fourthFlush = [ + { ts: 3, key: "d" }, + { ts: 5, key: "f" }, + ]; + const fifthFlush = [ + { ts: 5, key: "f" }, + { ts: 6, key: "g" }, + ]; const flushes = [ firstFlush, @@ -469,7 +505,10 @@ test.cb("accumulatorBy() sliding", t => { { ts: 6, key: "g" }, ]; const firstFlush = [{ ts: 0, key: "a" }]; - const secondFlush = [{ ts: 0, key: "a" }, { ts: 1, key: "b" }]; + const secondFlush = [ + { ts: 0, key: "a" }, + { ts: 1, key: "b" }, + ]; const thirdFlush = [ { ts: 0, key: "a" }, { ts: 1, key: "b" }, @@ -480,8 +519,14 @@ test.cb("accumulatorBy() sliding", t => { { ts: 2, key: "c" }, { ts: 3, key: "d" }, ]; - const fifthFlush = [{ ts: 3, key: "d" }, { ts: 5, key: "f" }]; - const sixthFlush = [{ ts: 5, key: "f" }, { ts: 6, key: "g" }]; + const fifthFlush = [ + { ts: 3, key: "d" }, + { ts: 5, key: "f" }, + ]; + const sixthFlush = [ + { ts: 5, key: "f" }, + { ts: 6, key: "g" }, + ]; const flushes = [ firstFlush, diff --git a/tests/batch.spec.ts b/tests/batch.spec.ts index 4ca3e08..7e059fc 100644 --- a/tests/batch.spec.ts +++ b/tests/batch.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { batch, map, fromArray } = mhysa({ objectMode: true }); +import { strom } from "../src"; +const { batch, map, fromArray } = strom({ objectMode: true }); test.cb("batch() batches chunks together", t => { t.plan(3); diff --git a/tests/child.spec.ts b/tests/child.spec.ts index 0b837b7..6e8fa26 100644 --- a/tests/child.spec.ts +++ b/tests/child.spec.ts @@ -2,8 +2,8 @@ import * as cp from "child_process"; import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { child } = mhysa(); +import { strom } from "../src"; +const { child } = strom(); test.cb( "child() allows easily writing to child process stdin and reading from its stdout", diff --git a/tests/collect.spec.ts b/tests/collect.spec.ts index ae13dc2..122ff51 100644 --- a/tests/collect.spec.ts +++ b/tests/collect.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { collect } = mhysa(); +import { strom } from "../src"; +const { collect } = strom(); test.cb( "collect() collects streamed elements into an array (object, flowing mode)", diff --git a/tests/compose.spec.ts b/tests/compose.spec.ts index 1cbabc1..d6c8363 100644 --- a/tests/compose.spec.ts +++ b/tests/compose.spec.ts @@ -2,9 +2,9 @@ import * as test from "ava"; import { expect } from "chai"; import { sleep } from "../src/helpers"; import { Readable, Writable } from "stream"; -import mhysa from "../src"; +import { strom } from "../src"; import { performance } from "perf_hooks"; -const { compose, map, fromArray } = mhysa({ objectMode: true }); +const { compose, map, fromArray } = strom({ objectMode: true }); test.cb("compose() chains two streams together in the correct order", t => { t.plan(3); @@ -114,13 +114,9 @@ test("compose() writable length should be less than highWaterMark when handing w return chunk; }); - const composed = compose( - [first, second], - undefined, - { - highWaterMark: 2, - }, - ); + const composed = compose([first, second], undefined, { + highWaterMark: 2, + }); composed.on("error", err => { reject(); }); @@ -168,13 +164,9 @@ test("compose() should emit drain event ~rate * highWaterMark ms for every write return chunk; }); - const composed = compose( - [first, second], - undefined, - { - highWaterMark, - }, - ); + const composed = compose([first, second], undefined, { + highWaterMark, + }); composed.on("error", err => { reject(); }); @@ -221,13 +213,9 @@ test.cb( return chunk; }); - const composed = compose( - [first, second], - undefined, - { - highWaterMark: 5, - }, - ); + const composed = compose([first, second], undefined, { + highWaterMark: 5, + }); composed.on("error", err => { t.end(err); @@ -284,13 +272,9 @@ test.cb( { highWaterMark: 1 }, ); - const composed = compose( - [first, second], - undefined, - { - highWaterMark: 5, - }, - ); + const composed = compose([first, second], undefined, { + highWaterMark: 5, + }); composed.on("error", err => { t.end(err); }); @@ -355,13 +339,9 @@ test.cb( { highWaterMark: 2 }, ); - const composed = compose( - [first, second], - undefined, - { - highWaterMark: 5, - }, - ); + const composed = compose([first, second], undefined, { + highWaterMark: 5, + }); composed.on("error", err => { t.end(err); }); @@ -414,13 +394,9 @@ test.cb( return chunk; }); - const composed = compose( - [first, second], - undefined, - { - highWaterMark: 6, - }, - ); + const composed = compose([first, second], undefined, { + highWaterMark: 6, + }); composed.on("error", err => { t.end(err); @@ -470,12 +446,9 @@ test.cb("compose() should be 'destroyable'", t => { return chunk; }); - const composed = compose( - [first, second], - (err: any) => { - t.pass(); - }, - ); + const composed = compose([first, second], (err: any) => { + t.pass(); + }); const fakeSource = new Readable({ objectMode: true, @@ -531,13 +504,9 @@ test.cb("compose() `finish` and `end` propagates", t => { return chunk; }); - const composed = compose( - [first, second], - undefined, - { - highWaterMark: 3, - }, - ); + const composed = compose([first, second], undefined, { + highWaterMark: 3, + }); const fakeSource = new Readable({ objectMode: true, diff --git a/tests/concat.spec.ts b/tests/concat.spec.ts index 350ab65..d77d441 100644 --- a/tests/concat.spec.ts +++ b/tests/concat.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { concat, collect } = mhysa(); +import { strom } from "../src"; +const { concat, collect } = strom(); test.cb( "concat() concatenates multiple readable streams (object, flowing mode)", diff --git a/tests/defaultOptions.spec.ts b/tests/defaultOptions.spec.ts index 3281001..a762929 100644 --- a/tests/defaultOptions.spec.ts +++ b/tests/defaultOptions.spec.ts @@ -1,11 +1,11 @@ import { Readable } from "stream"; import test from "ava"; -import mhysa from "../src"; +import { strom } from "../src"; -const withDefaultOptions = mhysa({ objectMode: true }); -const withoutOptions = mhysa(); +const withDefaultOptions = strom({ objectMode: true }); +const withoutOptions = strom(); -test("Mhysa instances can have default options", t => { +test("strom instances can have default options", t => { let batch = withDefaultOptions.batch(); t.true(batch._readableState.objectMode); t.true(batch._writableState.objectMode); diff --git a/tests/demux.spec.ts b/tests/demux.spec.ts index b8c8a5f..b3ca157 100644 --- a/tests/demux.spec.ts +++ b/tests/demux.spec.ts @@ -1,11 +1,11 @@ import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; +import { strom } from "../src"; import { Writable, Readable } from "stream"; -const sinon = require("sinon"); -const { sleep } = require("../src/helpers"); +import * as sinon from "sinon"; +import { sleep } from "../src/helpers"; import { performance } from "perf_hooks"; -const { demux, map, fromArray } = mhysa({ objectMode: true }); +const { demux, map, fromArray } = strom({ objectMode: true }); interface Test { key: string; diff --git a/tests/duplex.spec.ts b/tests/duplex.spec.ts index f0838d4..b477482 100644 --- a/tests/duplex.spec.ts +++ b/tests/duplex.spec.ts @@ -2,8 +2,8 @@ import * as cp from "child_process"; import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { duplex } = mhysa(); +import { strom } from "../src"; +const { duplex } = strom(); test.cb( "duplex() combines a writable and readable stream into a ReadWrite stream", diff --git a/tests/filter.spec.ts b/tests/filter.spec.ts index 9d3e7c0..eaf6128 100644 --- a/tests/filter.spec.ts +++ b/tests/filter.spec.ts @@ -1,8 +1,8 @@ import test from "ava"; import { expect } from "chai"; import { Readable } from "stream"; -import mhysa from "../src"; -const { filter } = mhysa(); +import { strom } from "../src"; +const { filter } = strom(); test.cb("filter() filters elements synchronously", t => { t.plan(2); diff --git a/tests/flatMap.spec.ts b/tests/flatMap.spec.ts index 6a1b468..1697b15 100644 --- a/tests/flatMap.spec.ts +++ b/tests/flatMap.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { flatMap } = mhysa({ objectMode: true }); +import { strom } from "../src"; +const { flatMap } = strom({ objectMode: true }); test.cb("flatMap() maps elements synchronously", t => { t.plan(6); diff --git a/tests/fromArray.spec.ts b/tests/fromArray.spec.ts index 7416923..84d9f0b 100644 --- a/tests/fromArray.spec.ts +++ b/tests/fromArray.spec.ts @@ -1,7 +1,7 @@ import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { fromArray } = mhysa(); +import { strom } from "../src"; +const { fromArray } = strom(); test.cb("fromArray() streams array elements in flowing mode", t => { t.plan(3); diff --git a/tests/join.spec.ts b/tests/join.spec.ts index 06cf717..403f80f 100644 --- a/tests/join.spec.ts +++ b/tests/join.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { join } = mhysa(); +import { strom } from "../src"; +const { join } = strom(); test.cb("join() joins chunks using the specified separator", t => { t.plan(9); diff --git a/tests/last.spec.ts b/tests/last.spec.ts index 7c6f321..a5ae2d2 100644 --- a/tests/last.spec.ts +++ b/tests/last.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { last } = mhysa(); +import { strom } from "../src"; +const { last } = strom(); test("last() resolves to the last chunk streamed by the given readable stream", async t => { const source = new Readable({ objectMode: true }); diff --git a/tests/map.spec.ts b/tests/map.spec.ts index 7c416d6..8898e54 100644 --- a/tests/map.spec.ts +++ b/tests/map.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { map } = mhysa(); +import { strom } from "../src"; +const { map } = strom(); test.cb("map() maps elements synchronously", t => { t.plan(3); diff --git a/tests/merge.spec.ts b/tests/merge.spec.ts index 3fe769f..6d50605 100644 --- a/tests/merge.spec.ts +++ b/tests/merge.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { merge } = mhysa(); +import { strom } from "../src"; +const { merge } = strom(); test.cb( "merge() merges multiple readable streams in chunk arrival order", diff --git a/tests/parallelMap.spec.ts b/tests/parallelMap.spec.ts index 89a80ca..9214464 100644 --- a/tests/parallelMap.spec.ts +++ b/tests/parallelMap.spec.ts @@ -2,9 +2,9 @@ import { Readable } from "stream"; import { performance } from "perf_hooks"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; +import { strom } from "../src"; import { sleep } from "../src/helpers"; -const { parallelMap } = mhysa({ objectMode: true }); +const { parallelMap } = strom({ objectMode: true }); test.cb("parallelMap() parallel mapping", t => { t.plan(6); diff --git a/tests/parse.spec.ts b/tests/parse.spec.ts index a65a109..4eed5fa 100644 --- a/tests/parse.spec.ts +++ b/tests/parse.spec.ts @@ -1,8 +1,8 @@ import { Readable, finished } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { parse } = mhysa(); +import { strom } from "../src"; +const { parse } = strom(); test.cb("parse() parses the streamed elements as JSON", t => { t.plan(3); diff --git a/tests/rate.spec.ts b/tests/rate.spec.ts index 8d88841..31fe5fe 100644 --- a/tests/rate.spec.ts +++ b/tests/rate.spec.ts @@ -2,8 +2,8 @@ import { Readable } from "stream"; import { performance } from "perf_hooks"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { rate } = mhysa({ objectMode: true }); +import { strom } from "../src"; +const { rate } = strom({ objectMode: true }); test.cb("rate() sends data at a rate of 150", t => { t.plan(5); diff --git a/tests/reduce.spec.ts b/tests/reduce.spec.ts index de70740..3cbef0a 100644 --- a/tests/reduce.spec.ts +++ b/tests/reduce.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { reduce } = mhysa({ objectMode: true }); +import { strom } from "../src"; +const { reduce } = strom({ objectMode: true }); test.cb("reduce() reduces elements synchronously", t => { t.plan(1); diff --git a/tests/replace.spec.ts b/tests/replace.spec.ts index 7297759..ffcba5b 100644 --- a/tests/replace.spec.ts +++ b/tests/replace.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { replace } = mhysa(); +import { strom } from "../src"; +const { replace } = strom(); test.cb( "replace() replaces occurrences of the given string in the streamed elements with the specified " + diff --git a/tests/split.spec.ts b/tests/split.spec.ts index 9f287d0..ea77a1b 100644 --- a/tests/split.spec.ts +++ b/tests/split.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { split } = mhysa(); +import { strom } from "../src"; +const { split } = strom(); test.cb("split() splits chunks using the default separator (\\n)", t => { t.plan(5); diff --git a/tests/stringify.spec.ts b/tests/stringify.spec.ts index fb138ef..8695654 100644 --- a/tests/stringify.spec.ts +++ b/tests/stringify.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { stringify } = mhysa(); +import { strom } from "../src"; +const { stringify } = strom(); test.cb("stringify() stringifies the streamed elements as JSON", t => { t.plan(4); diff --git a/tests/unbatch.spec.ts b/tests/unbatch.spec.ts index c3351cf..93c2c80 100644 --- a/tests/unbatch.spec.ts +++ b/tests/unbatch.spec.ts @@ -1,8 +1,8 @@ import { Readable } from "stream"; import test from "ava"; import { expect } from "chai"; -import mhysa from "../src"; -const { unbatch, batch } = mhysa({ objectMode: true }); +import { strom } from "../src"; +const { unbatch, batch } = strom({ objectMode: true }); test.cb("unbatch() unbatches", t => { t.plan(3); diff --git a/tests/utils/collected.spec.ts b/tests/utils/collected.spec.ts index 583427c..3aa1676 100644 --- a/tests/utils/collected.spec.ts +++ b/tests/utils/collected.spec.ts @@ -1,7 +1,7 @@ import test from "ava"; import { collected } from "../../src/utils"; -import mhysa from "../../src"; -const { fromArray, collect } = mhysa({ objectMode: true }); +import { strom } from "../../src"; +const { fromArray, collect } = strom({ objectMode: true }); test("collected returns a promise for the first data point", async t => { const data = collected(fromArray([1, 2, 3, 4]).pipe(collect()));