fix(@angular/build): correct Vitest coverage reporting for test files #31122
Add this suggestion to a batch that can be applied as a single commit.
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.
Add this suggestion to a batch that can be applied as a single commit.
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.
Suggestion cannot be applied right now. Please check back later.
Test coverage reporting within the Vitest runner was inaccurate because the test files themselves were being included in the coverage analysis. This was caused by how the in-memory provider directly loaded the test content.
This commit resolves the issue by introducing an intermediate virtual module for each test. The test entry point now only imports this module, which in turn contains the bundled test code. This extra layer of indirection prevents Vitest from including the test files in the coverage results, leading to an accurate analysis.
To support this change, the
getTestEntrypoints
function now removes the.spec
or.test
extension from bundle names, ensuring cleaner module identifiers. The Vitest runner has also been updated to better handle coverage exclusion options and resolve relative paths more reliably.Closes #30511
Closes #30557