@@ -260,7 +260,7 @@ async function collectEntrypoints(
260
260
options : KarmaBuilderOptions ,
261
261
context : BuilderContext ,
262
262
projectSourceRoot : string ,
263
- ) : Promise < Set < string > > {
263
+ ) : Promise < Map < string , string > > {
264
264
// Glob for files to test.
265
265
const testFiles = await findTests (
266
266
options . include ?? [ ] ,
@@ -269,7 +269,28 @@ async function collectEntrypoints(
269
269
projectSourceRoot ,
270
270
) ;
271
271
272
- return new Set ( testFiles ) ;
272
+ const seen = new Set < string > ( ) ;
273
+
274
+ return new Map (
275
+ Array . from ( testFiles , ( testFile ) => {
276
+ const relativePath = path
277
+ . relative (
278
+ testFile . startsWith ( projectSourceRoot ) ? projectSourceRoot : context . workspaceRoot ,
279
+ testFile ,
280
+ )
281
+ . replace ( / ^ [ . / ] + / , '_' )
282
+ . replace ( / \/ / g, '-' ) ;
283
+ let uniqueName = `spec-${ path . basename ( relativePath , path . extname ( relativePath ) ) } ` ;
284
+ let suffix = 2 ;
285
+ while ( seen . has ( uniqueName ) ) {
286
+ uniqueName = `${ relativePath } -${ suffix } ` ;
287
+ ++ suffix ;
288
+ }
289
+ seen . add ( uniqueName ) ;
290
+
291
+ return [ uniqueName , testFile ] ;
292
+ } ) ,
293
+ ) ;
273
294
}
274
295
275
296
async function initializeApplication (
@@ -298,12 +319,11 @@ async function initializeApplication(
298
319
fs . rm ( outputPath , { recursive : true , force : true } ) ,
299
320
] ) ;
300
321
301
- let mainName = 'init_test_bed ' ;
322
+ const mainName = 'test_main ' ;
302
323
if ( options . main ) {
303
- entryPoints . add ( options . main ) ;
304
- mainName = path . basename ( options . main , path . extname ( options . main ) ) ;
324
+ entryPoints . set ( mainName , options . main ) ;
305
325
} else {
306
- entryPoints . add ( '@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ) ;
326
+ entryPoints . set ( mainName , '@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ) ;
307
327
}
308
328
309
329
const instrumentForCoverage = options . codeCoverage
@@ -358,6 +378,8 @@ async function initializeApplication(
358
378
{ pattern : `${ outputPath } /${ mainName } .js` , type : 'module' , watched : false } ,
359
379
// Serve all source maps.
360
380
{ pattern : `${ outputPath } /*.map` , included : false , watched : false } ,
381
+ // These are the test entrypoints.
382
+ { pattern : `${ outputPath } /spec-*.js` , type : 'module' , watched : false } ,
361
383
) ;
362
384
363
385
if ( hasChunkOrWorkerFiles ( buildOutput . files ) ) {
@@ -371,10 +393,6 @@ async function initializeApplication(
371
393
} ,
372
394
) ;
373
395
}
374
- karmaOptions . files . push (
375
- // Serve remaining JS on page load, these are the test entrypoints.
376
- { pattern : `${ outputPath } /*.js` , type : 'module' , watched : false } ,
377
- ) ;
378
396
379
397
if ( options . styles ?. length ) {
380
398
// Serve CSS outputs on page load, these are the global styles.
0 commit comments