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 <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Tyler Vann-Campbell 2018-10-19 00:39:20 -07:00 committed by Anna Henningsen
parent cc750b71a1
commit 7d2494d867
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -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();
}