Skip to content

Commit

Permalink
test: improve lib/internal/webstreams/readablestream.js coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fossamagna authored and juanarbol committed May 31, 2022
1 parent d9156c9 commit 8bb7f56
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
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',
}).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 8bb7f56

Please sign in to comment.