Skip to content

Commit a7b75d5

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 5084ba8 commit a7b75d5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
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';
@@ -407,10 +408,15 @@ async function initializeApplication(
407408
},
408409
instrumentForCoverage,
409410
styles: options.styles,
411+
scripts: options.scripts,
410412
polyfills,
411413
webWorkerTsConfig: options.webWorkerTsConfig,
412414
watch: options.watch ?? !karmaOptions.singleRun,
413415
stylePreprocessorOptions: options.stylePreprocessorOptions,
416+
inlineStyleLanguage: options.inlineStyleLanguage,
417+
fileReplacements: options.fileReplacements
418+
? normalizeFileReplacements(options.fileReplacements, './')
419+
: undefined,
414420
};
415421

416422
// Build tests with `application` builder, using test files as entry points.
@@ -447,6 +453,16 @@ async function initializeApplication(
447453
};
448454

449455
karmaOptions.files ??= [];
456+
if (options.scripts?.length) {
457+
// This should be more granular to support named bundles.
458+
// However, it replicates the behavior of the Karma Webpack-based builder.
459+
karmaOptions.files.push({
460+
pattern: `${outputPath}/scripts.js`,
461+
watched: false,
462+
type: 'js',
463+
});
464+
}
465+
450466
karmaOptions.files.push(
451467
// Serve global setup script.
452468
{ 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)