1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { Writable, Readable } = require('stream'); 5class NullWriteable extends Writable { 6 _write(chunk, encoding, callback) { 7 return callback(); 8 } 9} 10class QuickEndReadable extends Readable { 11 _read() { 12 this.push(null); 13 } 14} 15class NeverEndReadable extends Readable { 16 _read() {} 17} 18 19{ 20 const dest = new NullWriteable(); 21 const src = new QuickEndReadable(); 22 dest.on('pipe', common.mustCall()); 23 dest.on('unpipe', common.mustCall()); 24 src.pipe(dest); 25 setImmediate(() => { 26 assert.strictEqual(src._readableState.pipes.length, 0); 27 }); 28} 29 30{ 31 const dest = new NullWriteable(); 32 const src = new NeverEndReadable(); 33 dest.on('pipe', common.mustCall()); 34 dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); 35 src.pipe(dest); 36 setImmediate(() => { 37 assert.strictEqual(src._readableState.pipes.length, 1); 38 }); 39} 40 41{ 42 const dest = new NullWriteable(); 43 const src = new NeverEndReadable(); 44 dest.on('pipe', common.mustCall()); 45 dest.on('unpipe', common.mustCall()); 46 src.pipe(dest); 47 src.unpipe(dest); 48 setImmediate(() => { 49 assert.strictEqual(src._readableState.pipes.length, 0); 50 }); 51} 52 53{ 54 const dest = new NullWriteable(); 55 const src = new QuickEndReadable(); 56 dest.on('pipe', common.mustCall()); 57 dest.on('unpipe', common.mustCall()); 58 src.pipe(dest, { end: false }); 59 setImmediate(() => { 60 assert.strictEqual(src._readableState.pipes.length, 0); 61 }); 62} 63 64{ 65 const dest = new NullWriteable(); 66 const src = new NeverEndReadable(); 67 dest.on('pipe', common.mustCall()); 68 dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); 69 src.pipe(dest, { end: false }); 70 setImmediate(() => { 71 assert.strictEqual(src._readableState.pipes.length, 1); 72 }); 73} 74 75{ 76 const dest = new NullWriteable(); 77 const src = new NeverEndReadable(); 78 dest.on('pipe', common.mustCall()); 79 dest.on('unpipe', common.mustCall()); 80 src.pipe(dest, { end: false }); 81 src.unpipe(dest); 82 setImmediate(() => { 83 assert.strictEqual(src._readableState.pipes.length, 0); 84 }); 85} 86