deno.land / std@0.224.0 / streams / merge_readable_streams_test.ts

merge_readable_streams_test.ts
View Documentation
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
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { mergeReadableStreams } from "./merge_readable_streams.ts";import { assertEquals } from "../assert/mod.ts";
Deno.test("mergeReadableStreams()", async () => { const textStream = ReadableStream.from([ "qwertzuiopasd", "mnbvcxylkjhgfds", "apoiuztrewq0987654321", ]);
const textStream2 = ReadableStream.from([ "mnbvcxylkjhgfds", "apoiuztrewq0987654321", "qwertzuiopasd", ]);
const buf = await Array.fromAsync( mergeReadableStreams(textStream, textStream2), );
assertEquals(buf.sort(), [ "apoiuztrewq0987654321", "apoiuztrewq0987654321", "mnbvcxylkjhgfds", "mnbvcxylkjhgfds", "qwertzuiopasd", "qwertzuiopasd", ]);});
Deno.test("mergeReadableStreams() handles errors", async () => { const textStream = ReadableStream.from(["1", "3"]);
const textStream2 = ReadableStream.from(["2", "4"]);
const buf = []; try { for await (const s of mergeReadableStreams(textStream, textStream2)) { buf.push(s); if (s === "2") { throw new Error("error"); } } throw new Error("should not be here"); } catch (error) { assertEquals((error as Error).message, "error"); assertEquals(buf, ["1", "2"]); }});
std

Version Info

Tagged at
6 months ago