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.
This commit is contained in:
Alan Agius 2025-02-14 14:07:32 +00:00
parent 0599580c1b
commit c0c1670a64

View File

@ -25,6 +25,7 @@ import * as path from 'path';
import { Observable, Subscriber, catchError, defaultIfEmpty, from, of, switchMap } from 'rxjs'; import { Observable, Subscriber, catchError, defaultIfEmpty, from, of, switchMap } from 'rxjs';
import { Configuration } from 'webpack'; import { Configuration } from 'webpack';
import { ExecutionTransformer } from '../../transforms'; import { ExecutionTransformer } from '../../transforms';
import { normalizeFileReplacements } from '../../utils';
import { OutputHashing } from '../browser-esbuild/schema'; import { OutputHashing } from '../browser-esbuild/schema';
import { findTests, getTestEntrypoints } from './find-tests'; import { findTests, getTestEntrypoints } from './find-tests';
import { Schema as KarmaBuilderOptions } from './schema'; import { Schema as KarmaBuilderOptions } from './schema';
@ -400,17 +401,24 @@ async function initializeApplication(
index: false, index: false,
outputHashing: OutputHashing.None, outputHashing: OutputHashing.None,
optimization: false, optimization: false,
sourceMap: { sourceMap: options.codeCoverage
scripts: true, ? {
styles: true, scripts: true,
vendor: true, styles: true,
}, vendor: true,
}
: options.sourceMap,
instrumentForCoverage, instrumentForCoverage,
styles: options.styles, styles: options.styles,
scripts: options.scripts,
polyfills, polyfills,
webWorkerTsConfig: options.webWorkerTsConfig, webWorkerTsConfig: options.webWorkerTsConfig,
watch: options.watch ?? !karmaOptions.singleRun, watch: options.watch ?? !karmaOptions.singleRun,
stylePreprocessorOptions: options.stylePreprocessorOptions, stylePreprocessorOptions: options.stylePreprocessorOptions,
inlineStyleLanguage: options.inlineStyleLanguage,
fileReplacements: options.fileReplacements
? normalizeFileReplacements(options.fileReplacements, './')
: undefined,
}; };
// Build tests with `application` builder, using test files as entry points. // Build tests with `application` builder, using test files as entry points.
@ -447,6 +455,16 @@ async function initializeApplication(
}; };
karmaOptions.files ??= []; karmaOptions.files ??= [];
if (options.scripts?.length) {
// This should be more granular to support named bundles.
// However, it replicates the behavior of the Karma Webpack-based builder.
karmaOptions.files.push({
pattern: `${outputPath}/scripts.js`,
watched: false,
type: 'js',
});
}
karmaOptions.files.push( karmaOptions.files.push(
// Serve global setup script. // Serve global setup script.
{ pattern: `${outputPath}/${mainName}.js`, type: 'module', watched: false }, { pattern: `${outputPath}/${mainName}.js`, type: 'module', watched: false },