Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New AOT options for Karma also run code coverage on component HTML files #30016

Open
1 task
hamfastgamgee opened this issue Apr 3, 2025 · 0 comments
Open
1 task
Labels
area: @angular/build devkit/build-angular:karma needs: discussion On the agenda for team meeting to determine next steps

Comments

@hamfastgamgee
Copy link

Command

test

Is this a regression?

  • Yes, this behavior used to work in the previous version

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

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 19.2.6
Node: 22.14.0
Package Manager: npm 11.2.0
OS: win32 x64

Angular: 19.2.5
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1902.6
@angular-devkit/build-angular     19.2.6
@angular-devkit/core              19.2.6 (cli-only)
@angular-devkit/schematics        19.2.6
@angular/cdk                      19.2.8
@angular/cli                      19.2.6
@angular/material                 19.2.8
@angular/material-luxon-adapter   19.2.8
@schematics/angular               19.2.6
rxjs                              7.8.2
typescript                        5.8.2
zone.js                           0.15.0

Anything else relevant?

No response

@clydin clydin added the needs: discussion On the agenda for team meeting to determine next steps label Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @angular/build devkit/build-angular:karma needs: discussion On the agenda for team meeting to determine next steps
Projects
None yet
Development

No branches or pull requests

3 participants