Skip to content

test(babel-plugin-transform-taroapi): jest to vitest#18214

Merged
yoyo837 merged 4 commits intoNervJS:mainfrom
ianzone:babel-plugin-transform-taroapi
Aug 25, 2025
Merged

test(babel-plugin-transform-taroapi): jest to vitest#18214
yoyo837 merged 4 commits intoNervJS:mainfrom
ianzone:babel-plugin-transform-taroapi

Conversation

@ianzone
Copy link
Copy Markdown
Contributor

@ianzone ianzone commented Aug 18, 2025

这个 PR 做了什么? (简要描述所做更改)

这个 PR 是什么类型? (至少选择一个)

  • 错误修复 (Bugfix) issue: fix #
  • 新功能 (Feature)
  • 代码重构 (Refactor)
  • TypeScript 类型定义修改 (Types)
  • 文档修改 (Docs)
  • 代码风格更新 (Code style update)
  • 构建优化 (Chore)
  • 其他,请描述 (Other, please describe):

这个 PR 涉及以下平台:

  • 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 钉钉小程序
  • QQ 小程序
  • 飞书小程序
  • 快手小程序
  • 头条小程序

Summary by CodeRabbit

  • 测试
    • 将测试框架从 Jest 迁移至 Vitest,更新相关脚本(本地/CI/快照)
    • 新增 Vitest 配置并在用例中显式引入 Vitest API
  • 杂务
    • 移除旧的 Jest/Babel/测试专用配置文件
    • 调整构建后脚本中测试资源路径
  • 其他
    • 无用户可见功能变更

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 18, 2025

Walkthrough

在 packages/babel-plugin-transform-taroapi 内,将测试框架从 Jest 迁移至 Vitest:更新 package.json 脚本,新增 vitest.config.ts;在测试文件中显式导入 Vitest API。删除 Jest、Babel 测试相关配置与测试专用 tsconfig,并调整一个 post-build 脚本中的目标 mock 文件路径。

Changes

Cohort / File(s) Summary of Changes
测试脚本迁移至 Vitest
packages/babel-plugin-transform-taroapi/package.json
将 test / test:ci / test:dev / updateSnapshot 脚本从 Jest(含 cross-env NODE_ENV=jest)改为 Vitest(如 vitest runvitest run --coveragevitestvitest run --updateSnapshot);移除 test:coverage 脚本。
移除 Jest 与 Babel 测试配置
packages/babel-plugin-transform-taroapi/jest.config.ts, packages/babel-plugin-transform-taroapi/babel.config.json, packages/babel-plugin-transform-taroapi/tsconfig.test.json
完全删除 Jest 配置、用于测试的 Babel 配置文件与测试专用 tsconfig(含 allowJs 扩展)。注意:jest.config.ts 的默认导出被移除。
新增 Vitest 配置
packages/babel-plugin-transform-taroapi/vitest.config.ts
新增 Vitest 配置并默认导出:包含测试匹配模式 tests/**/*.spec.ts?(x),开启覆盖率(Istanbul),coverage 源仅限 src/**/*.ts
测试文件适配 Vitest
packages/babel-plugin-transform-taroapi/tests/harmony.spec.ts, packages/babel-plugin-transform-taroapi/tests/index.spec.ts
在测试文件顶部显式添加 import { describe, expect, test } from 'vitest',不修改测试逻辑。
post-build 脚本路径修正
packages/taro-platform-h5/scripts/post-build.mjs
修改目标写入文件路径:从 babel-plugin-transform-taroapi/__tests__/__mocks__/h5-definition.json 变更为 babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json

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: 收集覆盖率
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • luckyadam
  • yoyo837
  • tutuxxx

Poem

我是小兔提壳来,换上 Vitest 跑得快。
脚本一改路径也换牌,测试轻跳月下徘徊。
代码整洁心里哼,快跑快测乐开怀。 🐰✨

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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.

📥 Commits

Reviewing files that changed from the base of the PR and between b3127a8 and 9496f65.

⛔ Files ignored due to path filters (3)
  • packages/babel-plugin-transform-taroapi/__tests__/__snapshots__/index.spec.ts.snap is excluded by !**/*.snap
  • packages/babel-plugin-transform-taroapi/tests/__snapshots__/harmony.spec.ts.snap is excluded by !**/*.snap
  • packages/babel-plugin-transform-taroapi/tests/__snapshots__/index.spec.ts.snap is 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.ts
  • packages/babel-plugin-transform-taroapi/tests/index.spec.ts
  • packages/babel-plugin-transform-taroapi/vitest.config.ts
  • packages/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,无需额外清理或自检。

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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: 优化路径拼接以提高跨平台稳健性

  • 核验结果:

    1. 未发现旧的 __tests__/__mocks__/h5-definition.json 引用
    2. 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 9496f65 and 495b4c7.

📒 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
Copy link
Copy Markdown

codecov Bot commented Aug 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.07%. Comparing base (a6bfe71) to head (3b2ceff).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
taro-cli 72.85% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 53.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This was referenced Aug 23, 2025
@yoyo837 yoyo837 merged commit d962619 into NervJS:main Aug 25, 2025
24 checks passed
@ianzone ianzone deleted the babel-plugin-transform-taroapi branch August 25, 2025 05:25
This was referenced Aug 30, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Nov 21, 2025
27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants