@@ -196,7 +196,21 @@ function normalizePolyfills(polyfills) {
196
196
async function collectEntrypoints ( options , context , projectSourceRoot ) {
197
197
// Glob for files to test.
198
198
const testFiles = await ( 0 , find_tests_1 . findTests ) ( options . include ?? [ ] , options . exclude ?? [ ] , context . workspaceRoot , projectSourceRoot ) ;
199
- return new Set ( testFiles ) ;
199
+ const seen = new Set ( ) ;
200
+ return new Map ( Array . from ( testFiles , ( testFile ) => {
201
+ const relativePath = path
202
+ . relative ( testFile . startsWith ( projectSourceRoot ) ? projectSourceRoot : context . workspaceRoot , testFile )
203
+ . replace ( / ^ [ . / ] + / , '_' )
204
+ . replace ( / \/ / g, '-' ) ;
205
+ let uniqueName = `spec-${ path . basename ( relativePath , path . extname ( relativePath ) ) } ` ;
206
+ let suffix = 2 ;
207
+ while ( seen . has ( uniqueName ) ) {
208
+ uniqueName = `${ relativePath } -${ suffix } ` ;
209
+ ++ suffix ;
210
+ }
211
+ seen . add ( uniqueName ) ;
212
+ return [ uniqueName , testFile ] ;
213
+ } ) ) ;
200
214
}
201
215
async function initializeApplication ( options , context , karmaOptions , transforms = { } ) {
202
216
if ( transforms . webpackConfiguration ) {
@@ -209,13 +223,12 @@ async function initializeApplication(options, context, karmaOptions, transforms
209
223
collectEntrypoints ( options , context , projectSourceRoot ) ,
210
224
fs . rm ( outputPath , { recursive : true , force : true } ) ,
211
225
] ) ;
212
- let mainName = 'init_test_bed ' ;
226
+ const mainName = 'test_main ' ;
213
227
if ( options . main ) {
214
- entryPoints . add ( options . main ) ;
215
- mainName = path . basename ( options . main , path . extname ( options . main ) ) ;
228
+ entryPoints . set ( mainName , options . main ) ;
216
229
}
217
230
else {
218
- entryPoints . add ( '@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ) ;
231
+ entryPoints . set ( mainName , '@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ) ;
219
232
}
220
233
const instrumentForCoverage = options . codeCoverage
221
234
? createInstrumentationFilter ( projectSourceRoot , getInstrumentationExcludedPaths ( context . workspaceRoot , options . codeCoverageExclude ?? [ ] ) )
@@ -257,7 +270,9 @@ async function initializeApplication(options, context, karmaOptions, transforms
257
270
// Serve global setup script.
258
271
{ pattern : `${ outputPath } /${ mainName } .js` , type : 'module' , watched : false } ,
259
272
// Serve all source maps.
260
- { pattern : `${ outputPath } /*.map` , included : false , watched : false } ) ;
273
+ { pattern : `${ outputPath } /*.map` , included : false , watched : false } ,
274
+ // These are the test entrypoints.
275
+ { pattern : `${ outputPath } /spec-*.js` , type : 'module' , watched : false } ) ;
261
276
if ( hasChunkOrWorkerFiles ( buildOutput . files ) ) {
262
277
karmaOptions . files . push (
263
278
// Allow loading of chunk-* files but don't include them all on load.
@@ -268,9 +283,6 @@ async function initializeApplication(options, context, karmaOptions, transforms
268
283
watched : false ,
269
284
} ) ;
270
285
}
271
- karmaOptions . files . push (
272
- // Serve remaining JS on page load, these are the test entrypoints.
273
- { pattern : `${ outputPath } /*.js` , type : 'module' , watched : false } ) ;
274
286
if ( options . styles ?. length ) {
275
287
// Serve CSS outputs on page load, these are the global styles.
276
288
karmaOptions . files . push ( { pattern : `${ outputPath } /*.css` , type : 'css' , watched : false } ) ;
0 commit comments