Skip to content

Commit 1d7eab3

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 3f4acd4 commit 1d7eab3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,13 @@ async function initializeApplication(
407407
},
408408
instrumentForCoverage,
409409
styles: options.styles,
410+
scripts: options.scripts,
410411
polyfills,
411412
webWorkerTsConfig: options.webWorkerTsConfig,
412413
watch: options.watch ?? !karmaOptions.singleRun,
413414
stylePreprocessorOptions: options.stylePreprocessorOptions,
415+
inlineStyleLanguage: options.inlineStyleLanguage,
416+
fileReplacements: options.fileReplacements as BuildOptions['fileReplacements'],
414417
};
415418

416419
// Build tests with `application` builder, using test files as entry points.
@@ -447,6 +450,16 @@ async function initializeApplication(
447450
};
448451

449452
karmaOptions.files ??= [];
453+
if (options.scripts?.length) {
454+
// This should be more granular to support named bundles.
455+
// However, it replicates the behavior of the Karma Webpack-based builder.
456+
karmaOptions.files.push({
457+
pattern: `${outputPath}/scripts.js`,
458+
watched: false,
459+
type: 'js',
460+
});
461+
}
462+
450463
karmaOptions.files.push(
451464
// Serve global setup script.
452465
{ pattern: `${outputPath}/${mainName}.js`, type: 'module', watched: false },

tests/legacy-cli/e2e/tests/test/test-scripts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export default async function () {
1010

1111
// prepare global scripts test files
1212
await writeMultipleFiles({
13-
'src/string-script.js': `stringScriptGlobal = 'string-scripts.js';`,
14-
'src/input-script.js': `inputScriptGlobal = 'input-scripts.js';`,
13+
'src/string-script.js': `globalThis.stringScriptGlobal = 'string-scripts.js';`,
14+
'src/input-script.js': `globalThis.inputScriptGlobal = 'input-scripts.js';`,
1515
'src/typings.d.ts': `
1616
declare var stringScriptGlobal: any;
1717
declare var inputScriptGlobal: any;

0 commit comments

Comments
 (0)