-
Notifications
You must be signed in to change notification settings - Fork 4.9k
test: vitest更新 #18646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: vitest更新 #18646
Conversation
演练该拉取请求更新了多个包中的Vitest和Vite依赖版本,调整了Vitest配置以支持新版本,更新了测试脚本命令,并从测试模拟文件中移除了一个不再使用的组件属性。 变更
预计代码审查工作量🎯 2 (Simple) | ⏱️ ~12 分钟
可能相关的PR
建议的审查者
诗
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (1)
packages/taro/package.json(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ianzone
Repo: NervJS/taro PR: 18146
File: packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json:12-14
Timestamp: 2025-08-08T02:32:58.265Z
Learning: 在 Taro 项目的 pnpm 工作区中,Vitest 相关依赖(vitest 和 vitest/coverage-istanbul)被管理在根目录的 package.json 中,而不是各个子包的 devDependencies 中。这是 monorepo 中依赖提升的标准做法。
📚 Learning: 2025-08-08T02:32:58.265Z
Learnt from: ianzone
Repo: NervJS/taro PR: 18146
File: packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json:12-14
Timestamp: 2025-08-08T02:32:58.265Z
Learning: 在 Taro 项目的 pnpm 工作区中,Vitest 相关依赖(vitest 和 vitest/coverage-istanbul)被管理在根目录的 package.json 中,而不是各个子包的 devDependencies 中。这是 monorepo 中依赖提升的标准做法。
Applied to files:
packages/taro/package.json
📚 Learning: 2025-09-05T18:40:45.775Z
Learnt from: ianzone
Repo: NervJS/taro PR: 18150
File: packages/taro-platform-harmony-hybrid/package.json:43-45
Timestamp: 2025-09-05T18:40:45.775Z
Learning: 在 tarojs/plugin-platform-harmony-hybrid 包中,tarojs/components-library-react、tarojs/components-library-solid 和 tarojs/components-library-vue3 必须作为直接依赖(dependencies)而不能作为 peer 依赖,因为插件源码中有对这些包的直接引用,包括 componentAdapter* getter 方法和 webpack 别名配置。
Applied to files:
packages/taro/package.json
🔇 Additional comments (1)
packages/taro/package.json (1)
39-40: packages/taro 应在 peerDependencies 中声明 vite,并解决版本不一致。根据验证,packages/taro 的类型定义中大量使用了 vite 类型(如
ViteServerOptions),且该包被下游应用依赖。vite 仅作为 devDependency 是不足的,应同时添加到 peerDependencies 中,以确保下游应用知道需要提供此依赖。此外,packages/taro 中的 vite ^4.2.0(2023 年版本)与根目录 package.json 中的 ^7.2.4 存在重大版本差异,可能导致类型不匹配或编译问题。建议:
- 将 vite 添加到 packages/taro 的 peerDependencies(例如
"vite": "^4.2.0")- 协调 vite 版本,确保与根目录或其他子包保持一致,或明确说明为何需要特定版本
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
package.json(2 hunks)packages/taro-framework-vue3/vitest.config.ts(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/taro-framework-vue3/vitest.config.ts
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-08T02:32:58.265Z
Learnt from: ianzone
Repo: NervJS/taro PR: 18146
File: packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json:12-14
Timestamp: 2025-08-08T02:32:58.265Z
Learning: 在 Taro 项目的 pnpm 工作区中,Vitest 相关依赖(vitest 和 vitest/coverage-istanbul)被管理在根目录的 package.json 中,而不是各个子包的 devDependencies 中。这是 monorepo 中依赖提升的标准做法。
Applied to files:
package.json
📚 Learning: 2025-11-21T07:15:22.626Z
Learnt from: ianzone
Repo: NervJS/taro PR: 18646
File: packages/taro/package.json:40-40
Timestamp: 2025-11-21T07:15:22.626Z
Learning: 在 tarojs/taro 包中添加 vite 作为 devDependency 是为了让 tarojs/vite-runner 能够依赖正确的 vite 类型版本,确保 monorepo 中的类型兼容性。
Applied to files:
package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
- GitHub Check: Build Rust WASM / stable - wasm32-wasi
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
🔇 Additional comments (1)
package.json (1)
167-168: Vite 版本跨度过大,导致 monorepo 中类型和 API 不兼容根目录 package.json 第 167 行的
"vite": "^7.2.4"与 monorepo 中所有其他 packages 的"vite": "^4.2.0"存在主版本差异。Vite 4 到 7 存在重大破坏性变更,这将导致:
- 类型定义冲突(packages/taro-vite-runner 特别需要与根 vite 版本一致)
- API 不兼容
- 插件和配置不适配
需要同步更新以下文件中的 Vite 版本:
packages/taro/package.jsonpackages/taro-framework-react/package.jsonpackages/taro-framework-solid/package.jsonpackages/taro-framework-vue3/package.jsonpackages/taro-platform-harmony-cpp/package.jsonpackages/taro-vite-runner/package.json⛔ Skipped due to learnings
Learnt from: ianzone Repo: NervJS/taro PR: 18646 File: packages/taro/package.json:40-40 Timestamp: 2025-11-21T07:15:22.634Z Learning: 在 tarojs/taro 包中添加 vite 作为 devDependency 是为了让 tarojs/vite-runner 能够依赖正确的 vite 类型版本,确保 monorepo 中的类型兼容性。Learnt from: ianzone Repo: NervJS/taro PR: 18146 File: packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json:12-14 Timestamp: 2025-08-08T02:32:58.265Z Learning: 在 Taro 项目的 pnpm 工作区中,Vitest 相关依赖(vitest 和 vitest/coverage-istanbul)被管理在根目录的 package.json 中,而不是各个子包的 devDependencies 中。这是 monorepo 中依赖提升的标准做法。Learnt from: ianzone Repo: NervJS/taro PR: 18150 File: packages/taro-platform-harmony-hybrid/package.json:43-45 Timestamp: 2025-09-05T18:40:45.775Z Learning: 在 tarojs/plugin-platform-harmony-hybrid 包中,tarojs/components-library-react、tarojs/components-library-solid 和 tarojs/components-library-vue3 必须作为直接依赖(dependencies)而不能作为 peer 依赖,因为插件源码中有对这些包的直接引用,包括 componentAdapter* getter 方法和 webpack 别名配置。
| "@typescript-eslint/eslint-plugin": "^7.8.0", | ||
| "@typescript-eslint/parser": "^7.8.0", | ||
| "@vitest/coverage-istanbul": "^3.2.4", | ||
| "@vitest/coverage-istanbul": "^4.0.13", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
PR 目标与实现不一致:应使用 v8 而非 istanbul
PR 目标声称"用新的 v8 reporter 替换现有的 istanbul",但该行仍保留 @vitest/coverage-istanbul。Vitest 4 默认使用 v8 作为覆盖率提供者,建议将依赖从 @vitest/coverage-istanbul 改为 @vitest/coverage-v8 以达成 PR 目标。V8 已采用基于 AST 的覆盖率重新映射,提供与 Istanbul 相同的准确性,同时保持 V8 的速度优势。
请验证:
- 此变更是否意在完全迁移到 v8(应替换 istanbul 包)或仅更新 istanbul 包版本
- 项目中的 vitest.config 文件是否已更新为
provider: 'v8'(如已在其他 PR 文件中修改) - 若确实迁移到 v8,请应用以下修改:
- "@vitest/coverage-istanbul": "^4.0.13",
+ "@vitest/coverage-v8": "^4.0.13",
---
🏁 Script executed:
```shell
#!/bin/bash
# 查找 vitest.config 文件
find . -type f -name "vitest.config.*" 2>/dev/null | head -20
Length of output: 511
🏁 Script executed:
#!/bin/bash
# 检查 packages/taro 目录中的 vite 版本
if [ -f "packages/taro/package.json" ]; then
cat "packages/taro/package.json" | grep -A2 -B2 '"vite"'
fiLength of output: 111
🏁 Script executed:
#!/bin/bash
# 搜索 coverage provider 相关配置
rg -i "provider.*coverage|coverage.*provider" --type=js --type=ts -C3 2>/dev/null | head -30Length of output: 0
🏁 Script executed:
#!/bin/bash
# 查看根目录 package.json 中的 devDependencies 覆盖率相关包
grep -A50 '"devDependencies"' package.json | grep -E "coverage|vitest"Length of output: 43
🌐 Web query:
Vitest 4 coverage provider v8 vs istanbul differences
💡 Result:
Short summary — key differences between Vitest's v8 and istanbul coverage providers:
-
How they collect coverage
- v8: native V8 engine profiler (node:inspector / CDP) at runtime — no source instrumentation. [1][2]
- istanbul: instrumentation-based (instrument code before/while running) using Istanbul tooling. [1]
-
Performance and resource use
- v8: generally faster and lower memory (no instrumentation step). Can be slower in some scenarios (many modules). [1]
- istanbul: usually slower and higher memory due to instrumentation, but can be faster for some workloads. [1]
-
Accuracy / remapping
- v8: Vitest uses AST-based remapping (since v3.2.0 / improved in v4) to produce coverage equivalent to Istanbul for most cases. [3][1]
- istanbul: produces coverage from instrumented sources (classic Istanbul reports). [1]
-
Environment support / limitations
- v8: requires a V8-based runtime (Node, Chrome, Deno). Not supported in non‑V8 runtimes (e.g., Firefox, Bun in some cases) or environments that don’t expose V8 profiler. V8 also cannot limit coverage to specific modules (engine limitation). [1]
- istanbul: works broadly (non‑V8 runtimes too) because it relies on instrumentation rather than the engine API. [1]
-
Configuration / UX
- v8: default provider in Vitest; no pre‑transpile/instrument step; Vitest will prompt to install @vitest/coverage-v8. [1][4]
- istanbul: opt‑in via provider setting; requires @vitest/coverage-istanbul if chosen. [1][4]
-
Small behavioral diffs / migration notes (Vitest 4)
- V8 remapping logic was improved in Vitest 4 (AST-based) so v8 reports match Istanbul more closely; some ignore/hint handling changed and certain options (e.g., coverage.ignoreEmptyLines) were removed/updated. Expect differences when upgrading. [3]
Sources: Vitest docs — Coverage guide and Config (v8 vs istanbul, provider defaults, limitations) and the Vitest migration notes about V8 remapping. [1][2][3]
References
[1] Vitest — Coverage guide.
[2] Vitest — Config › coverage.provider.
[3] Vitest — Migration notes (V8 coverage changes).
🌐 Web query:
@vitest/coverage-v8 package version 4.0.13
💡 Result:
Yes — @vitest/coverage-v8 v4.0.13 is available. Install with:
npm:
npm install -D @vitest/[email protected]
yarn:
yarn add -D @vitest/[email protected]
Changelog highlights for 4.0.13 (bug fixes and performance tweaks) are listed in the release notes. [1][2]
Sources:
[1] Snyk package page showing latest version 4.0.13.
[2] Release notes / changelog entry for v4.0.13.
---
🏁 Script executed:
```shell
#!/bin/bash
# 查看根目录 vitest.config.ts
cat ./vitest.config.ts
Length of output: 139
🏁 Script executed:
#!/bin/bash
# 查看 packages/taro/package.json 中 vitest 版本
grep -A1 -B1 '"vitest"' packages/taro/package.jsonLength of output: 0
🏁 Script executed:
#!/bin/bash
# 在 vitest.config 文件中搜索 coverage 相关配置(更宽泛的搜索)
grep -r "coverage\|provider" . --include="vitest.config.*" 2>/dev/null | grep -v node_modulesLength of output: 1431
🏁 Script executed:
#!/bin/bash
# 检查 PR 中是否添加了 @vitest/coverage-v8
grep -E "coverage-v8|coverage-istanbul" package.jsonLength of output: 43
PR 目标与实现严重不符:覆盖率提供者迁移未完成
PR 声称"用新的 v8 reporter 替换现有的 istanbul",但实际代码中:
- package.json:仅更新
@vitest/coverage-istanbul到 ^4.0.13,未添加@vitest/coverage-v8 - 所有 vitest.config 文件(packages/*/vitest.config.ts):10 个包的 coverage provider 仍配置为
'istanbul',未改为'v8'
若要完成迁移到 v8,需要:
# package.json
- "@vitest/coverage-istanbul": "^4.0.13",
+ "@vitest/coverage-v8": "^4.0.13",# packages/*/vitest.config.ts(所有 10 个包)
coverage: {
- provider: 'istanbul',
+ provider: 'v8',次要问题:Vite 版本不一致——根目录 ^7.2.4 vs packages/taro ^4.2.0(跨主版本),建议统一版本并验证兼容性。
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In package.json around line 112, the PR only bumped @vitest/coverage-istanbul
but did not add the new v8 reporter and did not update vitest configs; add the
dependency @vitest/coverage-v8 at a compatible version, remove or deprecate
@vitest/coverage-istanbul if no longer used, then update all
packages/*/vitest.config.ts files to set coverage.provider = 'v8' (replace
'istanbul') and run tests to verify reports; additionally reconcile Vite
versions by aligning root package.json and packages/taro to the same major
version (e.g., both ^7.x or both ^4.x) and test for compatibility before
finalizing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v8与node18不兼容,已更改PR目标
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
这个 PR 做了什么? (简要描述所做更改)
新的v8报告器提供了与istanbul相同的准确度及更快的速度,故改用v8。v8报告器与 node18不兼容,暂时保持Istanbul这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.