Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): pass missing options to Karma esb…
Browse files Browse the repository at this point in the history
…uild builder

Ensure that several previously omitted options are correctly passed to the Karma esbuild builder, improving consistency and expected behavior.
  • Loading branch information
alan-agius4 committed Feb 14, 2025
1 parent 0599580 commit c0c1670
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as path from 'path';
import { Observable, Subscriber, catchError, defaultIfEmpty, from, of, switchMap } from 'rxjs';
import { Configuration } from 'webpack';
import { ExecutionTransformer } from '../../transforms';
import { normalizeFileReplacements } from '../../utils';
import { OutputHashing } from '../browser-esbuild/schema';
import { findTests, getTestEntrypoints } from './find-tests';
import { Schema as KarmaBuilderOptions } from './schema';
Expand Down Expand Up @@ -400,17 +401,24 @@ async function initializeApplication(
index: false,
outputHashing: OutputHashing.None,
optimization: false,
sourceMap: {
scripts: true,
styles: true,
vendor: true,
},
sourceMap: options.codeCoverage
? {
scripts: true,
styles: true,
vendor: true,
}
: options.sourceMap,
instrumentForCoverage,
styles: options.styles,
scripts: options.scripts,
polyfills,
webWorkerTsConfig: options.webWorkerTsConfig,
watch: options.watch ?? !karmaOptions.singleRun,
stylePreprocessorOptions: options.stylePreprocessorOptions,
inlineStyleLanguage: options.inlineStyleLanguage,
fileReplacements: options.fileReplacements
? normalizeFileReplacements(options.fileReplacements, './')
: undefined,
};

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

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(
// Serve global setup script.
{ pattern: `${outputPath}/${mainName}.js`, type: 'module', watched: false },
Expand Down

0 comments on commit c0c1670

Please sign in to comment.