Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve lib/internal/webstreams/readablestream.js coverage #42823

Merged
Show file tree
Hide file tree
Changes from 2 commits
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
16 changes: 16 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 @@ -233,6 +236,19 @@ class Source {
});
}

{
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',
});
}

{
const stream = new ReadableStream({
type: 'bytes',
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
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
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