@@ -14,8 +14,9 @@ function spawnChild(script) {
1414 } ) ;
1515}
1616
17- function runTest ( { script, setup } , done ) {
17+ function runTest ( { script, onSpawn } , done ) {
1818 const child = spawnChild ( script ) ;
19+
1920 const timeout = setTimeout ( ( ) => {
2021 assert . fail ( 'stdin close event was not emitted' ) ;
2122 } , 2000 ) ;
@@ -39,34 +40,32 @@ function runTest({ script, setup }, done) {
3940 maybeDone ( ) ;
4041 } ) ) ;
4142
42- setup ( child ) ;
43+ onSpawn ?. ( child ) ;
4344}
4445
4546runTest ( {
4647 script : 'setTimeout(() => require("fs").closeSync(0), 50); setTimeout(() => {}, 2000)' ,
47- setup : ( ) => { } ,
4848} , common . mustCall ( ( ) => {
4949 runTest ( {
5050 script : 'setTimeout(() => require("fs").closeSync(0), 200); setTimeout(() => {}, 2000)' ,
51- setup : ( child ) => {
51+ onSpawn : common . mustCall ( ( child ) => {
5252 const handle = child . stdin ?. _handle ;
5353 assert . strictEqual ( typeof handle ?. watchPeerClose , 'function' ) ;
5454 handle . watchPeerClose ( true , common . mustNotCall ( ) ) ;
55- } ,
55+ } ) ,
5656 } , common . mustCall ( ( ) => {
5757 runTest ( {
5858 script : 'setTimeout(() => {}, 2000)' ,
59- setup : ( child ) => {
59+ onSpawn : common . mustCall ( ( child ) => {
6060 const handle = child . stdin ?. _handle ;
6161 assert . strictEqual ( typeof handle ?. watchPeerClose , 'function' ) ;
6262
6363 child . stdin . once ( 'close' , common . mustCall ( ( ) => {
64- assert . doesNotThrow ( ( ) => {
65- handle . watchPeerClose ( true , common . mustNotCall ( ) ) ;
66- } ) ;
64+ // Calling watchPeerClose again after close must not throw.
65+ handle . watchPeerClose ( true , common . mustNotCall ( ) ) ;
6766 } ) ) ;
6867 child . stdin . destroy ( ) ;
69- } ,
70- } , common . mustCall ( ( ) => { } ) ) ;
68+ } ) ,
69+ } , common . mustCall ( ) ) ;
7170 } ) ) ;
7271} ) ) ;
0 commit comments