Skip to content

Inaccurate code coverage with aot testing #64583

@cexbrayat

Description

@cexbrayat

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

Running ng test with AoT enabled produced inaccurate code coverage for branches, with signals (always?) marked as a not tested branch.

For example: input.required<UserModel>(); has <UserModel>() marked as untested (but input.required is marked as tested),
computed(...) or signal(...) have their last parenthesis marked as an untested branch as well.

Minimal Reproduction

This can be reproduced in a brand new CLI app.

npx @angular/cli@21.0.0-next.8 new aot-coverage --defaults --no-routing
cd aot-coverage

Running ng test --no-watch --code-coverage gives:

=============================== Coverage summary ===============================
Statements   : 100% ( 5/5 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 0/0 )
Lines        : 100% ( 3/3 )
================================================================================

Running ng test --no-watch --code-coverage --aot gives:

=============================== Coverage summary ===============================
Statements   : 100% ( 50/50 )
Branches     : 85.71% ( 6/7 )
Functions    : 100% ( 7/7 )
Lines        : 100% ( 43/43 )
================================================================================

In coverage/aot-coverage/app.ts.html we can see the last parenthesis of the signal is marked as not tested:

Image

Exception or Error


Your Environment

Angular CLI       : 21.0.0-next.8
Angular           : 21.0.0-next.8
Node.js           : 22.18.0
Package Manager   : npm 10.9.0
Operating System  : darwin arm64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.0.0-next.8     │ ^21.0.0-next.8    │
│ @angular/cli              │ 21.0.0-next.8     │ ^21.0.0-next.8    │
│ @angular/common           │ 21.0.0-next.8     │ ^21.0.0-next.0    │
│ @angular/compiler         │ 21.0.0-next.8     │ ^21.0.0-next.0    │
│ @angular/compiler-cli     │ 21.0.0-next.8     │ ^21.0.0-next.0    │
│ @angular/core             │ 21.0.0-next.8     │ ^21.0.0-next.0    │
│ @angular/forms            │ 21.0.0-next.8     │ ^21.0.0-next.0    │
│ @angular/platform-browser │ 21.0.0-next.8     │ ^21.0.0-next.0    │
│ @angular/router           │ 21.0.0-next.8     │ ^21.0.0-next.0    │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

Note that the same happens with the unit-test runner, with Vitest or Karma.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions