1- import { exec } from 'child_process' ;
1+ import { ChildProcess , exec } from 'child_process' ;
22import { delimiter as pathDelimiter } from 'path' ;
33import kill from 'tree-kill' ;
44import OS from 'os-family' ;
@@ -26,13 +26,17 @@ const ENV_PATH_KEY = (function () {
2626
2727
2828export default class TestedApp {
29- constructor ( ) {
30- this . process = null ;
29+ private _killed : boolean ;
30+ public errorPromise : null | Promise < void > ;
31+ private _process : null | ChildProcess ;
32+
33+ public constructor ( ) {
34+ this . _process = null ;
3135 this . errorPromise = null ;
32- this . killed = false ;
36+ this . _killed = false ;
3337 }
3438
35- async start ( command , initDelay ) {
39+ public async start ( command : string , initDelay : number ) : Promise < void > {
3640 this . errorPromise = new Promise ( ( resolve , reject ) => {
3741 const env = Object . assign ( { } , process . env ) ;
3842 const path = env [ ENV_PATH_KEY ] || '' ;
@@ -42,8 +46,8 @@ export default class TestedApp {
4246
4347 env [ ENV_PATH_KEY ] = pathParts . join ( pathDelimiter ) ;
4448
45- this . process = exec ( command , { env } , err => {
46- if ( ! this . killed && err ) {
49+ this . _process = exec ( command , { env } , err => {
50+ if ( ! this . _killed && err ) {
4751 const message = err . stack || String ( err ) ;
4852
4953 reject ( new GeneralError ( RUNTIME_ERRORS . testedAppFailedWithError , message ) ) ;
@@ -57,10 +61,10 @@ export default class TestedApp {
5761 ] ) ;
5862 }
5963
60- async kill ( ) {
61- this . killed = true ;
64+ public async kill ( ) : Promise < void > {
65+ this . _killed = true ;
6266
63- const killPromise = new Promise ( resolve => kill ( this . process . pid , 'SIGTERM' , resolve ) ) ;
67+ const killPromise = new Promise ( resolve => kill ( ( this . _process as ChildProcess ) . pid , 'SIGTERM' , resolve ) ) ;
6468
6569 await killPromise ;
6670 }
0 commit comments