Skip to content

Code coverage with Vitest v8 reports empty results #31895

@Mikastark

Description

@Mikastark

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

Since Angular v21, Vitest is the new default test runner. However, when generating code coverage reports using @vitest/coverage-v8, the output is empty, showing 0% coverage across all metrics.

Steps to Reproduce:

  1. Generate empty Angular project:
    ng new whatever
  2. Install @vitest/coverage-v8 as a dev dependency:
    npm install --save-dev @vitest/coverage-v8
  3. Run the test coverage command:
    ng test --coverage
  4. Observe the terminal output:
    % Coverage report from v8
    ----------|---------|----------|---------|---------|-------------------
    File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
    ----------|---------|----------|---------|---------|-------------------
    All files |       0 |        0 |       0 |       0 |
    ----------|---------|----------|---------|---------|-------------------
    
  5. Check the generated report in the coverage/ folder—it displays the same empty results.

The coverage report shows 0% for all files and metrics, regardless of actual test coverage.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No errors or warnings are displayed during the test run.

Please provide the environment you discovered this bug in (run ng version)

Angular CLI       : 21.0.0
Angular           : 21.0.0
Node.js           : 24.11.1
Package Manager   : npm 11.6.2
Operating System  : win32 x64

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

Anything else?

The coverage report should accurately reflect the test coverage of the project, similar to the previous setup with Karma/Jasmine/Istanbul in Angular v20.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions