@@ -186,12 +186,7 @@ async function collectEntrypoints(
186
186
projectSourceRoot ,
187
187
) ;
188
188
189
- const entryPoints = new Set ( [
190
- ...testFiles ,
191
- '@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ,
192
- ] ) ;
193
-
194
- return entryPoints ;
189
+ return new Set ( testFiles ) ;
195
190
}
196
191
197
192
async function initializeApplication (
@@ -218,6 +213,14 @@ async function initializeApplication(
218
213
fs . rm ( outputPath , { recursive : true , force : true } ) ,
219
214
] ) ;
220
215
216
+ let mainName = 'init_test_bed' ;
217
+ if ( options . main ) {
218
+ entryPoints . add ( options . main ) ;
219
+ mainName = path . basename ( options . main , path . extname ( options . main ) ) ;
220
+ } else {
221
+ entryPoints . add ( '@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ) ;
222
+ }
223
+
221
224
const instrumentForCoverage = options . codeCoverage
222
225
? createInstrumentationFilter (
223
226
projectSourceRoot ,
@@ -261,10 +264,19 @@ async function initializeApplication(
261
264
karmaOptions . files . push (
262
265
// Serve polyfills first.
263
266
{ pattern : `${ outputPath } /polyfills.js` , type : 'module' } ,
264
- // Allow loading of chunk-* files but don't include them all on load.
265
- { pattern : `${ outputPath } /{chunk,worker}-*.js` , type : 'module' , included : false } ,
267
+ // Serve global setup script.
268
+ { pattern : `${ outputPath } /${ mainName } .js` , type : 'module' } ,
269
+ // Serve all source maps.
270
+ { pattern : `${ outputPath } /*.map` , included : false } ,
266
271
) ;
267
272
273
+ if ( hasChunkOrWorkerFiles ( buildOutput . files ) ) {
274
+ karmaOptions . files . push (
275
+ // Allow loading of chunk-* files but don't include them all on load.
276
+ { pattern : `${ outputPath } /{chunk,worker}-*.js` , type : 'module' , included : false } ,
277
+ ) ;
278
+ }
279
+
268
280
karmaOptions . files . push (
269
281
// Serve remaining JS on page load, these are the test entrypoints.
270
282
{ pattern : `${ outputPath } /*.js` , type : 'module' } ,
@@ -316,6 +328,12 @@ async function initializeApplication(
316
328
return [ karma , parsedKarmaConfig , buildOptions ] ;
317
329
}
318
330
331
+ function hasChunkOrWorkerFiles ( files : Record < string , unknown > ) : boolean {
332
+ return Object . keys ( files ) . some ( ( filename ) => {
333
+ return / (?: ^ | \/ ) (?: w o r k e r | c h u n k ) [ ^ / ] + \. j s $ / . test ( filename ) ;
334
+ } ) ;
335
+ }
336
+
319
337
export async function writeTestFiles ( files : Record < string , ResultFile > , testDir : string ) {
320
338
const directoryExists = new Set < string > ( ) ;
321
339
// Writes the test related output files to disk and ensures the containing directories are present
0 commit comments