Skip to content

fix(@angular/build): disable Vitest fsModuleCache in unit-test builder - #34311

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix/vitest-disable-fs-module-cache
Oct 12, 2026
Merged

alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix/vitest-disable-fs-module-cache

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

Vitest 5.0.4 enabled fsModuleCache by default, which caches transformed modules on disk keyed by the raw source file content on disk before calling Vite's load() hook. Because @angular/build:unit-test pre-bundles test entry points and their imported application modules into memory, changes to imported application files do not change the on-disk .spec.ts file content, causing Vitest's fsModuleCache to serve stale cached bundles across test runs.

Vitest 5.0.4 enabled `fsModuleCache` by default, which caches transformed
modules on disk keyed by the raw source file content on disk before calling
Vite's `load()` hook. Because `@angular/build:unit-test` pre-bundles test entry
points and their imported application modules into memory, changes to imported
application files do not change the on-disk `.spec.ts` file content, causing
Vitest's `fsModuleCache` to serve stale cached bundles across test runs.
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Oct 12, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request disables Vitest's fsModuleCache by setting it to false in the configuration plugin. A review comment points out that a user's explicit configuration in vitest.config.ts could override this setting due to Vite's config merging behavior, and suggests deleting the option from the user's configuration while warning them.

@alan-agius4
alan-agius4 merged commit f0a74e8 into angular:main Oct 12, 2026
42 checks passed
@alan-agius4
alan-agius4 deleted the fix/vitest-disable-fs-module-cache branch October 12, 2026 11:24
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

FreekMencke added a commit to osrs-tracker/osrs-tracker-web that referenced this pull request Oct 14, 2026
Vitest 5 caches transformed modules in node_modules/.vitest-cache, keyed by
the spec file on disk, while Angular's unit-test builder hands it the spec
bundled with the code under test. A change to that code alone reused the old
bundle, so local runs (and verify.sh) could pass on stale code. CI installs
fresh and was unaffected.

A runnerConfig file sets fsModuleCache: false until @angular/build ships
angular/angular-cli#34311 (merged after 22.2.2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FreekMencke added a commit to FreekMencke/freek-mencke-web that referenced this pull request Oct 14, 2026
Ran `ng update @angular/cli --name migrate-karma-to-vitest`, which
switches `ng test` to the unit-test builder with Vitest 5. Removed the
Karma and Jasmine packages and their VS Code launch entry, and added
jsdom.

As in osrs-tracker-web, vitest-base.config.ts turns off Vitest 5's
module cache, which reran a stale bundle after a change to the tested
code alone (angular/angular-cli#34311, not released in 22.2.2).

Adds a first spec (MenuButtonComponent) and runs `npm test` in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FreekMencke added a commit to FreekMencke/freek-mencke-web that referenced this pull request Oct 14, 2026
* test: migrate from Karma to Vitest

Ran `ng update @angular/cli --name migrate-karma-to-vitest`, which
switches `ng test` to the unit-test builder with Vitest 5. Removed the
Karma and Jasmine packages and their VS Code launch entry, and added
jsdom.

As in osrs-tracker-web, vitest-base.config.ts turns off Vitest 5's
module cache, which reran a stale bundle after a change to the tested
code alone (angular/angular-cli#34311, not released in 22.2.2).

Adds a first spec (MenuButtonComponent) and runs `npm test` in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: align the Vitest setup with osrs-tracker-web

Build the tests from `::development` instead of the migration's own
`testing` configuration and leave `runner` and `tsConfig` at their
defaults, run them in their own CI job, and remove the VS Code settings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
FreekMencke added a commit to FreekMencke/freek-mencke-web that referenced this pull request Oct 18, 2026
…he workaround (#26)

@angular/build 22.2.3 turns fsModuleCache off itself (angular/angular-cli#34311), so
vitest-base.config.ts, runnerConfig in angular.json and the knip entry go.

Closes #19

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants