@@ -21,12 +21,14 @@ import {createProcess} from './Process';
2121// passes out events when it understands what data is being
2222// pass sent out of the process
2323export default class Runner extends EventEmitter {
24- debugprocess : ChildProcess ;
24+ debugprocess : ? ChildProcess ;
2525
2626 outputPath : string ;
2727
28+ // $FlowIgnore[value-as-type]
2829 workspace : ProjectWorkspace ;
2930
31+ // $FlowIgnore[value-as-type]
3032 _createProcess : ( workspace : ProjectWorkspace , args : Array < string > ) => ChildProcess ;
3133
3234 watchMode : boolean ;
@@ -39,6 +41,7 @@ export default class Runner extends EventEmitter {
3941
4042 _exited : boolean ;
4143
44+ // $FlowIgnore[value-as-type]
4245 constructor ( workspace : ProjectWorkspace , options ? : Options ) {
4346 super ( ) ;
4447
@@ -97,17 +100,18 @@ export default class Runner extends EventEmitter {
97100 this . watchAll = watchAll ;
98101
99102 const args = this . _getArgs ( ) ;
100- this . debugprocess = this . _createProcess ( this . workspace , args ) ;
101- this . debugprocess . stdout . on ( 'data' , ( data : Buffer ) => {
103+ const debugprocess = this . _createProcess ( this . workspace , args ) ;
104+ this . debugprocess = debugprocess ;
105+ debugprocess . stdout . on ( 'data' , ( data : Buffer ) => {
102106 this . _parseOutput ( data , false ) ;
103107 } ) ;
104108
105- this . debugprocess . stderr . on ( 'data' , ( data : Buffer ) => {
109+ debugprocess . stderr . on ( 'data' , ( data : Buffer ) => {
106110 // jest 23 could send test results message to stderr
107111 // see https://github.com/facebook/jest/pull/4858
108112 this . _parseOutput ( data , true ) ;
109113 } ) ;
110- this . debugprocess . on ( 'exit' , ( code : number | null , signal : string | null ) => {
114+ debugprocess . on ( 'exit' , ( code : number | null , signal : string | null ) => {
111115 this . _exited = true ;
112116
113117 // this is mainly for backward compatibility, should be deprecated soon
@@ -117,12 +121,12 @@ export default class Runner extends EventEmitter {
117121 this . prevMessageTypes . length = 0 ;
118122 } ) ;
119123
120- this . debugprocess . on ( 'error' , ( error : Error ) => {
124+ debugprocess . on ( 'error' , ( error : Error ) => {
121125 this . emit ( 'terminalError' , `Process failed: ${ error . message } ` ) ;
122126 this . prevMessageTypes . length = 0 ;
123127 } ) ;
124128
125- this . debugprocess . on ( 'close' , ( code : number | null , signal : string | null ) => {
129+ debugprocess . on ( 'close' , ( code : number | null , signal : string | null ) => {
126130 // this is mainly for backward compatibility, should be deprecated soon
127131 this . emit ( 'debuggerProcessExit' ) ;
128132
@@ -216,13 +220,15 @@ export default class Runner extends EventEmitter {
216220 // knowing this could leave orphan process...
217221 // eslint-disable-next-line no-console
218222 console . warn (
219- `failed to kill process group, this could leave some orphan process whose ppid=${ this . debugprocess . pid } . error=` ,
223+ `failed to kill process group, this could leave some orphan process whose ppid=${
224+ this . debugprocess ?. pid || 'process-non-exist'
225+ } . error=`,
220226 e
221227 ) ;
222- this . debugprocess . kill ( ) ;
228+ this . debugprocess ? .kill ( ) ;
223229 }
224230 }
225- delete this . debugprocess ;
231+ this . debugprocess = undefined ;
226232 }
227233
228234 // eslint-disable-next-line class-methods-use-this
@@ -242,7 +248,7 @@ export default class Runner extends EventEmitter {
242248 return match ? match . messageType : messageTypes . unknown ;
243249 }
244250
245- doResultsFollowNoTestsFoundMessage ( ) {
251+ doResultsFollowNoTestsFoundMessage ( ) : boolean {
246252 if ( this . prevMessageTypes . length === 1 ) {
247253 return this . prevMessageTypes [ 0 ] === messageTypes . noTests ;
248254 }
0 commit comments