From 7d2494d867f38d5d56f955cb7126e49f3348b96c 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 2d7eefc494623b..fe87f246327a3a 100644 --- a/test/parallel/test-stream-finished.js +++ b/test/parallel/test-stream-finished.js @@ -153,3 +153,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(); +}