New AOT options for Karma also run code coverage on component HTML files #30016
Labels
area: @angular/build
devkit/build-angular:karma
needs: discussion
On the agenda for team meeting to determine next steps
Command
test
Is this a regression?
The previous version in which this bug was not present was
No response
Description
When using the new-in-19.2.x option in angular.json to run Karma using AOT, I was surprised to find that my code coverage metrics suddenly got a lot worse. Looking into the output of "ng test" with code coverage enabled, I found that the number of statements and lines touched roughly doubled compared to when I run the same tests with AOT turned off. By looking at the files generated by karma-coverage, I found that in AOT mode the component HTML files are also being instrumented for code coverage now. I assume this is because AOT mode compiles the templates into the Javascript for test execution.
Was this intentional? If it was, at the very least it probably should have been mentioned in the release notes. I can't find any way to configure the codeCoverageExclude options to omit the component HTML files. I would imagine nearly every app will see a drop in their code coverage as a result of this difference, especially given that most of the IDE tooling around code coverage doesn't even consider the possibility that HTML files would be included. It's also not obvious at all how to cover the HTML; I have files that are listed as fully covered with basically no difference in the tests compared to ones that aren't marked as covered at all.
Minimal Reproduction
Create a simple component with a simple test and run Karma with code coverage enabled both with AOT enabled and AOT disabled. With AOT enabled, the component HTML will be instrumented in addition to the Typescript. With AOT disabled, only the Typescript is instrumented.
Exception or Error
Your Environment
Anything else relevant?
No response
The text was updated successfully, but these errors were encountered: