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 6771a14 commit 6fa24bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 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 @@ -407,10 +408,15 @@ async function initializeApplication(
},
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 +453,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
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/test/test-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default async function () {

// prepare global scripts test files
await writeMultipleFiles({
'src/string-script.js': `stringScriptGlobal = 'string-scripts.js';`,
'src/input-script.js': `inputScriptGlobal = 'input-scripts.js';`,
'src/string-script.js': `globalThis.stringScriptGlobal = 'string-scripts.js';`,
'src/input-script.js': `globalThis.inputScriptGlobal = 'input-scripts.js';`,
'src/typings.d.ts': `
declare var stringScriptGlobal: any;
declare var inputScriptGlobal: any;
Expand Down

0 comments on commit 6fa24bd

Please sign in to comment.