Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/angular/build/src/builders/karma/application_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ async function initializeApplication(
await writeTestFiles(buildOutput.files, buildOptions.outputPath);

// We need to add this to the beginning *after* the testing framework has
// prepended its files.
// prepended its files. The output path is required for each since they are
// added later in the test process via a plugin.
const polyfillsFile: FilePattern = {
pattern: `${outputPath}/polyfills.js`,
included: true,
Expand All @@ -458,31 +459,33 @@ async function initializeApplication(
watched: false,
};

karmaOptions.basePath = outputPath;

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`,
pattern: `scripts.js`,
watched: false,
type: 'js',
});
}

karmaOptions.files.push(
// Serve global setup script.
{ pattern: `${outputPath}/${mainName}.js`, type: 'module', watched: false },
{ pattern: `${mainName}.js`, type: 'module', watched: false },
// Serve all source maps.
{ pattern: `${outputPath}/*.map`, included: false, watched: false },
{ pattern: `*.map`, included: false, watched: false },
// These are the test entrypoints.
{ pattern: `${outputPath}/spec-*.js`, type: 'module', watched: false },
{ pattern: `spec-*.js`, type: 'module', watched: false },
);

if (hasChunkOrWorkerFiles(buildOutput.files)) {
karmaOptions.files.push(
// Allow loading of chunk-* files but don't include them all on load.
{
pattern: `${outputPath}/{chunk,worker}-*.js`,
pattern: `{chunk,worker}-*.js`,
type: 'module',
included: false,
watched: false,
Expand All @@ -492,7 +495,7 @@ async function initializeApplication(

if (options.styles?.length) {
// Serve CSS outputs on page load, these are the global styles.
karmaOptions.files.push({ pattern: `${outputPath}/*.css`, type: 'css', watched: false });
karmaOptions.files.push({ pattern: `*.css`, type: 'css', watched: false });
}

const parsedKarmaConfig: Config & ConfigOptions = await karma.config.parseConfig(
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/test/test-sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function () {
throw new Error('ng test should have failed.');
} catch (error) {
assertIsError(error);
assert.match(error.message, /src\/app\/app\.component\.spec\.ts/);
assert.match(error.message, /\(src\/app\/app\.component\.spec\.ts:3:27/);
assert.doesNotMatch(error.message, /_karma_webpack_/);
}

Expand Down
Loading