From d0aeccf07413279779be2e058e01926258422468 Mon Sep 17 00:00:00 2001 From: Jithil P Ponnan Date: Thu, 18 May 2023 23:37:57 +1000 Subject: [PATCH] test: test streambase already has a consumer --- ...t-whatwg-webstreams-adapters-streambase.js | 10 ++++++++++ ...treams-adapters-to-readablewritablepair.js | 7 +++++++ ...twg-webstreams-adapters-to-streamduplex.js | 20 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/test/parallel/test-whatwg-webstreams-adapters-streambase.js b/test/parallel/test-whatwg-webstreams-adapters-streambase.js index 43d28f0499dc7d..b5f99ceab2b103 100644 --- a/test/parallel/test-whatwg-webstreams-adapters-streambase.js +++ b/test/parallel/test-whatwg-webstreams-adapters-streambase.js @@ -65,3 +65,13 @@ const { const readable = newReadableStreamFromStreamBase(stream); readable.cancel().then(common.mustCall()); } + +{ + const stream = new JSStream(); + stream.onread = () => {}; + assert.throws(() => newReadableStreamFromStreamBase(stream), { + code: 'ERR_INVALID_STATE', + message: /StreamBase already has a consumer/ + }); + stream.emitEOF(); +} diff --git a/test/parallel/test-whatwg-webstreams-adapters-to-readablewritablepair.js b/test/parallel/test-whatwg-webstreams-adapters-to-readablewritablepair.js index a4ce9d163214cd..b3aa534f6933af 100644 --- a/test/parallel/test-whatwg-webstreams-adapters-to-readablewritablepair.js +++ b/test/parallel/test-whatwg-webstreams-adapters-to-readablewritablepair.js @@ -248,3 +248,10 @@ const { reader.closed.then(common.mustCall()); writer.close().then(common.mustCall()); } + +{ + assert.throws(() => newReadableWritablePairFromDuplex(null), { + code: 'ERR_INVALID_ARG_TYPE', + message: /The "duplex" argument must be an stream\.Duplex/ + }); +} diff --git a/test/parallel/test-whatwg-webstreams-adapters-to-streamduplex.js b/test/parallel/test-whatwg-webstreams-adapters-to-streamduplex.js index 15ac9f832714e9..285ebdb243d4c6 100644 --- a/test/parallel/test-whatwg-webstreams-adapters-to-streamduplex.js +++ b/test/parallel/test-whatwg-webstreams-adapters-to-streamduplex.js @@ -164,3 +164,23 @@ const { duplex.end(); } + +{ + const transform = { readable: {}, writable: {} }; + assert.throws(() => newStreamDuplexFromReadableWritablePair(transform), { + code: 'ERR_INVALID_ARG_TYPE', + message: /The "pair\.readable" property must be an instance of ReadableStream/ + }); +} + +{ + const transform = { + readable: new ReadableStream(), + writable: null + }; + + assert.throws(() => newStreamDuplexFromReadableWritablePair(transform), { + code: 'ERR_INVALID_ARG_TYPE', + message: /The "pair\.writable" property must be an instance of WritableStream/ + }); +}