2023-01-03 10:47:44 +00:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-11-29 13:55:38 +00:00
|
|
|
|
2023-07-13 07:04:30 +00:00
|
|
|
import { assertEquals, assertRejects } from "../assert/mod.ts";
|
2022-11-29 13:55:38 +00:00
|
|
|
import { LimitedTransformStream } from "./limited_transform_stream.ts";
|
|
|
|
|
|
|
|
Deno.test("[streams] LimitedTransformStream", async function () {
|
2023-11-10 03:57:52 +00:00
|
|
|
const r = ReadableStream.from([
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
2023-11-10 19:00:28 +00:00
|
|
|
]).pipeThrough(new LimitedTransformStream(3));
|
2022-11-29 13:55:38 +00:00
|
|
|
|
2023-11-10 19:00:28 +00:00
|
|
|
const chunks = await Array.fromAsync(r);
|
2022-11-29 13:55:38 +00:00
|
|
|
assertEquals(chunks.length, 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("[streams] LimitedTransformStream error", async function () {
|
2023-11-10 03:57:52 +00:00
|
|
|
const r = ReadableStream.from([
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
2023-11-10 19:00:28 +00:00
|
|
|
]).pipeThrough(new LimitedTransformStream(3, { error: true }));
|
2022-11-29 13:55:38 +00:00
|
|
|
|
2023-11-10 19:00:28 +00:00
|
|
|
await assertRejects(async () => await Array.fromAsync(r), RangeError);
|
2022-11-29 13:55:38 +00:00
|
|
|
});
|