@@ -136,11 +136,7 @@ function normalizePolyfills(polyfills) {
136
136
async function collectEntrypoints ( options , context , projectSourceRoot ) {
137
137
// Glob for files to test.
138
138
const testFiles = await ( 0 , find_tests_1 . findTests ) ( options . include ?? [ ] , options . exclude ?? [ ] , context . workspaceRoot , projectSourceRoot ) ;
139
- const entryPoints = new Set ( [
140
- ...testFiles ,
141
- '@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ,
142
- ] ) ;
143
- return entryPoints ;
139
+ return new Set ( testFiles ) ;
144
140
}
145
141
async function initializeApplication ( options , context , karmaOptions , transforms = { } ) {
146
142
if ( transforms . webpackConfiguration ) {
@@ -153,6 +149,14 @@ async function initializeApplication(options, context, karmaOptions, transforms
153
149
collectEntrypoints ( options , context , projectSourceRoot ) ,
154
150
fs . rm ( outputPath , { recursive : true , force : true } ) ,
155
151
] ) ;
152
+ let mainName = 'init_test_bed' ;
153
+ if ( options . main ) {
154
+ entryPoints . add ( options . main ) ;
155
+ mainName = path . basename ( options . main , path . extname ( options . main ) ) ;
156
+ }
157
+ else {
158
+ entryPoints . add ( '@angular-devkit/build-angular/src/builders/karma/init_test_bed.js' ) ;
159
+ }
156
160
const instrumentForCoverage = options . codeCoverage
157
161
? createInstrumentationFilter ( projectSourceRoot , getInstrumentationExcludedPaths ( context . workspaceRoot , options . codeCoverageExclude ?? [ ] ) )
158
162
: undefined ;
@@ -188,8 +192,15 @@ async function initializeApplication(options, context, karmaOptions, transforms
188
192
karmaOptions . files . push (
189
193
// Serve polyfills first.
190
194
{ pattern : `${ outputPath } /polyfills.js` , type : 'module' } ,
191
- // Allow loading of chunk-* files but don't include them all on load.
192
- { pattern : `${ outputPath } /{chunk,worker}-*.js` , type : 'module' , included : false } ) ;
195
+ // Serve global setup script.
196
+ { pattern : `${ outputPath } /${ mainName } .js` , type : 'module' } ,
197
+ // Serve all source maps.
198
+ { pattern : `${ outputPath } /*.map` , included : false } ) ;
199
+ if ( hasChunkOrWorkerFiles ( buildOutput . files ) ) {
200
+ karmaOptions . files . push (
201
+ // Allow loading of chunk-* files but don't include them all on load.
202
+ { pattern : `${ outputPath } /{chunk,worker}-*.js` , type : 'module' , included : false } ) ;
203
+ }
193
204
karmaOptions . files . push (
194
205
// Serve remaining JS on page load, these are the test entrypoints.
195
206
{ pattern : `${ outputPath } /*.js` , type : 'module' } ) ;
@@ -221,6 +232,11 @@ async function initializeApplication(options, context, karmaOptions, transforms
221
232
}
222
233
return [ karma , parsedKarmaConfig , buildOptions ] ;
223
234
}
235
+ function hasChunkOrWorkerFiles ( files ) {
236
+ return Object . keys ( files ) . some ( ( filename ) => {
237
+ return / (?: ^ | \/ ) (?: w o r k e r | c h u n k ) [ ^ / ] + \. j s $ / . test ( filename ) ;
238
+ } ) ;
239
+ }
224
240
async function writeTestFiles ( files , testDir ) {
225
241
const directoryExists = new Set ( ) ;
226
242
// Writes the test related output files to disk and ensures the containing directories are present
0 commit comments