Skip to content

Commit c0c1670

Browse files
committed
fix(@angular-devkit/build-angular): pass missing options to Karma esbuild builder
Ensure that several previously omitted options are correctly passed to the Karma esbuild builder, improving consistency and expected behavior.
1 parent 0599580 commit c0c1670

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

packages/angular_devkit/build_angular/src/builders/karma/application_builder.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as path from 'path';
2525
import { Observable, Subscriber, catchError, defaultIfEmpty, from, of, switchMap } from 'rxjs';
2626
import { Configuration } from 'webpack';
2727
import { ExecutionTransformer } from '../../transforms';
28+
import { normalizeFileReplacements } from '../../utils';
2829
import { OutputHashing } from '../browser-esbuild/schema';
2930
import { findTests, getTestEntrypoints } from './find-tests';
3031
import { Schema as KarmaBuilderOptions } from './schema';
@@ -400,17 +401,24 @@ async function initializeApplication(
400401
index: false,
401402
outputHashing: OutputHashing.None,
402403
optimization: false,
403-
sourceMap: {
404-
scripts: true,
405-
styles: true,
406-
vendor: true,
407-
},
404+
sourceMap: options.codeCoverage
405+
? {
406+
scripts: true,
407+
styles: true,
408+
vendor: true,
409+
}
410+
: options.sourceMap,
408411
instrumentForCoverage,
409412
styles: options.styles,
413+
scripts: options.scripts,
410414
polyfills,
411415
webWorkerTsConfig: options.webWorkerTsConfig,
412416
watch: options.watch ?? !karmaOptions.singleRun,
413417
stylePreprocessorOptions: options.stylePreprocessorOptions,
418+
inlineStyleLanguage: options.inlineStyleLanguage,
419+
fileReplacements: options.fileReplacements
420+
? normalizeFileReplacements(options.fileReplacements, './')
421+
: undefined,
414422
};
415423

416424
// Build tests with `application` builder, using test files as entry points.
@@ -447,6 +455,16 @@ async function initializeApplication(
447455
};
448456

449457
karmaOptions.files ??= [];
458+
if (options.scripts?.length) {
459+
// This should be more granular to support named bundles.
460+
// However, it replicates the behavior of the Karma Webpack-based builder.
461+
karmaOptions.files.push({
462+
pattern: `${outputPath}/scripts.js`,
463+
watched: false,
464+
type: 'js',
465+
});
466+
}
467+
450468
karmaOptions.files.push(
451469
// Serve global setup script.
452470
{ pattern: `${outputPath}/${mainName}.js`, type: 'module', watched: false },

0 commit comments

Comments
 (0)