GeezerVison is showing github.com — fix: invalidate Jest transform cache when inputs change by nrps9909 · Pull Request #297 · ant-design/antd-tools
Conversation
nrps9909
commented
Sep 5, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
The Jest code preprocessor currently returns the same cache key for every file and source revision at a given tools version and LIB_DIR. With caching enabled, a second Jest run can execute stale code after a file changes; different files with the same basename can also share transformed output.
This change incorporates Babel-Jest's cache key, using the same Babel configuration and filename normalization as process, while retaining the tools-version and LIB_DIR salts and the original source path.
The new integration regression runs Jest twice against the same cache, changes a module from exporting 1 to 2, and verifies that the second run reads 2. On the original code it reads 1. Additional regressions cover source text, same-basename paths, Jest configuration and instrumentation, plus stable keys for unchanged inputs.
Validation:
- Original implementation: five new regressions fail, including the two-process stale-source reproduction.
- Patched implementation: full suite passes (2 suites, 7 tests).
npm run compile, npm run lint, tsc --noEmit, targeted Prettier and git diff --check pass.
- Consumer verification: Ant Design's complete Checkbox suite passes twice with caching enabled using this transformer (9 suites, 78 tests including 4 independent review probes, 37 snapshots on each run).
Summary by CodeRabbit
-
Bug Fixes
- 修复 Jest 代码转换缓存未能准确反映源文件、文件路径、配置或插桩选项变化的问题。
- 修改源文件后,测试运行可正确加载最新内容,避免使用过期缓存。
-
Tests
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Sep 5, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Team
Run ID: 1045980b-edf0-4564-8843-a17692a6058d
📥 Commits
Reviewing files that changed from the base of the PR and between 967174e and db0cb6d.
📒 Files selected for processing (2)
src/jest/codePreprocessor.ts
tests/codePreprocessor.test.js
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.
📝 Walkthrough
Walkthrough
Jest 预处理器提取统一的转换器构建逻辑。缓存键现在包含转换器缓存键和文件路径。新增测试覆盖缓存键失效及缓存目录复用场景。
Changes
Jest 预处理器缓存流程
| Layer / File(s) |
Summary |
转换器构建与缓存键生成 src/jest/codePreprocessor.ts |
新增 CacheKey 类型和 getTransformer 辅助函数。process 和 getCacheKey 共用转换器构建逻辑。缓存键现在包含转换器缓存键、文件名和文件路径。 |
缓存失效与缓存复用验证 tests/codePreprocessor.test.js |
测试验证相同输入生成相同缓存键。源代码、路径、Jest 配置或插桩选项变化时,缓存键会失效。端到端测试验证复用缓存目录后加载修改后的源文件。 |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Merge Risk: ⚪ Minimal · up to db0cb
This updates Jest transform cache invalidation so changed source, paths, and transform settings produce fresh output while unchanged inputs retain stable keys. The included regression coverage supports merge readiness.
Sequence Diagram(s)
sequenceDiagram
participant Jest
participant Preprocessor
participant getTransformer
participant BabelTransformer
Jest->>Preprocessor: process(src, filePath, options)
Preprocessor->>getTransformer: 构建转换器和规范化文件名
getTransformer-->>Preprocessor: transformer, filename
Preprocessor->>BabelTransformer: transform(src, filename, options)
BabelTransformer-->>Jest: 转换后的代码
Jest->>Preprocessor: getCacheKey(src, filePath, options)
Preprocessor->>BabelTransformer: getCacheKey(src, filename, options)
BabelTransformer-->>Preprocessor: transformer cache key
Preprocessor-->>Jest: MD5(cache key + filePath)
Loading
Poem
小兔携来缓存钥匙亮,
源码变动,旧影不再藏。
路径配置同入签名,
Babel 轻跳换新装。
两次运行皆读新光。
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
⚠️ Warning |
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. |
Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
标题“fix: invalidate Jest transform cache when inputs change”准确概括了本次变更的主要目的:当转换输入发生变化时,使 Jest 转换缓存失效。标题简洁、具体,并与代码和测试变更一致。 |
| Linked Issues check |
✅ Passed |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
✅ Passed |
Check skipped because no linked issues were found for this pull request. |
- Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Warning Some tools did not complete. Review the errors below.
🔧 ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
tests/codePreprocessor.test.js
Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): tests/codePreprocessor.test.js
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|