diff options
author | Robert Nagy <ronagy@icloud.com> | 2021-12-09 09:15:12 +0100 |
---|---|---|
committer | Robert Nagy <ronagy@icloud.com> | 2021-12-16 14:28:31 +0100 |
commit | 752d75d8bccd23a21110a13a32baa880800be022 (patch) | |
tree | 3a96d27ccf406931e17a68aebdaf78145f4785b9 /test | |
parent | a3195f20cd8eb31a5e56ea6ee7ad431566e27cbf (diff) | |
download | node-new-752d75d8bccd23a21110a13a32baa880800be022.tar.gz |
stream: add isErrored helper
Refs: https://github.com/nodejs/undici/pull/1134
PR-URL: https://github.com/nodejs/node/pull/41121
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-stream-readable-didRead.js | 7 | ||||
-rw-r--r-- | test/parallel/test-whatwg-readablestream.js | 18 |
2 files changed, 22 insertions, 3 deletions
diff --git a/test/parallel/test-stream-readable-didRead.js b/test/parallel/test-stream-readable-didRead.js index c67289e654..878340ba19 100644 --- a/test/parallel/test-stream-readable-didRead.js +++ b/test/parallel/test-stream-readable-didRead.js @@ -1,15 +1,18 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); -const { isDisturbed, Readable } = require('stream'); +const { isDisturbed, isErrored, Readable } = require('stream'); function noop() {} function check(readable, data, fn) { assert.strictEqual(readable.readableDidRead, false); assert.strictEqual(isDisturbed(readable), false); + assert.strictEqual(isErrored(readable), false); if (data === -1) { - readable.on('error', common.mustCall()); + readable.on('error', common.mustCall(() => { + assert.strictEqual(isErrored(readable), true); + })); readable.on('data', common.mustNotCall()); readable.on('end', common.mustNotCall()); } else { diff --git a/test/parallel/test-whatwg-readablestream.js b/test/parallel/test-whatwg-readablestream.js index ce1d892262..b5cb94d043 100644 --- a/test/parallel/test-whatwg-readablestream.js +++ b/test/parallel/test-whatwg-readablestream.js @@ -2,7 +2,7 @@ 'use strict'; const common = require('../common'); -const { isDisturbed } = require('stream'); +const { isDisturbed, isErrored } = require('stream'); const assert = require('assert'); const { isPromise, @@ -1572,3 +1572,19 @@ class Source { isDisturbed(stream, true); })().then(common.mustCall()); } + + +{ + const stream = new ReadableStream({ + pull: common.mustCall((controller) => { + controller.error(new Error()); + }), + }); + + const reader = stream.getReader(); + (async () => { + isErrored(stream, false); + await reader.read().catch(common.mustCall()); + isErrored(stream, true); + })().then(common.mustCall()); +} |