Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: improve lib/internal/webstreams/readablestream.js coverage
  • Loading branch information
fossamagna committed Apr 22, 2022
commit a933ea98861816373d9fa235e2659ec6b714391c
21 changes: 21 additions & 0 deletions test/parallel/test-whatwg-readablebytestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const {
defaultReader.releaseLock();
const byobReader = r.getReader({ mode: 'byob' });
assert(byobReader instanceof ReadableStreamBYOBReader);
assert.match(
inspect(byobReader, { depth: 0 }),
/ReadableStreamBYOBReader/);
}

class Source {
Expand Down Expand Up @@ -209,9 +212,11 @@ class Source {
reader.releaseLock();
assert.rejects(reader.read(new Uint8Array(10)), {
code: 'ERR_INVALID_STATE',
message: 'Invalid state: The reader is not attached to a stream',

@aduh95 aduh95 Apr 22, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not test error messages, see #42813

Suggested change
message: 'Invalid state: The reader is not attached to a stream',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduh95 Thanks, I change that checking only the code property.

});
assert.rejects(reader.cancel(), {
code: 'ERR_INVALID_STATE',
message: 'Invalid state: The reader is not attached to a stream',
});
}

Expand All @@ -227,9 +232,25 @@ class Source {
controller.close();
assert.throws(() => controller.enqueue(new Uint8Array(10)), {
code: 'ERR_INVALID_STATE',
message: 'Invalid state: ReadableStream is already closed',
});
assert.throws(() => controller.close(), {
code: 'ERR_INVALID_STATE',
message: 'Invalid state: ReadableStream is already closed',
});
}

{
let controller;
new ReadableStream({
type: 'bytes',
start(c) { controller = c; }
});
controller.enqueue(new Uint8Array(10));
controller.close();
assert.throws(() => controller.enqueue(new Uint8Array(10)), {
code: 'ERR_INVALID_STATE',
message: 'Invalid state: Controller is already closed',
});
}

Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-whatwg-readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const {
readableStreamDefaultControllerCanCloseOrEnqueue,
readableByteStreamControllerClose,
readableByteStreamControllerRespond,
readableStreamReaderGenericRelease,
} = require('internal/webstreams/readablestream');

const {
Expand Down Expand Up @@ -371,6 +372,24 @@ assert.throws(() => {
});
}

{
const stream = new ReadableStream();
const iterable = stream.values();
readableStreamReaderGenericRelease(stream[kState].reader);
assert.rejects(iterable.next(), {
code: 'ERR_INVALID_STATE',
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
}).then(common.mustCall());

}

{
const stream = new ReadableStream();
const iterable = stream.values();
readableStreamReaderGenericRelease(stream[kState].reader);
assert.rejects(iterable.return(), {
code: 'ERR_INVALID_STATE',
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
}).then(common.mustCall());

}

{
const stream = new ReadableStream({
start(controller) {
Expand Down Expand Up @@ -1357,6 +1376,9 @@ class Source {
assert.throws(() => ReadableStream.prototype.tee.call({}), {
code: 'ERR_INVALID_THIS',
});
assert.throws(() => ReadableStream.prototype.values.call({}), {
code: 'ERR_INVALID_THIS',
});
assert.throws(() => ReadableStream.prototype[kTransfer].call({}), {
code: 'ERR_INVALID_THIS',
});
Expand Down