1
1
import * as ansiColors from 'ansi-colors' ;
2
- import { SpawnOptions } from 'child_process' ;
2
+ import { spawn , SpawnOptions } from 'child_process' ;
3
3
import * as child_process from 'child_process' ;
4
4
import { concat , defer , EMPTY , from } from 'rxjs' ;
5
5
import { repeat , takeLast } from 'rxjs/operators' ;
@@ -121,7 +121,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
121
121
. forEach ( ( line ) => console . error ( colors . yellow ( ' ' + line ) ) ) ;
122
122
} ) ;
123
123
124
- childProcess . on ( 'close' , ( code : number ) => {
124
+ childProcess . on ( 'close' , ( code ) => {
125
125
_processes = _processes . filter ( ( p ) => p !== childProcess ) ;
126
126
127
127
if ( options . waitForMatch && ! matched ) {
@@ -371,7 +371,7 @@ export function silentGit(...args: string[]) {
371
371
* the PATH variable only referencing the local node_modules and local NPM
372
372
* registry (not the test runner or standard global node_modules).
373
373
*/
374
- export async function launchTestProcess ( entry : string , ...args : any [ ] ) {
374
+ export async function launchTestProcess ( entry : string , ...args : any [ ] ) : Promise < void > {
375
375
const tempRoot : string = getGlobalVariable ( 'tmp-root' ) ;
376
376
377
377
// Extract explicit environment variables for the test process.
@@ -382,13 +382,30 @@ export async function launchTestProcess(entry: string, ...args: any[]) {
382
382
} ;
383
383
384
384
// Modify the PATH environment variable...
385
- let paths = ( env . PATH || process . env . PATH ) ! . split ( delimiter ) ;
386
-
387
- // Only include paths within the sandboxed test environment or external
388
- // non angular-cli paths such as /usr/bin for generic commands.
389
- paths = paths . filter ( ( p ) => p . startsWith ( tempRoot ) || ! p . includes ( 'angular-cli' ) ) ;
390
-
391
- env . PATH = paths . join ( delimiter ) ;
392
-
393
- return _exec ( { env } , process . execPath , [ resolve ( __dirname , 'run_test_process' ) , entry , ...args ] ) ;
385
+ env . PATH = ( env . PATH || process . env . PATH )
386
+ ?. split ( delimiter )
387
+ // Only include paths within the sandboxed test environment or external
388
+ // non angular-cli paths such as /usr/bin for generic commands.
389
+ . filter ( ( p ) => p . startsWith ( tempRoot ) || ! p . includes ( 'angular-cli' ) )
390
+ . join ( delimiter ) ;
391
+
392
+ const testProcessArgs = [ resolve ( __dirname , 'run_test_process' ) , entry , ...args ] ;
393
+
394
+ return new Promise < void > ( ( resolve , reject ) => {
395
+ spawn ( process . execPath , testProcessArgs , {
396
+ stdio : 'inherit' ,
397
+ env,
398
+ } )
399
+ . on ( 'close' , ( code ) => {
400
+ if ( ! code ) {
401
+ resolve ( ) ;
402
+ return ;
403
+ }
404
+
405
+ reject ( `Process error - "${ testProcessArgs } ` ) ;
406
+ } )
407
+ . on ( 'error' , ( err ) => {
408
+ reject ( `Process exit error - "${ testProcessArgs } ]\n\n${ err } ` ) ;
409
+ } ) ;
410
+ } ) ;
394
411
}
0 commit comments