Skip to content

Conversation

clydin
Copy link
Member

@clydin clydin commented Sep 4, 2025

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

@clydin clydin added the target: major This PR is targeted for the next major release label Sep 4, 2025
@clydin clydin force-pushed the unit-test/vitest-coverage branch from d71f1c5 to e66bf78 Compare September 4, 2025 23:16
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.
@clydin clydin force-pushed the unit-test/vitest-coverage branch from e66bf78 to 267e60d Compare September 4, 2025 23:44
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 5, 2025
@clydin clydin requested a review from alan-agius4 September 5, 2025 10:27
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 5, 2025
@clydin clydin merged commit cd5c92b into angular:main Sep 5, 2025
57 of 58 checks passed
@clydin clydin deleted the unit-test/vitest-coverage branch September 5, 2025 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: @angular/build target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vitest: code coverage is always 0 (and is slow) Vitest error the coverage report (Unable to lookup source)
2 participants