test(babel-plugin-transform-taroapi): jest to vitest#18214
test(babel-plugin-transform-taroapi): jest to vitest#18214yoyo837 merged 4 commits intoNervJS:mainfrom
Conversation
Walkthrough在 packages/babel-plugin-transform-taroapi 内,将测试框架从 Jest 迁移至 Vitest:更新 package.json 脚本,新增 vitest.config.ts;在测试文件中显式导入 Vitest API。删除 Jest、Babel 测试相关配置与测试专用 tsconfig,并调整一个 post-build 脚本中的目标 mock 文件路径。 Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as 开发者
participant NPM as NPM Scripts
participant Vitest as Vitest
participant Config as vitest.config.ts
participant Tests as tests/**/*.spec.ts?(x)
participant Src as src/**/*.ts (coverage)
Dev->>NPM: 运行 test / test:ci / test:dev
NPM->>Vitest: 调用 Vitest
Vitest->>Config: 加载配置
Vitest->>Tests: 发现并执行测试用例
Vitest->>Src: 收集覆盖率
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/babel-plugin-transform-taroapi/vitest.config.ts (1)
1-12: Vitest 配置基本到位;建议显式指定运行环境与覆盖率报告器
当前配置已能匹配测试并启用 Istanbul 覆盖率。为提升可读性和 CI 一致性,建议:
- 显式设置 environment: 'node'(虽为默认,但写清更不易踩坑)。
- 为覆盖率添加常用 reporter(如 lcov、json-summary、text),方便 CI 上报与本地查看。
可以在此处直接修改为:
export default defineConfig({ test: { + environment: 'node', + globals: false, include: ['tests/**/*.spec.ts?(x)'], coverage: { provider: 'istanbul', - include: ['src/**/*.ts'], + include: ['src/**/*.ts'], + reporter: ['text', 'json-summary', 'lcov'] } } })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (3)
packages/babel-plugin-transform-taroapi/__tests__/__snapshots__/index.spec.ts.snapis excluded by!**/*.snappackages/babel-plugin-transform-taroapi/tests/__snapshots__/harmony.spec.ts.snapis excluded by!**/*.snappackages/babel-plugin-transform-taroapi/tests/__snapshots__/index.spec.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (7)
packages/babel-plugin-transform-taroapi/babel.config.json(0 hunks)packages/babel-plugin-transform-taroapi/jest.config.ts(0 hunks)packages/babel-plugin-transform-taroapi/package.json(1 hunks)packages/babel-plugin-transform-taroapi/tests/harmony.spec.ts(1 hunks)packages/babel-plugin-transform-taroapi/tests/index.spec.ts(1 hunks)packages/babel-plugin-transform-taroapi/tsconfig.test.json(0 hunks)packages/babel-plugin-transform-taroapi/vitest.config.ts(1 hunks)
💤 Files with no reviewable changes (3)
- packages/babel-plugin-transform-taroapi/babel.config.json
- packages/babel-plugin-transform-taroapi/tsconfig.test.json
- packages/babel-plugin-transform-taroapi/jest.config.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ianzone
PR: NervJS/taro#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
PR: NervJS/taro#17842
File: packages/jest-helper/tsconfig.json:9-9
Timestamp: 2025-06-23T00:09:31.233Z
Learning: 在 jest-helper 包中,src 目录下没有 __tests__ 测试目录,只包含 resolver.ts、sequencer.ts 和 snapshot 目录。不要假设包中存在测试目录结构。
📚 Learning: 2025-08-08T02:32:58.265Z
Learnt from: ianzone
PR: NervJS/taro#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/babel-plugin-transform-taroapi/tests/harmony.spec.tspackages/babel-plugin-transform-taroapi/tests/index.spec.tspackages/babel-plugin-transform-taroapi/vitest.config.tspackages/babel-plugin-transform-taroapi/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 - x86_64-unknown-linux-gnu
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust WASM / stable - wasm32-wasi
🔇 Additional comments (3)
packages/babel-plugin-transform-taroapi/tests/harmony.spec.ts (1)
3-3: 显式导入 Vitest API,迁移姿势正确
在测试内直接从 vitest 导入 describe/expect/test,去掉对全局的假设,更稳健。packages/babel-plugin-transform-taroapi/tests/index.spec.ts (1)
3-3: 显式导入 Vitest API,保持与仓库迁移策略一致
与其他子包的做法一致,去除了对全局测试 API 的依赖,可继续沿用原有断言(如 toMatchSnapshot/toThrowError)。packages/babel-plugin-transform-taroapi/package.json (1)
12-15: 测试脚本迁移完成 — 无残留的 Jest 依赖
已在 packages/babel-plugin-transform-taroapi 中验证:
- 未发现任何 jest.fn/spyOn/mock 等 API 或 from 'jest' 导入
- 所有 *.spec.ts(x) 测试文件均已显式从 vitest 导入
- 未找到 jest.config.*、babel.config.json 或 tsconfig.test.json 等旧配置文件
包内已完全切换至 Vitest,无需额外清理或自检。
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
packages/taro-platform-h5/scripts/post-build.mjs (4)
9-9: 跨平台路径分隔符小优化同样建议把
'dist/definition.json'拆分为两个段,避免在 Windows 下混用分隔符。-const sourceFileDist = resolve(__dirname, '..', 'dist/definition.json') +const sourceFileDist = resolve(__dirname, '..', 'dist', 'definition.json')
2-2: 确保目标目录存在,避免写入失败(在目录缺失时)如果
packages/babel-plugin-transform-taroapi/tests/__mocks__尚未创建,writeFileSync会抛错。可在写入前递归创建目标目录,增强鲁棒性。在行 2 增加
mkdirSync引入:-import { readFileSync, writeFileSync } from 'fs' +import { readFileSync, writeFileSync, mkdirSync } from 'fs'在写入前创建目录:
- // 写入目标文件 - writeFileSync(targetFile, sourceContent, 'utf8') + // 确保目标目录存在 + mkdirSync(dirname(targetFile), { recursive: true }) + // 写入目标文件 + writeFileSync(targetFile, sourceContent, 'utf8')Also applies to: 17-18
22-24: 错误日志建议打印堆栈,便于排查仅输出
error.message可能不足以追踪问题来源,建议优先输出error.stack。- console.error('❌ 脚本执行失败:', error.message) + console.error('❌ 脚本执行失败:', error.stack || error)
11-11: 优化路径拼接以提高跨平台稳健性
核验结果:
- 未发现旧的
__tests__/__mocks__/h5-definition.json引用packages/babel-plugin-transform-taroapi/tests/__mocks__目录已存在,且包含h5-definition.json建议将
resolve的路径参数拆分,以避免在 Windows 下分隔符混用带来的潜在问题:- const targetFile = resolve(__dirname, '../..', 'babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json') + const targetFile = resolve( + __dirname, + '../..', + 'babel-plugin-transform-taroapi', + 'tests', + '__mocks__', + 'h5-definition.json' + )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/taro-platform-h5/scripts/post-build.mjs(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ianzone
PR: NervJS/taro#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
PR: NervJS/taro#17842
File: packages/jest-helper/tsconfig.json:9-9
Timestamp: 2025-06-23T00:09:31.233Z
Learning: 在 jest-helper 包中,src 目录下没有 __tests__ 测试目录,只包含 resolver.ts、sequencer.ts 和 snapshot 目录。不要假设包中存在测试目录结构。
📚 Learning: 2025-06-23T00:09:31.233Z
Learnt from: ianzone
PR: NervJS/taro#17842
File: packages/jest-helper/tsconfig.json:9-9
Timestamp: 2025-06-23T00:09:31.233Z
Learning: 在 jest-helper 包中,src 目录下没有 __tests__ 测试目录,只包含 resolver.ts、sequencer.ts 和 snapshot 目录。不要假设包中存在测试目录结构。
Applied to files:
packages/taro-platform-h5/scripts/post-build.mjs
⏰ 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). (6)
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
- GitHub Check: Build Rust WASM / stable - wasm32-wasi
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #18214 +/- ##
==========================================
- Coverage 55.07% 55.07% -0.01%
==========================================
Files 416 416
Lines 21561 21559 -2
Branches 5301 5286 -15
==========================================
- Hits 11875 11873 -2
+ Misses 8035 8030 -5
- Partials 1651 1656 +5
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
这个 PR 做了什么? (简要描述所做更改)
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit