11'use strict' ;
2- require ( '../common' ) ;
2+ const common = require ( '../common' ) ;
33const assert = require ( 'assert' ) ;
4-
54const Readable = require ( '_stream_readable' ) ;
65const Writable = require ( '_stream_writable' ) ;
76const EE = require ( 'events' ) . EventEmitter ;
87
9- let testRuns = 0 , completedRuns = 0 ;
108function runTest ( highWaterMark , objectMode , produce ) {
11- testRuns ++ ;
129
1310 const old = new EE ( ) ;
1411 const r = new Readable ( { highWaterMark : highWaterMark ,
1512 objectMode : objectMode } ) ;
1613 assert . strictEqual ( r , r . wrap ( old ) ) ;
1714
18- let ended = false ;
19- r . on ( 'end' , function ( ) {
20- ended = true ;
21- } ) ;
15+ r . on ( 'end' , common . mustCall ( function ( ) { } ) ) ;
2216
2317 old . pause = function ( ) {
24- console . error ( 'old.pause()' ) ;
2518 old . emit ( 'pause' ) ;
2619 flowing = false ;
2720 } ;
2821
2922 old . resume = function ( ) {
30- console . error ( 'old.resume()' ) ;
3123 old . emit ( 'resume' ) ;
3224 flow ( ) ;
3325 } ;
@@ -41,13 +33,10 @@ function runTest(highWaterMark, objectMode, produce) {
4133 while ( flowing && chunks -- > 0 ) {
4234 const item = produce ( ) ;
4335 expected . push ( item ) ;
44- console . log ( 'old.emit' , chunks , flowing ) ;
4536 old . emit ( 'data' , item ) ;
46- console . log ( 'after emit' , chunks , flowing ) ;
4737 }
4838 if ( chunks <= 0 ) {
4939 oldEnded = true ;
50- console . log ( 'old end' , chunks , flowing ) ;
5140 old . emit ( 'end' ) ;
5241 }
5342 }
@@ -56,22 +45,19 @@ function runTest(highWaterMark, objectMode, produce) {
5645 objectMode : objectMode } ) ;
5746 const written = [ ] ;
5847 w . _write = function ( chunk , encoding , cb ) {
59- console . log ( '_write' , chunk ) ;
6048 written . push ( chunk ) ;
6149 setTimeout ( cb , 1 ) ;
6250 } ;
6351
64- w . on ( 'finish' , function ( ) {
65- completedRuns ++ ;
52+ w . on ( 'finish' , common . mustCall ( function ( ) {
6653 performAsserts ( ) ;
67- } ) ;
54+ } ) ) ;
6855
6956 r . pipe ( w ) ;
7057
7158 flow ( ) ;
7259
7360 function performAsserts ( ) {
74- assert ( ended ) ;
7561 assert ( oldEnded ) ;
7662 assert . deepStrictEqual ( written , expected ) ;
7763 }
@@ -83,8 +69,3 @@ runTest(1, true, function() { return { foo: 'bar' }; });
8369
8470const objectChunks = [ 5 , 'a' , false , 0 , '' , 'xyz' , { x : 4 } , 7 , [ ] , 555 ] ;
8571runTest ( 1 , true , function ( ) { return objectChunks . shift ( ) ; } ) ;
86-
87- process . on ( 'exit' , function ( ) {
88- assert . strictEqual ( testRuns , completedRuns ) ;
89- console . log ( 'ok' ) ;
90- } ) ;
0 commit comments