-
Notifications
You must be signed in to change notification settings - Fork 0
/
merges.spec.ts
37 lines (33 loc) · 1007 Bytes
/
merges.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
import { sleep } from "bun";
import sflow from "./index";
import { mergeStream } from "./mergeStream";
it("merge different type", async () => {
expect(
await sflow(mergeStream(["1", "2", "3", "4"], [5, 6, 7, 8])).toArray(),
).toEqual(["1", 5, "2", 6, "3", 7, "4", 8]);
});
it("zips when same speed", async () => {
expect(
await sflow(mergeStream([1, 2, 3, 4], [5, 6, 7, 8])).toArray(),
).toEqual([1, 5, 2, 6, 3, 7, 4, 8]);
});
it("works when a stream slower", async () => {
expect(
await sflow(
mergeStream(
sflow([1, 2, 3, 4]).forEach(() => sleep(30)),
[5, 6, 7, 8],
),
).toArray(),
).toEqual([5, 6, 7, 8, 1, 2, 3, 4]);
});
it("zips in timing order", async () => {
expect(
await sflow(
mergeStream(
sflow([30, 20, 40, 80]).asyncMap(async (ms) => (await sleep(ms), ms)),
sflow([70, 60, 50, 10]).asyncMap(async (ms) => (await sleep(ms), ms)),
),
).toArray(),
).toEqual([10, 20, 30, 40, 50, 60, 70, 80]);
});