@@ -438,7 +438,8 @@ async function initializeApplication(
438438 await writeTestFiles ( buildOutput . files , buildOptions . outputPath ) ;
439439
440440 // We need to add this to the beginning *after* the testing framework has
441- // prepended its files.
441+ // prepended its files. The output path is required for each since they are
442+ // added later in the test process via a plugin.
442443 const polyfillsFile : FilePattern = {
443444 pattern : `${ outputPath } /polyfills.js` ,
444445 included : true ,
@@ -454,31 +455,33 @@ async function initializeApplication(
454455 watched : false ,
455456 } ;
456457
458+ karmaOptions . basePath = outputPath ;
459+
457460 karmaOptions . files ??= [ ] ;
458461 if ( options . scripts ?. length ) {
459462 // This should be more granular to support named bundles.
460463 // However, it replicates the behavior of the Karma Webpack-based builder.
461464 karmaOptions . files . push ( {
462- pattern : `${ outputPath } / scripts.js` ,
465+ pattern : `scripts.js` ,
463466 watched : false ,
464467 type : 'js' ,
465468 } ) ;
466469 }
467470
468471 karmaOptions . files . push (
469472 // Serve global setup script.
470- { pattern : `${ outputPath } / ${ mainName } .js` , type : 'module' , watched : false } ,
473+ { pattern : `${ mainName } .js` , type : 'module' , watched : false } ,
471474 // Serve all source maps.
472- { pattern : `${ outputPath } / *.map` , included : false , watched : false } ,
475+ { pattern : `*.map` , included : false , watched : false } ,
473476 // These are the test entrypoints.
474- { pattern : `${ outputPath } / spec-*.js` , type : 'module' , watched : false } ,
477+ { pattern : `spec-*.js` , type : 'module' , watched : false } ,
475478 ) ;
476479
477480 if ( hasChunkOrWorkerFiles ( buildOutput . files ) ) {
478481 karmaOptions . files . push (
479482 // Allow loading of chunk-* files but don't include them all on load.
480483 {
481- pattern : `${ outputPath } / {chunk,worker}-*.js` ,
484+ pattern : `{chunk,worker}-*.js` ,
482485 type : 'module' ,
483486 included : false ,
484487 watched : false ,
@@ -488,7 +491,7 @@ async function initializeApplication(
488491
489492 if ( options . styles ?. length ) {
490493 // Serve CSS outputs on page load, these are the global styles.
491- karmaOptions . files . push ( { pattern : `${ outputPath } / *.css` , type : 'css' , watched : false } ) ;
494+ karmaOptions . files . push ( { pattern : `*.css` , type : 'css' , watched : false } ) ;
492495 }
493496
494497 const parsedKarmaConfig : Config & ConfigOptions = await karma . config . parseConfig (
0 commit comments