{{ message }}
fix(@angular/build): forward tsconfig paths as Vite aliases for Vitest coverage#33024
Open
tomeelog wants to merge 1 commit into
Open
fix(@angular/build): forward tsconfig paths as Vite aliases for Vitest coverage#33024tomeelog wants to merge 1 commit into
tomeelog wants to merge 1 commit into
Conversation
…t coverage When using tsconfig.json 'paths' (e.g. "#/util": ["./src/util"]) with coverage enabled, Vitest's vite:import-analysis plugin fails to resolve path-alias imports from original source files during coverage processing because the Angular CLI's Vitest integration did not expose those aliases to the Vite resolve configuration. The fix reads the tsconfig file, converts every paths entry to a Vite resolve.alias entry (supporting both exact and wildcard patterns), and injects them into the projectDefaults resolve config used by the project workspace. This makes path aliases available during both test execution and coverage instrumentation. Fixes angular#32891
There was a problem hiding this comment.
Code Review
This pull request introduces support for resolving tsconfig path aliases during Vitest unit testing, specifically addressing issues where coverage instrumentation failed to resolve these aliases. It includes logic to parse compilerOptions.paths from the tsconfig file and map them to Vite-compatible resolve aliases. Feedback was provided regarding the robustness of the JSON comment-stripping regex to avoid breaking valid strings and the need to normalize resolved paths to POSIX format for better cross-platform compatibility.
Sorry, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When a project configures
compilerOptions.pathsintsconfig.json(e.g."#/*": ["./src/app/*"]) and runsng testwithcoverage: true, Vitest'svite:import-analysisplugin fails during the coverage phase with:This happens because the Angular CLI's Vitest integration does not forward
tsconfig path aliases to Vite's
resolve.aliasconfiguration. They areresolved during compilation (by esbuild) but not during Vitest's own
Vite-based coverage instrumentation pass.
Issue Number: #32891
What is the new behavior?
The tsconfig file is read at Vitest initialisation time. Its
compilerOptions.pathsentries are converted to Vite-compatibleresolve.aliasobjects (supporting both exact and wildcard patterns) andinjected into the
projectDefaults.resolve.aliasconfig that the AngularCLI passes to the Vitest project workspace.
Path aliases are now resolved correctly during both test execution and
coverage instrumentation.
Does this PR introduce a breaking change?
Other information
The fix is intentionally narrow — it only reads
pathsandbaseUrlfromthe tsconfig, leaving all other resolution behaviour unchanged. Comment
syntax in tsconfig files (C-style
/* */and//) is stripped beforeJSON parsing to handle real-world configs.
A new behavior spec (
vitest-coverage-tsconfig-paths_spec.ts) verifies thefix end-to-end using the builder test harness.