@@ -79,27 +79,28 @@ async function getProjectSourceRoot(context) {
79
79
const sourceRoot = ( projectMetadata . sourceRoot ?? projectMetadata . root ?? '' ) ;
80
80
return path . join ( context . workspaceRoot , sourceRoot ) ;
81
81
}
82
+ function normalizePolyfills ( polyfills ) {
83
+ if ( typeof polyfills === 'string' ) {
84
+ return [ polyfills ] ;
85
+ }
86
+ return polyfills ?? [ ] ;
87
+ }
82
88
async function collectEntrypoints ( options , context , projectSourceRoot ) {
83
89
// Glob for files to test.
84
90
const testFiles = await ( 0 , find_tests_1 . findTests ) ( options . include ?? [ ] , options . exclude ?? [ ] , context . workspaceRoot , projectSourceRoot ) ;
85
91
const entryPoints = new Set ( [
86
92
...testFiles ,
87
93
'@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ,
88
94
] ) ;
89
- // Extract `zone.js/testing` to a separate entry point because it needs to be loaded after Jasmine.
90
- const [ polyfills , hasZoneTesting ] = extractZoneTesting ( options . polyfills ) ;
91
- if ( hasZoneTesting ) {
92
- entryPoints . add ( 'zone.js/testing' ) ;
93
- }
94
- return [ entryPoints , polyfills ] ;
95
+ return entryPoints ;
95
96
}
96
97
async function initializeApplication ( options , context , karmaOptions , transforms = { } ) {
97
98
if ( transforms . webpackConfiguration ) {
98
99
context . logger . warn ( `This build is using the application builder but transforms.webpackConfiguration was provided. The transform will be ignored.` ) ;
99
100
}
100
101
const testDir = path . join ( context . workspaceRoot , 'dist/test-out' , ( 0 , crypto_1 . randomUUID ) ( ) ) ;
101
102
const projectSourceRoot = await getProjectSourceRoot ( context ) ;
102
- const [ karma , [ entryPoints , polyfills ] ] = await Promise . all ( [
103
+ const [ karma , entryPoints ] = await Promise . all ( [
103
104
Promise . resolve ( ) . then ( ( ) => __importStar ( require ( 'karma' ) ) ) ,
104
105
collectEntrypoints ( options , context , projectSourceRoot ) ,
105
106
fs . rm ( testDir , { recursive : true , force : true } ) ,
@@ -124,7 +125,7 @@ async function initializeApplication(options, context, karmaOptions, transforms
124
125
} ,
125
126
instrumentForCoverage,
126
127
styles : options . styles ,
127
- polyfills,
128
+ polyfills : normalizePolyfills ( options . polyfills ) ,
128
129
webWorkerTsConfig : options . webWorkerTsConfig ,
129
130
} , context ) ) ;
130
131
if ( buildOutput . kind === private_1 . ResultKind . Failure ) {
@@ -140,11 +141,8 @@ async function initializeApplication(options, context, karmaOptions, transforms
140
141
// Serve polyfills first.
141
142
{ pattern : `${ testDir } /polyfills.js` , type : 'module' } ,
142
143
// Allow loading of chunk-* files but don't include them all on load.
143
- { pattern : `${ testDir } /chunk-*.js` , type : 'module' , included : false } ,
144
- // Allow loading of worker-* files but don't include them all on load.
145
- { pattern : `${ testDir } /worker-*.js` , type : 'module' , included : false } ,
146
- // `zone.js/testing`, served but not included on page load.
147
- { pattern : `${ testDir } /testing.js` , type : 'module' , included : false } ,
144
+ { pattern : `${ testDir } /{chunk,worker}-*.js` , type : 'module' , included : false } ) ;
145
+ karmaOptions . files . push (
148
146
// Serve remaining JS on page load, these are the test entrypoints.
149
147
{ pattern : `${ testDir } /*.js` , type : 'module' } ) ;
150
148
if ( options . styles ?. length ) {
@@ -199,15 +197,6 @@ async function writeTestFiles(files, testDir) {
199
197
}
200
198
} ) ;
201
199
}
202
- function extractZoneTesting ( polyfills ) {
203
- if ( typeof polyfills === 'string' ) {
204
- polyfills = [ polyfills ] ;
205
- }
206
- polyfills ??= [ ] ;
207
- const polyfillsWithoutZoneTesting = polyfills . filter ( ( polyfill ) => polyfill !== 'zone.js/testing' ) ;
208
- const hasZoneTesting = polyfills . length !== polyfillsWithoutZoneTesting . length ;
209
- return [ polyfillsWithoutZoneTesting , hasZoneTesting ] ;
210
- }
211
200
/** Returns the first item yielded by the given generator and cancels the execution. */
212
201
async function first ( generator ) {
213
202
for await ( const value of generator ) {
0 commit comments