16
16
*/
17
17
18
18
// @ts -ignore
19
- import { spawn } from 'child-process-promise' ;
19
+ import {
20
+ spawn ,
21
+ ChildProcessPromise ,
22
+ SpawnPromiseResult
23
+ } from 'child-process-promise' ;
20
24
import * as path from 'path' ;
21
25
// @ts -ignore
22
26
import * as freePortFinder from 'find-free-port' ;
@@ -35,19 +39,32 @@ function runTest(port: number, projectId: string, withPersistence: boolean) {
35
39
// TODO(b/113267261): Include browser test once WebChannel support is
36
40
// ready in Firestore emulator.
37
41
// Use `prod` to allow test runner's env variable overrides to work.
42
+ const childProcesses : ChildProcessPromise < SpawnPromiseResult > [ ] = [ ] ;
38
43
if ( withPersistence ) {
39
- return Promise . all ( [
44
+ childProcesses . push (
40
45
spawn ( 'yarn' , [ 'test:node:persistence:prod' ] , options ) ,
41
46
spawn ( 'yarn' , [ 'test:exp:persistence:prod' ] , options ) ,
42
47
spawn ( 'yarn' , [ 'test:lite:prod' ] , options )
43
- ] ) ;
48
+ ) ;
44
49
} else {
45
- return Promise . all ( [
50
+ childProcesses . push (
46
51
spawn ( 'yarn' , [ 'test:node:prod' ] , options ) ,
47
52
spawn ( 'yarn' , [ 'test:exp:prod' ] , options ) ,
48
53
spawn ( 'yarn' , [ 'test:lite:prod' ] , options )
49
- ] ) ;
54
+ ) ;
50
55
}
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 ) ;
51
68
}
52
69
53
70
async function run ( ) : Promise < void > {
0 commit comments