fix(@angular/build): execute setup file hooks for each spec file when coverage is enabled - #34143
Merged
Merged
Conversation
alan-agius4
marked this pull request as ready for review
September 22, 2026 11:34
There was a problem hiding this comment.
Code Review
This pull request ensures that setup files are not wrapped in virtual import stubs when coverage is enabled in Vitest, allowing setup hooks to run correctly for each spec file. The feedback suggests normalizing the paths in setupFiles to absolute POSIX paths to prevent issues on Windows and with relative paths, which also allows simplifying the setup file detection logic by removing the fragile entryPoint.startsWith('setup') check.
alan-agius4
force-pushed
the
fix-coverage-setup-files
branch
from
September 22, 2026 11:51
0b1620a to
89e9d60
Compare
… coverage is enabled
When code coverage is enabled with the Vitest runner, test entry points are served as a virtual one-line import stub (`import "./${outputPath}";`) so that the test files themselves can be excluded from coverage reports after sourcemap remapping.
However, setup files configured via `setupFiles` were also treated as test entry points and served as virtual stubs. Because Vitest only invalidates the top-level setup module between spec files, the imported intermediate bundle was cached in `vite-node` after its initial evaluation and never re-evaluated on subsequent spec files. This caused setup file hooks (e.g. `beforeEach` / `afterEach`) to silently only run for the first spec file of each worker.
This commit excludes setup files from being wrapped in the virtual coverage stub, allowing them to be directly evaluated and re-evaluated by Vitest before each spec file.
Fixes angular#34137
alan-agius4
force-pushed
the
fix-coverage-setup-files
branch
from
September 22, 2026 13:49
89e9d60 to
a75ea7d
Compare
clydin
approved these changes
Sep 22, 2026
Collaborator
Author
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
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.
When code coverage is enabled with the Vitest runner, test entry points are served as a virtual one-line import stub (
import "./${outputPath}";) so that the test files themselves can be excluded from coverage reports after sourcemap remapping.However, setup files configured via
setupFileswere also registered intestEntryPointMappingsand served as virtual stubs. Because Vitest only invalidates the top-level setup module between spec files, the imported intermediate bundle was cached invite-nodeafter its initial evaluation and never re-evaluated on subsequent spec files. This caused setup file hooks (e.g.beforeEach/afterEach) to silently run only for the first spec file executed by each worker.This PR:
setupFilestoPluginOptionsinplugins.tsand passestestSetupFilesfromexecutor.ts.setupFileSet.has(id)), allowing setup files to be directly evaluated and re-evaluated by Vitest before each spec file.setup-files_spec.tsverifying thatbeforeEachandafterEachhooks in setup files execute for each spec file when coverage is enabled.Fixes #34137