deno.land / std@0.177.1 / streams / limited_transform_stream_test.ts

limited_transform_stream_test.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
40
41
42
43
44
45
46
47
48
49
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertRejects } from "../testing/asserts.ts";import { LimitedTransformStream } from "./limited_transform_stream.ts";
Deno.test("[streams] LimitedTransformStream", async function () { const r = new ReadableStream({ start(controller) { controller.enqueue("foo"); controller.enqueue("foo"); controller.enqueue("foo"); controller.enqueue("foo"); controller.enqueue("foo"); controller.enqueue("foo"); controller.close(); }, });
const chunks = []; for await (const chunk of r.pipeThrough(new LimitedTransformStream(3))) { chunks.push(chunk); } assertEquals(chunks.length, 3);});
Deno.test("[streams] LimitedTransformStream error", async function () { const r = new ReadableStream({ start(controller) { controller.enqueue("foo"); controller.enqueue("foo"); controller.enqueue("foo"); controller.enqueue("foo"); controller.enqueue("foo"); controller.enqueue("foo"); controller.close(); }, });
await assertRejects(async () => { for await ( const _chunk of r.pipeThrough( new LimitedTransformStream(3, { error: true }), ) ) { // needed to read } }, RangeError);});
std

Version Info

Tagged at
10 months ago