Command
test
Is this a regression?
The previous version in which this bug was not present was
No response
Description
When adding v8 coverage ignore comments (Vitest docs), generated coverage reports still include suppressed lines. This only happens with the Vitest runner, when using the Karma runner, istanbul ignore comments work as expected.
Minimal Reproduction
- Create a new project:
ng new Test
- Install Vitest coverage:
npm i -D @vitest/coverage-v8
- Add uncovered branch with ignore comment to
src/app/app.ts
export class App {
protected readonly title = signal('Test');
+ constructor() {
+ /* v8 ignore if -- @preserve */
+ if (this.title() === 'Not Test') {
+ console.log('I dont get run!');
+ }
+ }
}
- Run test with coverage
ng test --coverage
Observe ignored code is still marked as uncovered
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 98.24 | 92.3 | 100 | 97.82 |
app.html | 100 | 100 | 100 | 100 |
app.ts | 87.5 | 92.3 | 100 | 75 | 16
----------|---------|----------|---------|---------|-------------------
- Switch runner to Karma in
angular.json
"test": {
- "builder": "@angular/build:unit-test"
+ "builder": "@angular/build:unit-test",
+ "options": {"runner": "karma"}
}
- Install Karma dependencies:
npm i -D karma karma-jasmine karma-coverage karma-chrome-launcher karma-jasmine-html-reporter
- Change coverage ignore comment to istanbul in
src/app/app.ts
< /* v8 ignore if -- @preserve */
---
> /* istanbul ignore if -- @preserve */
- Run tests with coverage
ng test --coverage
- Observe coverage report correctly ignores suppressed lines
=============================== Coverage summary ===============================
Statements : 100% ( 53/53 )
Branches : 100% ( 6/6 )
Functions : 100% ( 9/9 )
Lines : 100% ( 45/45 )
================================================================================
Exception or Error
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI : 21.2.3
Angular : 21.2.5
Node.js : 25.8.1 (Unsupported)
Package Manager : npm 11.11.0
Operating System : linux x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 21.2.3 │ ^21.2.3 │
│ @angular/cli │ 21.2.3 │ ^21.2.3 │
│ @angular/common │ 21.2.5 │ ^21.2.0 │
│ @angular/compiler │ 21.2.5 │ ^21.2.0 │
│ @angular/compiler-cli │ 21.2.5 │ ^21.2.0 │
│ @angular/core │ 21.2.5 │ ^21.2.0 │
│ @angular/forms │ 21.2.5 │ ^21.2.0 │
│ @angular/platform-browser │ 21.2.5 │ ^21.2.0 │
│ @angular/router │ 21.2.5 │ ^21.2.0 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 5.9.3 │ ~5.9.2 │
│ vitest │ 4.1.0 │ ^4.0.8 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?
No response
Command
test
Is this a regression?
The previous version in which this bug was not present was
No response
Description
When adding v8 coverage ignore comments (Vitest docs), generated coverage reports still include suppressed lines. This only happens with the Vitest runner, when using the Karma runner, istanbul ignore comments work as expected.
Minimal Reproduction
ng new Testcd Testnpm i -D @vitest/coverage-v8src/app/app.tsexport class App { protected readonly title = signal('Test'); + constructor() { + /* v8 ignore if -- @preserve */ + if (this.title() === 'Not Test') { + console.log('I dont get run!'); + } + } }ng test --coverageObserve ignored code is still marked as uncovered
angular.json"test": { - "builder": "@angular/build:unit-test" + "builder": "@angular/build:unit-test", + "options": {"runner": "karma"} }npm i -D karma karma-jasmine karma-coverage karma-chrome-launcher karma-jasmine-html-reportersrc/app/app.tsng test --coverageException or Error
Your Environment
Anything else relevant?
No response