9
9
import * as child_process from 'child_process' ;
10
10
import { EventEmitter } from 'events' ;
11
11
import { join , resolve } from 'path' ;
12
+ import { interval , Subject } from 'rxjs' ;
13
+ import { takeUntil } from 'rxjs/operators' ;
12
14
13
15
import { resolveAndRunNgcc } from '../ngcc' ;
14
16
@@ -17,13 +19,22 @@ const WORKSPACE_ROOT = join(PACKAGE_ROOT, 'integration', 'workspace');
17
19
const PROJECT = join ( WORKSPACE_ROOT , 'projects' , 'demo' ) ;
18
20
19
21
describe ( 'resolveAndRunNgcc' , ( ) => {
22
+ const afterEach$ = new Subject < void > ( ) ;
23
+ afterEach ( ( ) => {
24
+ afterEach$ . next ( ) ;
25
+ } )
26
+
20
27
it ( 'runs ngcc from node_modules where ngcc is resolved to' , async ( ) => {
21
28
const fakeChild = new EventEmitter ( ) ;
22
29
const spy = spyOn ( child_process , 'fork' ) . and . returnValue ( fakeChild as any ) ;
23
30
// Note that tsconfig.json is in the project directory
24
31
const tsconfig = join ( PROJECT , 'tsconfig.json' ) ;
32
+ // Because resolveNgcc is async, we need to periodically emit `close` from the child since
33
+ // `resolveAndRunNgcc` subscribes after the async resolveNgcc.
34
+ interval ( 500 ) . pipe ( takeUntil ( afterEach$ ) ) . subscribe ( ( ) => {
35
+ fakeChild . emit ( 'close' , 0 /* exit code */ ) ;
36
+ } ) ;
25
37
const promise = resolveAndRunNgcc ( tsconfig , { report ( ) { } } ) ;
26
- fakeChild . emit ( 'close' , 0 /* exit code */ ) ;
27
38
await expectAsync ( promise ) . toBeResolved ( ) ;
28
39
expect ( spy . calls . count ( ) ) . toBe ( 1 ) ;
29
40
// First arg is the ngcc binary, second arg is program arguments, third
0 commit comments