Skip to content

Commit

Permalink
test: improve lib/internal/webstreams/readablestream.js coverage
Browse files Browse the repository at this point in the history
PR-URL: #42823
Refs: https://coverage.nodejs.org/coverage-3a6b975981092213/lib/internal/webstreams/readablestream.js.html#L421
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
  • Loading branch information
fossamagna authored and targos committed Jul 31, 2022
1 parent 1a98f16 commit 24c4f76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/parallel/test-whatwg-readablebytestream.js
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
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',
}).then(common.mustCall());
}

{
const stream = new ReadableStream();
const iterable = stream.values();
readableStreamReaderGenericRelease(stream[kState].reader);
assert.rejects(iterable.return(), {
code: 'ERR_INVALID_STATE',
}).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

0 comments on commit 24c4f76

Please sign in to comment.