Skip to content

Commit b41cf22

Browse files
Niels Nielsenaddaleax
authored andcommitted
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.
1 parent 431638d commit b41cf22

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// Should be able to unpipe them in the reverse order that they were piped.
18+
19+
source.unpipe(dest2);
20+
21+
assert.strictEqual(source._readableState.pipes, dest1);
22+
assert.notStrictEqual(source._readableState.pipes, dest2);
23+
24+
source.unpipe(dest1);
25+
26+
assert.strictEqual(source._readableState.pipes, null);

0 commit comments

Comments
 (0)