Skip to content

Commit 6bef1db

Browse files
Niels NielsenMyles Borins
Niels Nielsen
authored and
Myles Borins
committed
test: add regression test for unpipe()
Since 2e568d9 there is a bug where unpiping a stream from a readable stream that has `_readableState.pipesCount > 1` will cause it to remove the first stream in the `_.readableState.pipes` array no matter where in the list the `dest` stream was. PR-URL: #9171 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Myles Borins <[email protected]>
1 parent 8244efb commit 6bef1db

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
const { Readable, Writable } = require('stream');
6+
7+
const source = Readable({read: () => {}});
8+
const dest1 = Writable({write: () => {}});
9+
const dest2 = Writable({write: () => {}});
10+
11+
source.pipe(dest1);
12+
source.pipe(dest2);
13+
14+
dest1.on('unpipe', common.mustCall(() => {}));
15+
dest2.on('unpipe', common.mustCall(() => {}));
16+
17+
assert.strictEqual(source._readableState.pipes[0], dest1);
18+
assert.strictEqual(source._readableState.pipes[1], dest2);
19+
assert.strictEqual(source._readableState.pipes.length, 2);
20+
21+
// Should be able to unpipe them in the reverse order that they were piped.
22+
23+
source.unpipe(dest2);
24+
25+
assert.strictEqual(source._readableState.pipes, dest1);
26+
assert.notStrictEqual(source._readableState.pipes, dest2);
27+
28+
source.unpipe(dest1);
29+
30+
assert.strictEqual(source._readableState.pipes, null);

0 commit comments

Comments
 (0)