Skip to content

Expose sourceFinder in @vite/coverage-v8 createContext #8324

@teoeter

Description

@teoeter

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:

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions