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,
|
2020-07-14 15:24:17 -04:00
|
|
|
"highWaterMark must be a positive number or Infinity. Received:",
|
2020-05-20 20:18:43 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
new ReadableStream<number>(
|
|
|
|
undefined,
|
2020-06-02 00:24:44 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-07-14 15:24:17 -04:00
|
|
|
{ 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,
|
2020-07-14 15:24:17 -04:00
|
|
|
new CountQueuingStrategy({ highWaterMark }),
|
2020-05-20 20:18:43 -04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
RangeError,
|
2020-07-14 15:24:17 -04:00
|
|
|
"highWaterMark must be a positive number or Infinity. Received:",
|
2020-05-20 20:18:43 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
new WritableStream(
|
|
|
|
undefined,
|
2020-06-02 00:24:44 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-07-14 15:24:17 -04:00
|
|
|
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,
|
2020-07-14 15:24:17 -04:00
|
|
|
"highWaterMark must be a positive number or Infinity. Received:",
|
2020-05-20 20:18:43 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertThrows(() => {
|
|
|
|
new TransformStream(
|
|
|
|
undefined,
|
|
|
|
undefined,
|
2020-06-02 00:24:44 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-07-14 15:24:17 -04:00
|
|
|
{ highWaterMark: Symbol("hwmk") as any },
|
2020-05-20 20:18:43 -04:00
|
|
|
);
|
|
|
|
}, TypeError);
|
|
|
|
});
|