From 4a2bd69db99c1bb8692e1f653edcb225fbc23032 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 16 Jul 2019 00:03:23 +0200 Subject: stream: fix destroy() behavior Ensure errorEmitted is always set. Only emit 'error' once. PR-URL: https://github.com/nodejs/node/pull/29058 Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca Reviewed-By: Franziska Hinkelmann Reviewed-By: Rich Trott --- .../parallel/test-stream-readable-invalid-chunk.js | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'test/parallel/test-stream-readable-invalid-chunk.js') diff --git a/test/parallel/test-stream-readable-invalid-chunk.js b/test/parallel/test-stream-readable-invalid-chunk.js index fcd7414bb6..3e147c065f 100644 --- a/test/parallel/test-stream-readable-invalid-chunk.js +++ b/test/parallel/test-stream-readable-invalid-chunk.js @@ -3,17 +3,32 @@ const common = require('../common'); const stream = require('stream'); -const readable = new stream.Readable({ - read: () => {} -}); - -function checkError(fn) { - common.expectsError(fn, { +function testPushArg(val) { + const readable = new stream.Readable({ + read: () => {} + }); + readable.on('error', common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError + })); + readable.push(val); +} + +testPushArg([]); +testPushArg({}); +testPushArg(0); + +function testUnshiftArg(val) { + const readable = new stream.Readable({ + read: () => {} }); + readable.on('error', common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError + })); + readable.unshift(val); } -checkError(() => readable.push([])); -checkError(() => readable.push({})); -checkError(() => readable.push(0)); +testUnshiftArg([]); +testUnshiftArg({}); +testUnshiftArg(0); -- cgit v1.2.3