@@ -85,11 +85,19 @@ async function getProjectSourceRoot(context: BuilderContext): Promise<string> {
85
85
return path . join ( context . workspaceRoot , sourceRoot ) ;
86
86
}
87
87
88
+ function normalizePolyfills ( polyfills : string | string [ ] | undefined ) : string [ ] {
89
+ if ( typeof polyfills === 'string' ) {
90
+ return [ polyfills ] ;
91
+ }
92
+
93
+ return polyfills ?? [ ] ;
94
+ }
95
+
88
96
async function collectEntrypoints (
89
97
options : KarmaBuilderOptions ,
90
98
context : BuilderContext ,
91
99
projectSourceRoot : string ,
92
- ) : Promise < [ Set < string > , string [ ] ] > {
100
+ ) : Promise < Set < string > > {
93
101
// Glob for files to test.
94
102
const testFiles = await findTests (
95
103
options . include ?? [ ] ,
@@ -102,13 +110,8 @@ async function collectEntrypoints(
102
110
...testFiles ,
103
111
'@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ,
104
112
] ) ;
105
- // Extract `zone.js/testing` to a separate entry point because it needs to be loaded after Jasmine.
106
- const [ polyfills , hasZoneTesting ] = extractZoneTesting ( options . polyfills ) ;
107
- if ( hasZoneTesting ) {
108
- entryPoints . add ( 'zone.js/testing' ) ;
109
- }
110
113
111
- return [ entryPoints , polyfills ] ;
114
+ return entryPoints ;
112
115
}
113
116
114
117
async function initializeApplication (
@@ -129,7 +132,7 @@ async function initializeApplication(
129
132
const testDir = path . join ( context . workspaceRoot , 'dist/test-out' , randomUUID ( ) ) ;
130
133
const projectSourceRoot = await getProjectSourceRoot ( context ) ;
131
134
132
- const [ karma , [ entryPoints , polyfills ] ] = await Promise . all ( [
135
+ const [ karma , entryPoints ] = await Promise . all ( [
133
136
import ( 'karma' ) ,
134
137
collectEntrypoints ( options , context , projectSourceRoot ) ,
135
138
fs . rm ( testDir , { recursive : true , force : true } ) ,
@@ -162,7 +165,7 @@ async function initializeApplication(
162
165
} ,
163
166
instrumentForCoverage,
164
167
styles : options . styles ,
165
- polyfills,
168
+ polyfills : normalizePolyfills ( options . polyfills ) ,
166
169
webWorkerTsConfig : options . webWorkerTsConfig ,
167
170
} ,
168
171
context ,
@@ -184,11 +187,10 @@ async function initializeApplication(
184
187
// Serve polyfills first.
185
188
{ pattern : `${ testDir } /polyfills.js` , type : 'module' } ,
186
189
// Allow loading of chunk-* files but don't include them all on load.
187
- { pattern : `${ testDir } /chunk-*.js` , type : 'module' , included : false } ,
188
- // Allow loading of worker-* files but don't include them all on load.
189
- { pattern : `${ testDir } /worker-*.js` , type : 'module' , included : false } ,
190
- // `zone.js/testing`, served but not included on page load.
191
- { pattern : `${ testDir } /testing.js` , type : 'module' , included : false } ,
190
+ { pattern : `${ testDir } /{chunk,worker}-*.js` , type : 'module' , included : false } ,
191
+ ) ;
192
+
193
+ karmaOptions . files . push (
192
194
// Serve remaining JS on page load, these are the test entrypoints.
193
195
{ pattern : `${ testDir } /*.js` , type : 'module' } ,
194
196
) ;
@@ -266,22 +268,6 @@ export async function writeTestFiles(files: Record<string, ResultFile>, testDir:
266
268
} ) ;
267
269
}
268
270
269
- function extractZoneTesting (
270
- polyfills : readonly string [ ] | string | undefined ,
271
- ) : [ polyfills : string [ ] , hasZoneTesting : boolean ] {
272
- if ( typeof polyfills === 'string' ) {
273
- polyfills = [ polyfills ] ;
274
- }
275
- polyfills ??= [ ] ;
276
-
277
- const polyfillsWithoutZoneTesting = polyfills . filter (
278
- ( polyfill ) => polyfill !== 'zone.js/testing' ,
279
- ) ;
280
- const hasZoneTesting = polyfills . length !== polyfillsWithoutZoneTesting . length ;
281
-
282
- return [ polyfillsWithoutZoneTesting , hasZoneTesting ] ;
283
- }
284
-
285
271
/** Returns the first item yielded by the given generator and cancels the execution. */
286
272
async function first < T > ( generator : AsyncIterable < T > ) : Promise < T > {
287
273
for await ( const value of generator ) {
0 commit comments