2020-05-20 20:18:43 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { unitTest, assertThrows } from "./test_util.ts";
|
|
|
|
|
|
|
|
unitTest(function streamReadableHwmError() {
|
2020-06-02 00:24:44 -04:00
|
|
|
// 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(
|
|
|
|
() => {
|
2020-06-02 00:24:44 -04:00
|
|
|
new ReadableStream<number>(undefined, { highWaterMark });
|
2020-05-20 20:18:43 -04:00
|
|
|
},
|
|
|
|
RangeError,
|
|
|
|
"highWaterMark must be a positive number or Infinity. Received:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
new ReadableStream<number>(
|
|
|
|
undefined,
|
2020-06-02 00:24:44 -04:00
|
|
|
// 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() {
|
2020-06-02 00:24:44 -04:00
|
|
|
// 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 })
|
|
|
|
);
|
|
|
|
},
|
|
|
|
RangeError,
|
|
|
|
"highWaterMark must be a positive number or Infinity. Received:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
new WritableStream(
|
|
|
|
undefined,
|
2020-06-02 00:24:44 -04:00
|
|
|
// 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() {
|
2020-06-02 00:24:44 -04:00
|
|
|
// 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(
|
|
|
|
() => {
|
2020-06-02 00:24:44 -04:00
|
|
|
new TransformStream(undefined, undefined, { highWaterMark });
|
2020-05-20 20:18:43 -04:00
|
|
|
},
|
|
|
|
RangeError,
|
|
|
|
"highWaterMark must be a positive number or Infinity. Received:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
new TransformStream(
|
|
|
|
undefined,
|
|
|
|
undefined,
|
2020-06-02 00:24:44 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
{ highWaterMark: Symbol("hwmk") as any }
|
2020-05-20 20:18:43 -04:00
|
|
|
);
|
|
|
|
}, TypeError);
|
|
|
|
});
|