Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request enables and configures Vitest's file system module cache (fsModuleCache) for Angular unit tests. It removes the hardcoded fsModuleCache: false setting and introduces a custom cache key generator via context.defineCacheKeyGenerator to ensure that in-memory built artifacts and test entry points are cached correctly based on their output hashes rather than their disk paths. Additionally, the loading logic has been refactored to use a new getOutputPath helper, and corresponding integration tests have been updated and added to verify that the cache is successfully created and reused across unchanged runs. There are no review comments, so I have no feedback to provide.
1 task
jv3n
force-pushed
the
fix/unit-test-vitest-fs-module-cache
branch
from
October 20, 2026 20:43
b2d7f32 to
9f1aabc
Compare
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.
PR Checklist
PR Type
What is the current behavior?
Issue Number: #34443
The unit-test builder forces
fsModuleCache: false(f0a74e8), because Vitest keys its module cache on the file found on disk while a test entry point is served from its bundle: changing a file imported by a spec did not change the key, and the cache served a stale bundle. As a result the cache can never be used, even when enabled in therunnerConfig.What is the new behavior?
The
angular:test-in-memory-providerplugin defines a cache key generator inconfigureVitest: for a module it serves, the key includes the content hash of the build output file and of its source map, so it changes whenever the served code changes. Modules served from a disk file bail out of the cache; modules the plugin does not serve keep Vitest's default key.fsModuleCacheis no longer forced off, and the output path computation is shared betweenload()and the key generator.The generator is registered through
defineCacheKeyGeneratoron Vitest 5, and throughexperimental_defineCacheKeyGeneratoron Vitest 4.1, which only has that name. Vitest 4.0 has no file system module cache, so no generator is registered there and nothing changes.With deterministic test bundles (#34337), an unchanged build gives the same keys, so the cache is reused across runs.
Tests:
How Vitest builds the key
From Vitest 5.0.5,
packages/vitest/src/node/cache/fsModuleCache.ts(generateCachePath, trimmed):fileContentis the file read from disk forid. For a spec, that is the.spec.tssource, while the module actually served is its bundle, which also contains the application code the spec imports. That is the stale-bundle case behind f0a74e8. The generator's return value maps to:<output hash>:<source map hash>falseorigin: 'disk'has no hash)undefinedExample
A project opting in through its
runnerConfig:value.tswithout touching the spec: the spec's bundle hash changes, so does its key, and the new code runs. Before f0a74e8 this served the old bundle.Does this PR introduce a breaking change?
Other information
Measured on an application with 255 spec files (numbers in #34443): Vitest duration from ~21.4 s to ~18.4–20 s with a warm cache. Changing a file imported by a spec, without touching the spec, makes that spec fail as expected; reverting it reuses the original cache entry. Watch mode is unaffected:
invalidateFilealready drops the memoized cache key of the invalidated modules.