Skip to content

Conversation

@ianzone
Copy link
Contributor

@ianzone ianzone commented Aug 8, 2025

这个 PR 做了什么? (简要描述所做更改)
@tarojs/shared 测试重构

这个 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,包括相关配置文件的新增和删除,以及测试用例的语法替换。
  • 杂项
    • 更新测试脚本命令,现已采用 Vitest 运行测试。

@coderabbitai
Copy link

coderabbitai bot commented Aug 8, 2025

Walkthrough

本次变更将 @tarojs/shared 包的测试框架从 Jest 迁移至 Vitest。相关配置文件、测试脚本及测试用例均已适配 Vitest,移除了 Jest 相关内容,并新增了 Vitest 配置和代码覆盖率设置。

Changes

Cohort / File(s) Change Summary
Jest 配置文件移除
packages/shared/jest.config.js
删除了整个 Jest 配置文件,包括所有测试相关自定义设置。
测试脚本切换
packages/shared/package.json
test 脚本从 jest 切换为 vitest run,未涉及其他脚本或依赖变更。
测试用例适配 Vitest
packages/shared/tests/hooks.spec.ts, packages/shared/tests/shared.spec.ts
测试用例从 Jest API 切换为 Vitest API,调整了测试函数和 mock 的调用方式,未更改测试逻辑。
测试 TypeScript 配置移除
packages/shared/tsconfig.test.json
移除了专用于测试环境的 TypeScript 配置文件。
新增 Vitest 配置
packages/shared/vitest.config.ts
新增 Vitest 配置文件,指定测试文件匹配规则和代码覆盖率收集设置。

Sequence Diagram(s)

sequenceDiagram
    participant 开发者 as Developer
    participant Vitest
    participant 源码 as Source Files
    participant 覆盖率 as Coverage

    开发者->>Vitest: 运行测试 (vitest run)
    Vitest->>源码: 加载并执行 tests/**/*.spec.ts(x)
    Vitest->>覆盖率: 收集 src/**/*.ts 的覆盖率
    Vitest-->>开发者: 输出测试结果和覆盖率报告
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • tutuxxx
  • yoyo837

Poem

🐇
换装新衣 Vitest 来,
Jest 旧友轻轻拜。
测试脚本新语法,
覆盖报告更明快。
小兔敲键笑开怀,
代码质量步步高!

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

@coderabbitai coderabbitai bot requested review from tutuxxx and yoyo837 August 8, 2025 02:52
Copy link

@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: 3

🔭 Outside diff range comments (1)
packages/shared/tests/hooks.spec.ts (1)

59-61: toBeCalledTimes 同样需替换为 toHaveBeenCalledTimes
保持断言 API 与 Vitest 规范一致,可避免运行期错误。

-    expect(fnA).toBeCalledTimes(0)
+    expect(fnA).toHaveBeenCalledTimes(0)
🧹 Nitpick comments (1)
packages/shared/tests/shared.spec.ts (1)

5-7: 移除多余的 async 关键字
此测试用例并未使用 await,保留 async 会造成异步语义误导,建议去掉。

-  test('#indent', async () => {
+  test('#indent', () => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae19ce5 and bad1264.

📒 Files selected for processing (6)
  • packages/shared/jest.config.js (0 hunks)
  • packages/shared/package.json (1 hunks)
  • packages/shared/tests/hooks.spec.ts (8 hunks)
  • packages/shared/tests/shared.spec.ts (1 hunks)
  • packages/shared/tsconfig.test.json (0 hunks)
  • packages/shared/vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/shared/tsconfig.test.json
  • packages/shared/jest.config.js
🧰 Additional context used
🧠 Learnings (5)
📓 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.207Z
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 目录。不要假设包中存在测试目录结构。
Learnt from: ianzone
PR: NervJS/taro#17746
File: packages/taro-runtime/tsdown.config.ts:10-16
Timestamp: 2025-05-25T18:02:31.387Z
Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。
📚 Learning: 2025-08-08T02:32:58.207Z
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.207Z
Learning: 在 Taro 项目的 pnpm 工作区中,Vitest 相关依赖(vitest 和 vitest/coverage-istanbul)被管理在根目录的 package.json 中,而不是各个子包的 devDependencies 中。这是 monorepo 中依赖提升的标准做法。

Applied to files:

  • packages/shared/tests/shared.spec.ts
  • packages/shared/package.json
  • packages/shared/vitest.config.ts
  • packages/shared/tests/hooks.spec.ts
📚 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/shared/tests/shared.spec.ts
  • packages/shared/package.json
  • packages/shared/vitest.config.ts
  • packages/shared/tests/hooks.spec.ts
📚 Learning: 2025-05-25T18:02:31.387Z
Learnt from: ianzone
PR: NervJS/taro#17746
File: packages/taro-runtime/tsdown.config.ts:10-16
Timestamp: 2025-05-25T18:02:31.387Z
Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。

Applied to files:

  • packages/shared/package.json
  • packages/shared/tests/hooks.spec.ts
📚 Learning: 2025-07-22T09:16:21.180Z
Learnt from: ianzone
PR: NervJS/taro#18056
File: packages/taro-runtime/tsconfig.json:10-10
Timestamp: 2025-07-22T09:16:21.180Z
Learning: 在使用 rollup-plugin-dts 的项目中,rollup.config.ts 等构建配置文件会被自动排除,不需要在 tsconfig.json 中手动排除。

Applied to files:

  • packages/shared/vitest.config.ts
⏰ 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

@codecov
Copy link

codecov bot commented Aug 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.95%. Comparing base (bb41575) to head (2a395ef).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main   #18148    +/-   ##
========================================
  Coverage   54.95%   54.95%            
========================================
  Files         419      419            
  Lines       21750    21750            
  Branches     5337     5368    +31     
========================================
  Hits        11953    11953            
- Misses       8123     8241   +118     
+ Partials     1674     1556   -118     
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 43 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 9, 2025
@yoyo837 yoyo837 merged commit b3127a8 into NervJS:main Aug 13, 2025
24 of 25 checks passed
@ianzone ianzone deleted the shared branch August 13, 2025 02:03
This was referenced Aug 16, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 28, 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