From 1d201be04bd15a23c113ca8e82e418276fb73371 Mon Sep 17 00:00:00 2001 From: Tyler Vann-Campbell Date: Fri, 19 Oct 2018 00:39:20 -0700 Subject: [PATCH] test: increase coverage of internal/stream/end-of-stream This change adds test cases to call the function returned by end-of-stream and asserts that callbacks are not called when the stream is ended, or prematurely closed. PR-URL: https://github.com/nodejs/node/pull/23751 Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell --- test/parallel/test-stream-finished.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/parallel/test-stream-finished.js b/test/parallel/test-stream-finished.js index 3aade5610c7045..86564e824cd857 100644 --- a/test/parallel/test-stream-finished.js +++ b/test/parallel/test-stream-finished.js @@ -119,3 +119,25 @@ const { promisify } = require('util'); rs.push(null); rs.resume(); } + +// Test that calling returned function removes listeners +{ + const ws = new Writable({ + write(data, env, cb) { + cb(); + } + }); + const removeListener = finished(ws, common.mustNotCall()); + removeListener(); + ws.end(); +} + +{ + const rs = new Readable(); + const removeListeners = finished(rs, common.mustNotCall()); + removeListeners(); + + rs.emit('close'); + rs.push(null); + rs.resume(); +}