@@ -6,7 +6,7 @@ import {getQueriesForElement} from './get-queries-for-instance'
66import  userEvent  from  './user-event' 
77import  { bindObjectFnsToInstance ,  setCurrentInstance }  from  './helpers' 
88import  { fireEvent }  from  './events' 
9- import  { getConfig }  from  " ./config" ; 
9+ import  { getConfig }  from  ' ./config' 
1010
1111const  mountedInstances  =  new  Set < TestInstance > ( ) 
1212
@@ -25,18 +25,20 @@ async function render(
2525  } ) 
2626
2727  let  _readyPromiseInternals : null  |  { resolve : Function ;  reject : Function }  = 
28-       null 
28+     null 
29+ 
30+   let  _resolved  =  false 
2931
3032  const  execOutputAPI  =  { 
3133    __exitCode : null  as  null  |  number , 
3234    _isOutputAPI : true , 
3335    _isReady : new  Promise ( 
34-          ( resolve ,  reject )  =>  ( _readyPromiseInternals  =  { resolve,  reject} ) , 
36+       ( resolve ,  reject )  =>  ( _readyPromiseInternals  =  { resolve,  reject} ) , 
3537    ) , 
3638    process : exec , 
3739    // Clear buffer of stdout to do more accurate `t.regex` checks 
3840    clear ( )  { 
39-          execOutputAPI . stdoutArr  =  [ ] 
41+       execOutputAPI . stdoutArr  =  [ ] 
4042    } , 
4143    // An array of strings gathered from stdout when unable to do 
4244    // `await stdout` because of inquirer interactive prompts 
@@ -50,30 +52,42 @@ async function render(
5052  mountedInstances . add ( execOutputAPI  as  unknown  as  TestInstance ) 
5153
5254  exec . stdout . on ( 'data' ,  ( result : string  |  Buffer )  =>  { 
55+     // `on('spawn') doesn't work the same way in Node12. 
56+     // Instead, we have to rely on this working as-expected. 
57+     if  ( _readyPromiseInternals  &&  ! _resolved )  { 
58+       _readyPromiseInternals . resolve ( ) 
59+       _resolved  =  true 
60+     } 
61+ 
5362    const  resStr  =  stripFinalNewline ( result  as  string ) 
5463    execOutputAPI . stdoutArr . push ( resStr ) 
5564    _runObservers ( ) 
5665  } ) 
5766
5867  exec . stderr . on ( 'data' ,  ( result : string  |  Buffer )  =>  { 
68+     if  ( _readyPromiseInternals  &&  ! _resolved )  { 
69+       _readyPromiseInternals . resolve ( ) 
70+       _resolved  =  true 
71+     } 
72+ 
5973    const  resStr  =  stripFinalNewline ( result  as  string ) 
6074    execOutputAPI . stderrArr . push ( resStr ) 
6175    _runObservers ( ) 
6276  } ) 
6377
6478  exec . on ( 'error' ,  result  =>  { 
6579    if  ( _readyPromiseInternals )  { 
66-       _readyPromiseInternals . reject ( result ) ; 
80+       _readyPromiseInternals . reject ( result ) 
6781    } 
6882  } ) 
6983
7084  exec . on ( 'spawn' ,  ( )  =>  { 
71-        setTimeout ( ( )  =>  { 
72-            if  ( _readyPromiseInternals )  { 
73- 
74-                _readyPromiseInternals . resolve ( ) ; 
75-            } 
76-   } ,  getConfig ( ) . renderAwaitTime ) 
85+     setTimeout ( ( )  =>  { 
86+       if  ( _readyPromiseInternals   &&   ! _resolved )  { 
87+          _readyPromiseInternals . resolve ( ) 
88+         _resolved   =   true 
89+       } 
90+      } ,  getConfig ( ) . renderAwaitTime ) 
7791  } ) 
7892
7993  exec . on ( 'exit' ,  code  =>  { 
@@ -87,7 +101,7 @@ async function render(
87101  return  Object . assign ( 
88102    execOutputAPI , 
89103    { 
90-       userEvent : bindObjectFnsToInstance ( execOutputAPI ,  userEvent ) 
104+       userEvent : bindObjectFnsToInstance ( execOutputAPI ,  userEvent ) , 
91105    } , 
92106    getQueriesForElement ( execOutputAPI ) , 
93107  )  as  TestInstance  as  RenderResult 
0 commit comments