fix(@angular/build): resolve coverage overrides paths relative to workspace root#32926
Open
maruthang wants to merge 1 commit intoangular:mainfrom
Open
fix(@angular/build): resolve coverage overrides paths relative to workspace root#32926maruthang wants to merge 1 commit intoangular:mainfrom
maruthang wants to merge 1 commit intoangular:mainfrom
Conversation
…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
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
@angular/build:karma, coverageoverridesdefined inkarma.conf.jsundercoverageReporter.check.each.overrides(orglobal.overrides) are silently ignored.Root cause
The builder sets
karmaOptions.basePathto the temporary build output directory (e.g.dist/test-out/<uuid>).karma-coveragenormalises each coverage-map key (an absolute source file path) by computingpath.relative(basePath, absoluteKey). So/workspace/src/app/app.tsbecomes../../../src/app/app.ts, which never matches a user-written pattern likesrc/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.overridesandcoverageReporter.check.each.overridesso they are expressed as paths relative tobasePath(the temp output path), which is exactly howkarma-coveragenormalises coverage-map keys.This follows the same pattern already used for
junitReporter.outputDir(adjusted post-parse to account for the changedbasePath).Relative patterns are resolved from
workspaceRoot; absolute patterns are used as-is — both are then made relative tooutputPath.Behaviour change
overrides: { 'src/app/app.ts': { ... } }silently ignoredCloses #30956