1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 16:49:18 -05:00
denoland-deno/cli/tests/unit/streams_internal_test.ts

73 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-05-20 20:18:43 -04:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assertThrows, unitTest } from "./test_util.ts";
2020-05-20 20:18:43 -04:00
unitTest(function streamReadableHwmError() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
2020-05-20 20:18:43 -04:00
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new ReadableStream<number>(undefined, { highWaterMark });
2020-05-20 20:18:43 -04:00
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:",
2020-05-20 20:18:43 -04:00
);
}
assertThrows(() => {
new ReadableStream<number>(
undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{ highWaterMark: Symbol("hwk") as any },
2020-05-20 20:18:43 -04:00
);
}, TypeError);
});
unitTest(function streamWriteableHwmError() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
2020-05-20 20:18:43 -04:00
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new WritableStream(
undefined,
new CountQueuingStrategy({ highWaterMark }),
2020-05-20 20:18:43 -04:00
);
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:",
2020-05-20 20:18:43 -04:00
);
}
assertThrows(() => {
new WritableStream(
undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new CountQueuingStrategy({ highWaterMark: Symbol("hwmk") as any }),
2020-05-20 20:18:43 -04:00
);
}, TypeError);
});
unitTest(function streamTransformHwmError() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const invalidHwm: any[] = [NaN, Number("NaN"), {}, -1, "two"];
2020-05-20 20:18:43 -04:00
for (const highWaterMark of invalidHwm) {
assertThrows(
() => {
new TransformStream(undefined, undefined, { highWaterMark });
2020-05-20 20:18:43 -04:00
},
RangeError,
"highWaterMark must be a positive number or Infinity. Received:",
2020-05-20 20:18:43 -04:00
);
}
assertThrows(() => {
new TransformStream(
undefined,
undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{ highWaterMark: Symbol("hwmk") as any },
2020-05-20 20:18:43 -04:00
);
}, TypeError);
});