2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-11-29 13:55:38 +00:00
|
|
|
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals, assertRejects } from "@std/assert";
|
2022-11-29 13:55:38 +00:00
|
|
|
import { LimitedTransformStream } from "./limited_transform_stream.ts";
|
|
|
|
|
2024-02-27 20:12:47 +00:00
|
|
|
Deno.test("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);
|
2024-05-28 01:27:40 +00:00
|
|
|
assertEquals(chunks, [
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
"foo",
|
|
|
|
]);
|
2022-11-29 13:55:38 +00:00
|
|
|
});
|
|
|
|
|
2024-02-27 20:12:47 +00:00
|
|
|
Deno.test("LimitedTransformStream handles 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
|
|
|
});
|