unit-test builder (Vitest): key `fsModuleCache` on the served build output instead of forcing it off
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 20/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- angular, typescript
- 领域
- build-system, testing
调研方向
Start in the angular:test-in-memory-provider plugin’s configureVitest hook and inspect how buildResultFiles are served and hashed. Check the unit-test builder configuration that forces fsModuleCache off, then trace how the cache key can include the served output and source map hashes. Done means the cache can be enabled without stale results when an imported file changes; the issue reports a fix-ready linked pull request, #34444.
由索引模型根据 Issue 内容生成。
描述
Command
test
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
Since f0a74e8f0 (released in 22.2.3), @angular/build:unit-test forces fsModuleCache: false, at the root and on the test project, overriding the runnerConfig. The reason is sound: Vitest keys its file system module cache on the file found on disk, while a test entry point is served from its bundle, which also holds the application code the spec imports. Changing an imported file without touching the spec left the key unchanged, and the cache served a stale bundle.
Vitest provides a hook for exactly this case: a plugin can add its own part to the cache key with defineCacheKeyGenerator, from configureVitest. The angular:test-in-memory-provider plugin already implements configureVitest and holds buildResultFiles, the files its load() serves, each with a content hash. Keying the cache on the served build output (the output file hash plus its source map hash) removes the staleness at its root, so the cache does not need to be turned off.
Since #34337 (also in 22.2.3) the test bundles are byte-identical from one build to the next, so such a key is stable and the cache can be reused across runs and CI pipelines.
Measured on a workspace application with 255 spec files (warm Angular cache, macOS, runs alternated on an idle machine), the builder patched as described:
| builder | Vitest duration | ng test wall time |
|---|---|---|
| 22.2.3 (cache forced off) | 21.4 s, 21.4 s | 36.6 s, 37.9 s |
patched, warm fsModuleCache |
20.0 s, 18.4 s | 35.8 s, 35.8 s |
The gain is modest here, since execution dominates this suite; it grows with the share of transform time. On the same workspace, changing a file imported by a spec (without touching the spec) makes that spec fail as expected, and reverting the change reuses the original cache entry.
I have a fix ready and will open a PR referencing this issue.
Minimal Reproduction
- In a project using
@angular/build:unit-testwith Vitest 5, setfsModuleCache: trueandfsModuleCachePath: './.vitest-cache'in therunnerConfig. - Run
ng test --no-watch. - No
.vitest-cachedirectory is created: the builder overrides the option.
Exception or Error
No response
Your Environment
Angular CLI : 22.2.3
Angular : 22.2.3
Node.js : 24.21.0
Package Manager : npm 11.19.0
Operating System : darwin arm64
@angular/build : 22.2.3
vitest : 5.0.4
Anything else relevant?
Follow-up of #34335 / #34337 (deterministic test discovery) and of f0a74e8f0 (fsModuleCache disabled to avoid stale bundles).
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 11.8k
- 平均合并
- 1 天 5 小时
- 30 天内合并 PR
- 244
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
angular/angular-cli 的其他 Issue
-
area: @angular/build gemini-triaged
难度 2/5 1-3 小时 新手友好度 74/100
angular/angular-cli#33955 ·
维护者通常 1 天内回复
-
area: @angular/cli gemini-triaged
难度 2/5 1-3 小时 新手友好度 72/100
angular/angular-cli#33055 · 1 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
-
Angular SSR Unescaped prerender parameters enable RCE through generated manifests and XSS in redirect pages可能已有人在做 @SkyZeroZx 于 151 天前认领。 未关闭area: @angular/ssr
难度 4/5 3-5 天 新手友好度 53/100
angular/angular-cli#34474 ·
维护者通常 1 天内回复
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configured可能已有人在做 @MeAkib 于 1 天前认领。 未关闭area: @schematics/angular
难度 3/5 1-2 天 新手友好度 35/100
angular/angular-cli#34449 ·
维护者通常 1 天内回复
-
Tailwind CSS v4 classes in new or moved files are not picked up by ng serve until another rebuild可能已有人在做 @MeAkib 于 3 天前认领。 未关闭area: @angular/build
难度 4/5 3-5 天 新手友好度 35/100
angular/angular-cli#34446 ·
维护者通常 1 天内回复
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
level/task type/bug
难度 2/5 1-3 小时 新手友好度 75/100
wazuh/wazuh-dashboard-plugins#9508 ·
维护者通常 1 天内回复
-
Testnet EOL page links Zonescan mainnet可能已有人在做 @napelvs 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 78/100
Azure-Samples/azure-search-openai-demo#3249 ·
维护者通常 1 天内回复
-
[Docs] docs/architecture.mermaid leaves out 21 of the 51 src/ directories可能已有人在做 @uyg7x 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
enhancement status:needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
dongdongbh/Mindwtr#1438 ·
维护者通常 1 天内回复