9
9
10
10
import { DefaultTimeout , TestLogger , runTargetSpec } from '@angular-devkit/architect/testing' ;
11
11
import { join , normalize , virtualFs } from '@angular-devkit/core' ;
12
- import { debounceTime , take , tap } from 'rxjs/operators' ;
12
+ import { debounceTime , take , takeWhile , tap } from 'rxjs/operators' ;
13
13
import { browserTargetSpec , host } from '../utils' ;
14
14
import { lazyModuleFiles , lazyModuleImport } from './lazy-module_spec_large' ;
15
15
@@ -65,29 +65,28 @@ describe('Browser Builder rebuilds', () => {
65
65
66
66
const overrides = { watch : true } ;
67
67
68
- let buildNumber = 0 ;
69
-
68
+ let buildCount = 0 ;
69
+ let phase = 1 ;
70
70
runTargetSpec ( host , browserTargetSpec , overrides , DefaultTimeout * 3 ) . pipe (
71
- // We must debounce on watch mode because file watchers are not very accurate.
72
- // Changes from just before a process runs can be picked up and cause rebuilds.
73
- // In this case, cleanup from the test right before this one causes a few rebuilds.
74
- debounceTime ( 1000 ) ,
75
- tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
71
+ tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true , 'build should succeed' ) ) ,
76
72
tap ( ( ) => {
77
- buildNumber += 1 ;
78
- switch ( buildNumber ) {
73
+ buildCount ++ ;
74
+ const hasLazyChunk = host . scopedSync ( ) . exists ( join ( outputPath , 'lazy-lazy-module.js' ) ) ;
75
+ switch ( phase ) {
79
76
case 1 :
80
77
// No lazy chunk should exist.
81
- expect ( host . scopedSync ( ) . exists ( join ( outputPath , 'lazy-module.js' ) ) ) . toBe ( false ) ;
82
- // Write the lazy chunk files. Order matters when writing these, because of imports.
83
- host . writeMultipleFiles ( lazyModuleFiles ) ;
84
- host . writeMultipleFiles ( lazyModuleImport ) ;
78
+ if ( ! hasLazyChunk ) {
79
+ phase = 2 ;
80
+ host . writeMultipleFiles ( { ... lazyModuleFiles , ... lazyModuleImport } ) ;
81
+ }
85
82
break ;
86
83
87
84
case 2 :
88
85
// A lazy chunk should have been with the filename.
89
- expect ( host . scopedSync ( ) . exists ( join ( outputPath , 'lazy-lazy-module.js' ) ) ) . toBe ( true ) ;
90
- host . writeMultipleFiles ( goldenValueFiles ) ;
86
+ if ( hasLazyChunk ) {
87
+ phase = 3 ;
88
+ host . writeMultipleFiles ( goldenValueFiles ) ;
89
+ }
91
90
break ;
92
91
93
92
case 3 :
@@ -101,15 +100,18 @@ describe('Browser Builder rebuilds', () => {
101
100
const content = virtualFs . fileBufferToString (
102
101
host . scopedSync ( ) . read ( normalize ( fileName ) ) ,
103
102
) ;
104
- expect ( content ) . toMatch ( re ) ;
105
- break ;
106
103
107
- default :
104
+ if ( re . test ( content ) ) {
105
+ phase = 4 ;
106
+ }
108
107
break ;
109
108
}
110
109
} ) ,
111
- take ( 3 ) ,
112
- ) . toPromise ( ) . then ( done , done . fail ) ;
110
+ takeWhile ( ( ) => phase < 4 ) ,
111
+ ) . toPromise ( ) . then (
112
+ ( ) => done ( ) ,
113
+ ( ) => done . fail ( `stuck at phase ${ phase } [builds: ${ buildCount } ]` ) ,
114
+ ) ;
113
115
} ) ;
114
116
115
117
it ( 'rebuilds on CSS changes' , ( done ) => {
0 commit comments