2020-05-03 15:10:52 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
assertEquals,
|
|
|
|
assertNotEquals,
|
|
|
|
assertThrows,
|
2020-09-27 06:22:32 -04:00
|
|
|
unitTest,
|
2020-05-03 15:10:52 -04:00
|
|
|
} from "./test_util.ts";
|
|
|
|
|
|
|
|
function delay(seconds: number): Promise<void> {
|
|
|
|
return new Promise<void>((resolve) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
resolve();
|
|
|
|
}, seconds);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function readableStreamToArray<R>(
|
|
|
|
readable: { getReader(): ReadableStreamDefaultReader<R> },
|
2020-07-14 15:24:17 -04:00
|
|
|
reader?: ReadableStreamDefaultReader<R>,
|
2020-05-03 15:10:52 -04:00
|
|
|
): Promise<R[]> {
|
|
|
|
if (reader === undefined) {
|
|
|
|
reader = readable.getReader();
|
|
|
|
}
|
|
|
|
|
|
|
|
const chunks: R[] = [];
|
|
|
|
|
|
|
|
return pump();
|
|
|
|
|
|
|
|
function pump(): Promise<R[]> {
|
|
|
|
return reader!.read().then((result) => {
|
|
|
|
if (result.done) {
|
|
|
|
return chunks;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunks.push(result.value);
|
|
|
|
return pump();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unitTest(function transformStreamConstructedWithTransformFunction() {
|
|
|
|
new TransformStream({ transform(): void {} });
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamConstructedNoTransform() {
|
|
|
|
new TransformStream();
|
|
|
|
new TransformStream({});
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamIntstancesHaveProperProperties() {
|
|
|
|
const ts = new TransformStream({ transform(): void {} });
|
|
|
|
const proto = Object.getPrototypeOf(ts);
|
|
|
|
|
|
|
|
const writableStream = Object.getOwnPropertyDescriptor(proto, "writable");
|
|
|
|
assert(writableStream !== undefined, "it has a writable property");
|
|
|
|
assert(!writableStream.enumerable, "writable should be non-enumerable");
|
|
|
|
assertEquals(
|
|
|
|
typeof writableStream.get,
|
|
|
|
"function",
|
2020-07-14 15:24:17 -04:00
|
|
|
"writable should have a getter",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assertEquals(
|
|
|
|
writableStream.set,
|
|
|
|
undefined,
|
2020-07-14 15:24:17 -04:00
|
|
|
"writable should not have a setter",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(writableStream.configurable, "writable should be configurable");
|
|
|
|
assert(
|
|
|
|
ts.writable instanceof WritableStream,
|
2020-07-14 15:24:17 -04:00
|
|
|
"writable is an instance of WritableStream",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(
|
|
|
|
WritableStream.prototype.getWriter.call(ts.writable),
|
2020-07-14 15:24:17 -04:00
|
|
|
"writable should pass WritableStream brand check",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
const readableStream = Object.getOwnPropertyDescriptor(proto, "readable");
|
|
|
|
assert(readableStream !== undefined, "it has a readable property");
|
|
|
|
assert(!readableStream.enumerable, "readable should be non-enumerable");
|
|
|
|
assertEquals(
|
|
|
|
typeof readableStream.get,
|
|
|
|
"function",
|
2020-07-14 15:24:17 -04:00
|
|
|
"readable should have a getter",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assertEquals(
|
|
|
|
readableStream.set,
|
|
|
|
undefined,
|
2020-07-14 15:24:17 -04:00
|
|
|
"readable should not have a setter",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(readableStream.configurable, "readable should be configurable");
|
|
|
|
assert(
|
|
|
|
ts.readable instanceof ReadableStream,
|
2020-07-14 15:24:17 -04:00
|
|
|
"readable is an instance of ReadableStream",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assertNotEquals(
|
|
|
|
ReadableStream.prototype.getReader.call(ts.readable),
|
|
|
|
undefined,
|
2020-07-14 15:24:17 -04:00
|
|
|
"readable should pass ReadableStream brand check",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamWritableStartsAsWritable() {
|
|
|
|
const ts = new TransformStream({ transform(): void {} });
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
assertEquals(writer.desiredSize, 1, "writer.desiredSize should be 1");
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamReadableCanReadOutOfWritable() {
|
|
|
|
const ts = new TransformStream();
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
assertEquals(
|
|
|
|
writer.desiredSize,
|
|
|
|
0,
|
2020-07-14 15:24:17 -04:00
|
|
|
"writer.desiredSize should be 0 after write()",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
const result = await ts.readable.getReader().read();
|
|
|
|
assertEquals(
|
|
|
|
result.value,
|
|
|
|
"a",
|
2020-07-14 15:24:17 -04:00
|
|
|
"result from reading the readable is the same as was written to writable",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(!result.done, "stream should not be done");
|
|
|
|
|
|
|
|
await delay(0);
|
|
|
|
assert(writer.desiredSize === 1, "desiredSize should be 1 again");
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamCanReadWhatIsWritten() {
|
|
|
|
let c: TransformStreamDefaultController;
|
|
|
|
const ts = new TransformStream({
|
|
|
|
start(controller: TransformStreamDefaultController): void {
|
|
|
|
c = controller;
|
|
|
|
},
|
|
|
|
transform(chunk: string): void {
|
|
|
|
c.enqueue(chunk.toUpperCase());
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
|
|
|
|
const result = await ts.readable.getReader().read();
|
|
|
|
assertEquals(
|
|
|
|
result.value,
|
|
|
|
"A",
|
2020-07-14 15:24:17 -04:00
|
|
|
"result from reading the readable is the transformation of what was written to writable",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(!result.done, "stream should not be done");
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamCanReadBothChunks() {
|
|
|
|
let c: TransformStreamDefaultController;
|
|
|
|
const ts = new TransformStream({
|
|
|
|
start(controller: TransformStreamDefaultController): void {
|
|
|
|
c = controller;
|
|
|
|
},
|
|
|
|
transform(chunk: string): void {
|
|
|
|
c.enqueue(chunk.toUpperCase());
|
|
|
|
c.enqueue(chunk.toUpperCase());
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
|
|
|
|
const reader = ts.readable.getReader();
|
|
|
|
|
|
|
|
const result1 = await reader.read();
|
|
|
|
assertEquals(
|
|
|
|
result1.value,
|
|
|
|
"A",
|
2020-07-14 15:24:17 -04:00
|
|
|
"the first chunk read is the transformation of the single chunk written",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(!result1.done, "stream should not be done");
|
|
|
|
|
|
|
|
const result2 = await reader.read();
|
|
|
|
assertEquals(
|
|
|
|
result2.value,
|
|
|
|
"A",
|
2020-07-14 15:24:17 -04:00
|
|
|
"the second chunk read is also the transformation of the single chunk written",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(!result2.done, "stream should not be done");
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamCanReadWhatIsWritten() {
|
|
|
|
let c: TransformStreamDefaultController;
|
|
|
|
const ts = new TransformStream({
|
|
|
|
start(controller: TransformStreamDefaultController): void {
|
|
|
|
c = controller;
|
|
|
|
},
|
|
|
|
transform(chunk: string): Promise<void> {
|
|
|
|
return delay(0).then(() => c.enqueue(chunk.toUpperCase()));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
|
|
|
|
const result = await ts.readable.getReader().read();
|
|
|
|
assertEquals(
|
|
|
|
result.value,
|
|
|
|
"A",
|
2020-07-14 15:24:17 -04:00
|
|
|
"result from reading the readable is the transformation of what was written to writable",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(!result.done, "stream should not be done");
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamAsyncReadMultipleChunks() {
|
|
|
|
let doSecondEnqueue: () => void;
|
|
|
|
let returnFromTransform: () => void;
|
|
|
|
const ts = new TransformStream({
|
|
|
|
transform(
|
|
|
|
chunk: string,
|
2020-07-14 15:24:17 -04:00
|
|
|
controller: TransformStreamDefaultController,
|
2020-05-03 15:10:52 -04:00
|
|
|
): Promise<void> {
|
|
|
|
delay(0).then(() => controller.enqueue(chunk.toUpperCase()));
|
|
|
|
doSecondEnqueue = (): void => controller.enqueue(chunk.toUpperCase());
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
returnFromTransform = resolve;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const reader = ts.readable.getReader();
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
|
|
|
|
const result1 = await reader.read();
|
|
|
|
assertEquals(
|
|
|
|
result1.value,
|
|
|
|
"A",
|
2020-07-14 15:24:17 -04:00
|
|
|
"the first chunk read is the transformation of the single chunk written",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(!result1.done, "stream should not be done");
|
|
|
|
doSecondEnqueue!();
|
|
|
|
|
|
|
|
const result2 = await reader.read();
|
|
|
|
assertEquals(
|
|
|
|
result2.value,
|
|
|
|
"A",
|
2020-07-14 15:24:17 -04:00
|
|
|
"the second chunk read is also the transformation of the single chunk written",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(!result2.done, "stream should not be done");
|
|
|
|
returnFromTransform!();
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamClosingWriteClosesRead() {
|
|
|
|
const ts = new TransformStream({ transform(): void {} });
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
return Promise.all([writer.closed, ts.readable.getReader().closed]).then(
|
2020-07-14 15:24:17 -04:00
|
|
|
undefined,
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamCloseWaitAwaitsTransforms() {
|
|
|
|
let transformResolve: () => void;
|
|
|
|
const transformPromise = new Promise<void>((resolve) => {
|
|
|
|
transformResolve = resolve;
|
|
|
|
});
|
|
|
|
const ts = new TransformStream(
|
|
|
|
{
|
|
|
|
transform(): Promise<void> {
|
|
|
|
return transformPromise;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
undefined,
|
2020-07-14 15:24:17 -04:00
|
|
|
{ highWaterMark: 1 },
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
let rsClosed = false;
|
|
|
|
ts.readable.getReader().closed.then(() => {
|
|
|
|
rsClosed = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
await delay(0);
|
|
|
|
assertEquals(rsClosed, false, "readable is not closed after a tick");
|
|
|
|
transformResolve!();
|
|
|
|
|
|
|
|
await writer.closed;
|
|
|
|
// TODO: Is this expectation correct?
|
|
|
|
assertEquals(rsClosed, true, "readable is closed at that point");
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamCloseWriteAfterSyncEnqueues() {
|
|
|
|
let c: TransformStreamDefaultController<string>;
|
|
|
|
const ts = new TransformStream<string, string>({
|
|
|
|
start(controller: TransformStreamDefaultController): void {
|
|
|
|
c = controller;
|
|
|
|
},
|
|
|
|
transform(): Promise<void> {
|
|
|
|
c.enqueue("x");
|
|
|
|
c.enqueue("y");
|
|
|
|
return delay(0);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
const readableChunks = readableStreamToArray(ts.readable);
|
|
|
|
|
|
|
|
await writer.closed;
|
|
|
|
const chunks = await readableChunks;
|
|
|
|
assertEquals(
|
|
|
|
chunks,
|
|
|
|
["x", "y"],
|
2020-07-14 15:24:17 -04:00
|
|
|
"both enqueued chunks can be read from the readable",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamWritableCloseAsyncAfterAsyncEnqueues() {
|
|
|
|
let c: TransformStreamDefaultController<string>;
|
|
|
|
const ts = new TransformStream<string, string>({
|
|
|
|
start(controller: TransformStreamDefaultController<string>): void {
|
|
|
|
c = controller;
|
|
|
|
},
|
|
|
|
transform(): Promise<void> {
|
|
|
|
return delay(0)
|
|
|
|
.then(() => c.enqueue("x"))
|
|
|
|
.then(() => c.enqueue("y"))
|
|
|
|
.then(() => delay(0));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
const readableChunks = readableStreamToArray(ts.readable);
|
|
|
|
|
|
|
|
await writer.closed;
|
|
|
|
const chunks = await readableChunks;
|
|
|
|
assertEquals(
|
|
|
|
chunks,
|
|
|
|
["x", "y"],
|
2020-07-14 15:24:17 -04:00
|
|
|
"both enqueued chunks can be read from the readable",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamTransformerMethodsCalledAsMethods() {
|
|
|
|
let c: TransformStreamDefaultController<string>;
|
|
|
|
const transformer = {
|
|
|
|
suffix: "-suffix",
|
|
|
|
|
|
|
|
start(controller: TransformStreamDefaultController<string>): void {
|
|
|
|
c = controller;
|
|
|
|
c.enqueue("start" + this.suffix);
|
|
|
|
},
|
|
|
|
|
|
|
|
transform(chunk: string): void {
|
|
|
|
c.enqueue(chunk + this.suffix);
|
|
|
|
},
|
|
|
|
|
|
|
|
flush(): void {
|
|
|
|
c.enqueue("flushed" + this.suffix);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const ts = new TransformStream(transformer);
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
const readableChunks = readableStreamToArray(ts.readable);
|
|
|
|
|
|
|
|
await writer.closed;
|
|
|
|
const chunks = await readableChunks;
|
|
|
|
assertEquals(
|
|
|
|
chunks,
|
|
|
|
["start-suffix", "a-suffix", "flushed-suffix"],
|
2020-07-14 15:24:17 -04:00
|
|
|
"all enqueued chunks have suffixes",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamMethodsShouldNotBeAppliedOrCalled() {
|
|
|
|
function functionWithOverloads(): void {}
|
|
|
|
functionWithOverloads.apply = (): void => {
|
|
|
|
throw new Error("apply() should not be called");
|
|
|
|
};
|
|
|
|
functionWithOverloads.call = (): void => {
|
|
|
|
throw new Error("call() should not be called");
|
|
|
|
};
|
|
|
|
const ts = new TransformStream({
|
|
|
|
start: functionWithOverloads,
|
|
|
|
transform: functionWithOverloads,
|
|
|
|
flush: functionWithOverloads,
|
|
|
|
});
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.write("a");
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
await readableStreamToArray(ts.readable);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamCallTransformSync() {
|
|
|
|
let transformCalled = false;
|
|
|
|
const ts = new TransformStream(
|
|
|
|
{
|
|
|
|
transform(): void {
|
|
|
|
transformCalled = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
undefined,
|
2020-07-14 15:24:17 -04:00
|
|
|
{ highWaterMark: Infinity },
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
// transform() is only called synchronously when there is no backpressure and
|
|
|
|
// all microtasks have run.
|
|
|
|
await delay(0);
|
|
|
|
const writePromise = ts.writable.getWriter().write(undefined);
|
|
|
|
assert(transformCalled, "transform() should have been called");
|
|
|
|
await writePromise;
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamCloseWriteCloesesReadWithNoChunks() {
|
|
|
|
const ts = new TransformStream({}, undefined, { highWaterMark: 0 });
|
|
|
|
|
|
|
|
const writer = ts.writable.getWriter();
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
return Promise.all([writer.closed, ts.readable.getReader().closed]).then(
|
2020-07-14 15:24:17 -04:00
|
|
|
undefined,
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamEnqueueThrowsAfterTerminate() {
|
|
|
|
new TransformStream({
|
|
|
|
start(controller: TransformStreamDefaultController): void {
|
|
|
|
controller.terminate();
|
|
|
|
assertThrows(() => {
|
|
|
|
controller.enqueue(undefined);
|
|
|
|
}, TypeError);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamEnqueueThrowsAfterReadableCancel() {
|
|
|
|
let controller: TransformStreamDefaultController;
|
|
|
|
const ts = new TransformStream({
|
|
|
|
start(c: TransformStreamDefaultController): void {
|
|
|
|
controller = c;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const cancelPromise = ts.readable.cancel();
|
|
|
|
assertThrows(
|
|
|
|
() => controller.enqueue(undefined),
|
|
|
|
TypeError,
|
|
|
|
undefined,
|
2020-07-14 15:24:17 -04:00
|
|
|
"enqueue should throw",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
return cancelPromise;
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamSecondTerminateNoOp() {
|
|
|
|
new TransformStream({
|
|
|
|
start(controller: TransformStreamDefaultController): void {
|
|
|
|
controller.terminate();
|
|
|
|
controller.terminate();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamTerminateAfterReadableCancelIsNoop() {
|
|
|
|
let controller: TransformStreamDefaultController;
|
|
|
|
const ts = new TransformStream({
|
|
|
|
start(c: TransformStreamDefaultController): void {
|
|
|
|
controller = c;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const cancelReason = { name: "cancelReason" };
|
|
|
|
const cancelPromise = ts.readable.cancel(cancelReason);
|
|
|
|
controller!.terminate();
|
|
|
|
await cancelPromise;
|
|
|
|
try {
|
|
|
|
await ts.writable.getWriter().closed;
|
|
|
|
} catch (e) {
|
|
|
|
assert(e === cancelReason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw new Error("closed should have rejected");
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(async function transformStreamStartCalledOnce() {
|
|
|
|
let calls = 0;
|
|
|
|
new TransformStream({
|
|
|
|
start(): void {
|
|
|
|
++calls;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await delay(0);
|
|
|
|
assertEquals(calls, 1, "start() should have been called exactly once");
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamReadableTypeThrows() {
|
|
|
|
assertThrows(
|
2020-06-19 05:05:37 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-05-03 15:10:52 -04:00
|
|
|
() => new TransformStream({ readableType: "bytes" as any }),
|
|
|
|
RangeError,
|
|
|
|
undefined,
|
2020-07-14 15:24:17 -04:00
|
|
|
"constructor should throw",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamWirtableTypeThrows() {
|
|
|
|
assertThrows(
|
2020-06-19 05:05:37 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-05-03 15:10:52 -04:00
|
|
|
() => new TransformStream({ writableType: "bytes" as any }),
|
|
|
|
RangeError,
|
|
|
|
undefined,
|
2020-07-14 15:24:17 -04:00
|
|
|
"constructor should throw",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
unitTest(function transformStreamSubclassable() {
|
|
|
|
class Subclass extends TransformStream {
|
|
|
|
extraFunction(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(
|
|
|
|
Object.getPrototypeOf(Subclass.prototype) === TransformStream.prototype,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Subclass.prototype's prototype should be TransformStream.prototype",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(
|
|
|
|
Object.getPrototypeOf(Subclass) === TransformStream,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Subclass's prototype should be TransformStream",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
const sub = new Subclass();
|
|
|
|
assert(
|
|
|
|
sub instanceof TransformStream,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Subclass object should be an instance of TransformStream",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(
|
|
|
|
sub instanceof Subclass,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Subclass object should be an instance of Subclass",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
const readableGetter = Object.getOwnPropertyDescriptor(
|
|
|
|
TransformStream.prototype,
|
2020-07-14 15:24:17 -04:00
|
|
|
"readable",
|
2020-05-03 15:10:52 -04:00
|
|
|
)!.get;
|
|
|
|
assert(
|
|
|
|
readableGetter!.call(sub) === sub.readable,
|
2020-07-14 15:24:17 -04:00
|
|
|
"Subclass object should pass brand check",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
assert(
|
|
|
|
sub.extraFunction(),
|
2020-07-14 15:24:17 -04:00
|
|
|
"extraFunction() should be present on Subclass object",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
});
|