diff options
author | Matteo Collina <hello@matteocollina.com> | 2019-08-19 17:45:30 +0200 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2019-12-03 12:14:48 +0100 |
commit | e490d9b1539a7ec5f6b9d9b2f18753ce1c3459f7 (patch) | |
tree | 2d0f7e2431de3a96df24200d8c733896fdfb7176 /test | |
parent | ae8f20ec5eee55f648823392c9c4e9491c958b60 (diff) | |
download | android-node-v8-e490d9b1539a7ec5f6b9d9b2f18753ce1c3459f7.tar.gz android-node-v8-e490d9b1539a7ec5f6b9d9b2f18753ce1c3459f7.tar.bz2 android-node-v8-e490d9b1539a7ec5f6b9d9b2f18753ce1c3459f7.zip |
stream: add support for captureRejection option
PR-URL: https://github.com/nodejs/node/pull/27867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-stream-catch-rejections.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/parallel/test-stream-catch-rejections.js b/test/parallel/test-stream-catch-rejections.js new file mode 100644 index 0000000000..fb5f1fccc1 --- /dev/null +++ b/test/parallel/test-stream-catch-rejections.js @@ -0,0 +1,52 @@ +'use strict'; + +const common = require('../common'); +const stream = require('stream'); +const assert = require('assert'); + +{ + const r = new stream.Readable({ + captureRejections: true, + read() { + this.push('hello'); + this.push('world'); + this.push(null); + } + }); + + const err = new Error('kaboom'); + + r.on('error', common.mustCall((_err) => { + assert.strictEqual(err, _err); + assert.strictEqual(r.destroyed, true); + })); + + r.on('data', async () => { + throw err; + }); +} + +{ + const w = new stream.Writable({ + captureRejections: true, + highWaterMark: 1, + write(chunk, enc, cb) { + cb(); + } + }); + + const err = new Error('kaboom'); + + w.write('hello', () => { + w.write('world'); + }); + + w.on('error', common.mustCall((_err) => { + assert.strictEqual(err, _err); + assert.strictEqual(w.destroyed, true); + })); + + w.on('drain', common.mustCall(async () => { + throw err; + }, 2)); +} |