-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Clear and concise description of the problem
Angular 20 Vitest has an issue where the src
paths are not resolved correctly by istanbul-lib-coverage
, which is used by vitest/coverage-v8
so the coverage report in the default angular project doesn't work.
See: angular/angular-cli#30511
A fix is straightforward using the sourceFinder
property of the createContext
function. However, for it to work, the property needs to be transferred from the options
to the createContext
configuration.
Suggested solution
See PR: #8325
Explanation:
vitest/packages/coverage-v8/src/provider.ts
Line 115 in 87245a5
const context = libReport.createContext({ |
so my suggestion is to add sourceFinder
as an option:
const context = libReport.createContext({
dir: this.options.reportsDirectory,
coverageMap,
watermarks: this.options.watermarks,
sourceFinder: this.options.sourceFinder
})
This would allow the angular/cli builder to rewrite the path that is causing the following issue:
Unable to lookup source: /..../angular20/dist/test-out/20250718T220622393Z-47be11c7/src/app/app.ts
(ENOENT: no such file or directory,
open '/..../angular20/dist/test-out/20250718T220622393Z-47be11c7/src/app/app.ts')
to replace it with: /..../angular20/src/app/app.ts
- remove dist/test-out/20250718T220622393Z-47be11c7/
I tested it, and it solves the issue. Angular 20 with Vitest is able to generate proper code coverage reports without the error.
Alternative
Is there an alternative approach or a config I'm missing?
a custom reporter / provider could be used but that is not as nice as the sourceFinder.
also maybe the source folder where the src file are can be configurated / it's maybe a path config issue
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.