Skip to content

fix(@angular/build): resolve coverage overrides paths relative to workspace root#32926

Open
maruthang wants to merge 1 commit intoangular:mainfrom
maruthang:fix-30956-karma-coverage-overrides
Open

fix(@angular/build): resolve coverage overrides paths relative to workspace root#32926
maruthang wants to merge 1 commit intoangular:mainfrom
maruthang:fix-30956-karma-coverage-overrides

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

Problem

When using @angular/build:karma, coverage overrides defined in karma.conf.js under coverageReporter.check.each.overrides (or global.overrides) are silently ignored.

Root cause

The builder sets karmaOptions.basePath to the temporary build output directory (e.g. dist/test-out/<uuid>). karma-coverage normalises each coverage-map key (an absolute source file path) by computing path.relative(basePath, absoluteKey). So /workspace/src/app/app.ts becomes ../../../src/app/app.ts, which never matches a user-written pattern like src/app/app.ts.

This was confirmed by a community contributor in #30956 who showed that the workaround '../../../src/app/app.ts' worked but was clearly not the intended API.

Fix

After the karma config is parsed, rewrite the keys of coverageReporter.check.global.overrides and coverageReporter.check.each.overrides so they are expressed as paths relative to basePath (the temp output path), which is exactly how karma-coverage normalises coverage-map keys.

This follows the same pattern already used for junitReporter.outputDir (adjusted post-parse to account for the changed basePath).

Relative patterns are resolved from workspaceRoot; absolute patterns are used as-is — both are then made relative to outputPath.

Behaviour change

Before After
overrides: { 'src/app/app.ts': { ... } } silently ignored pattern resolved from workspace root and correctly matched

Closes #30956

…kspace root

karma-coverage normalises coverage-map keys using the karma `basePath`, which
the builder sets to the temporary build output directory. As a result, override
patterns written relative to the workspace root (e.g. `src/app/app.ts`) were
never matched and the overrides were silently ignored.

Fix: after parsing the karma config, rewrite the keys of
`coverageReporter.check.global.overrides` and
`coverageReporter.check.each.overrides` so they are expressed as paths relative
to `basePath` (the temp output path), matching how karma-coverage itself
normalises the keys in the coverage map.

Closes angular#30956
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where Karma coverage reporter overrides were not being correctly applied due to path mismatches. The implementation now rebases override patterns from the workspace root to the Karma base path (output directory) within the application builder. Additionally, a regression test has been introduced to ensure that per-file coverage thresholds are properly respected during the test execution. I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@angular/build:karma ignores overrides in karma.conf.js

1 participant