-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.ts
39 lines (31 loc) · 962 Bytes
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import tap from "tap";
import { Collect } from "stream-collect";
import stringify from "./";
import { Readable } from "stream";
const basicArr = [
"string",
0,
["nested", "array", { with: "object" }],
{ key: "value" },
];
tap.test("basic stringification", async (t) => {
const stringified = await Readable.from(basicArr)
.pipe(stringify())
.pipe(new Collect({ encoding: "utf-8" }))
.collect();
t.equal(stringified, JSON.stringify(basicArr));
});
tap.test("empty array", async (t) => {
const stringified = await Readable.from([])
.pipe(stringify())
.pipe(new Collect({ encoding: "utf-8" }))
.collect();
t.equal(stringified, JSON.stringify([]));
});
tap.test("ndjson", async (t) => {
const stringified = await Readable.from(basicArr)
.pipe(stringify("", "", "\n"))
.pipe(new Collect({ encoding: "utf-8" }))
.collect();
t.equal(stringified, basicArr.map((obj) => JSON.stringify(obj)).join("\n"));
});