@@ -8,28 +8,25 @@ const args = ['--interactive'];
88const opts = { cwd : fixtures . path ( 'es-modules' ) } ;
99const child = cp . spawn ( process . execPath , args , opts ) ;
1010
11- const outputs = [ ] ;
11+ let output = '' ;
1212child . stdout . setEncoding ( 'utf8' ) ;
1313child . stdout . on ( 'data' , ( data ) => {
14- outputs . push ( data ) ;
15- if ( outputs . length === 3 ) {
14+ output += data ;
15+
16+ if (
17+ ! child . stdin . writableEnded &&
18+ output . includes ( '[Module: null prototype] { message: \'A message\' }' )
19+ ) {
1620 // All the expected outputs have been received
1721 // so we can close the child process's stdin
1822 child . stdin . end ( ) ;
1923 }
2024} ) ;
2125
22- child . on ( 'exit' , common . mustCall ( ( ) => {
23- const results = outputs [ 2 ] . split ( '\n' ) [ 0 ] ;
24- assert . strictEqual (
25- results ,
26- '[Module: null prototype] { message: \'A message\' }'
27- ) ;
26+ child . on ( 'exit' , common . mustCall ( ( code , signal ) => {
27+ assert . strictEqual ( code , 0 ) ;
28+ assert . strictEqual ( signal , null ) ;
2829} ) ) ;
2930
30- // Note: write the commands on stdin with a slight delay to make sure
31- // that the child process is ready to receive and process them
32- setTimeout ( ( ) => {
33- child . stdin . write ( 'await import(\'./message.mjs\');\n' ) ;
34- child . stdin . write ( '.exit' ) ;
35- } , common . platformTimeout ( 250 ) ) ;
31+ child . stdin . write ( 'await import(\'./message.mjs\');\n' ) ;
32+ child . stdin . write ( '.exit' ) ;
0 commit comments