1616 */
1717
1818// @ts -ignore
19- import { spawn } from 'child-process-promise' ;
19+ import {
20+ spawn ,
21+ ChildProcessPromise ,
22+ SpawnPromiseResult
23+ } from 'child-process-promise' ;
2024import * as path from 'path' ;
2125// @ts -ignore
2226import * as freePortFinder from 'find-free-port' ;
@@ -35,19 +39,32 @@ function runTest(port: number, projectId: string, withPersistence: boolean) {
3539 // TODO(b/113267261): Include browser test once WebChannel support is
3640 // ready in Firestore emulator.
3741 // Use `prod` to allow test runner's env variable overrides to work.
42+ const childProcesses : ChildProcessPromise < SpawnPromiseResult > [ ] = [ ] ;
3843 if ( withPersistence ) {
39- return Promise . all ( [
44+ childProcesses . push (
4045 spawn ( 'yarn' , [ 'test:node:persistence:prod' ] , options ) ,
4146 spawn ( 'yarn' , [ 'test:exp:persistence:prod' ] , options ) ,
4247 spawn ( 'yarn' , [ 'test:lite:prod' ] , options )
43- ] ) ;
48+ ) ;
4449 } else {
45- return Promise . all ( [
50+ childProcesses . push (
4651 spawn ( 'yarn' , [ 'test:node:prod' ] , options ) ,
4752 spawn ( 'yarn' , [ 'test:exp:prod' ] , options ) ,
4853 spawn ( 'yarn' , [ 'test:lite:prod' ] , options )
49- ] ) ;
54+ ) ;
5055 }
56+
57+ process . once ( 'exit' , ( ) =>
58+ childProcesses . forEach ( p => p . childProcess . kill ( ) )
59+ ) ;
60+ process . once ( 'SIGINT' , ( ) =>
61+ childProcesses . forEach ( p => p . childProcess . kill ( 'SIGINT' ) )
62+ ) ;
63+ process . once ( 'SIGTERM' , ( ) =>
64+ childProcesses . forEach ( p => p . childProcess . kill ( 'SIGTERM' ) )
65+ ) ;
66+
67+ return Promise . all ( childProcesses ) ;
5168}
5269
5370async function run ( ) : Promise < void > {
0 commit comments