Skip to content

test(babel-plugin-transform-solid-jsx): vitest#18607

Merged
yoyo837 merged 8 commits intoNervJS:mainfrom
ianzone:vitest
Dec 2, 2025
Merged

test(babel-plugin-transform-solid-jsx): vitest#18607
yoyo837 merged 8 commits intoNervJS:mainfrom
ianzone:vitest

Conversation

@ianzone
Copy link
Copy Markdown
Contributor

@ianzone ianzone commented Nov 11, 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

发布说明

  • Chores

    • 升级/新增构建与测试工具链(升级 Vitest、coverage 插件,新增/调整 Vite、Rollup 等开发依赖)。
  • Tests

    • 将测试框架从 Jest 迁移到 Vitest,移除旧的 Jest 配置并新增 Vitest 配置文件,更新测试脚本和覆盖率命令以适配 Vitest。
    • 若干测试文件迁移为 ES 模块格式,更新快照更新命令标记以配合 Vitest。

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 11, 2025

Walkthrough

将多个包的测试框架从 Jest 迁移到 Vitest:移除包级 Jest 配置、添加 Vitest 配置文件、更新测试脚本与测试文件为 ESM,并在仓根与若干包中新增或升级 Vite/Rollup/Vitest 相关依赖与脚本。

Changes

内聚组 / 文件(s) 变更摘要
仓根依赖变更
package.json
升级 devDependency @vitest/coverage-istanbulvitest 至 ^4.0.13;新增 vite ^7.2.4。
babel-plugin-transform-solid-jsx:删除 Jest 配置
packages/babel-plugin-transform-solid-jsx/jest.config.js
删除包级 Jest 配置文件(包含 moduleDirectories、testEnvironment、collectCoverageFrom、transform 等设置)。
babel-plugin-transform-solid-jsx:package.json 脚本更新
packages/babel-plugin-transform-solid-jsx/package.json
将测试相关脚本从 Jest 切换为 Vitest(test / test:ci / test:coverage 改为使用 vitest run 与对应参数)。
babel-plugin-transform-solid-jsx:新增 Vitest 配置
packages/babel-plugin-transform-solid-jsx/vitest.config.mts
新增并默认导出 Vitest 配置(启用 globals,coverage provider = istanbul,coverage include = src/**/*.js)。
babel-plugin-transform-solid-jsx:测试文件 ESM 化
packages/babel-plugin-transform-solid-jsx/test/unique-transform.spec.js
将 CommonJS require 改为 ESModule import,用 fileURLToPath(import.meta.url) 重建 __filename/__dirname,并调整 pluginTester 引用到 ../dist/index.js
taro 包依赖调整
packages/taro/package.json
在 devDependencies 中新增/调整 rollup ^3.29.4 与 vite ^4.2.0,并在 peerDependencies 保留/调整 rollup^3
babel-plugin-transform-taroapi:脚本调整
packages/babel-plugin-transform-taroapi/package.json
将 snapshot 更新脚本由 vitest run --updateSnapshot 改为 vitest run --update(Vitest 新标志)。
Vitest 配置发现扩展名
vitest.config.mts
将仓根/项目的 Vitest 配置引用/发现改为 .mts 扩展名(由 .ts -> .mts 的发现变更)。
新增更新快照脚本(单包)
packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json
新增 updateSnapshot: "vitest run --update" 脚本。

Sequence Diagram(s)

sequenceDiagram
  participant Dev as 开发者
  participant CLI as 包管理/脚本 (pnpm)
  participant Vitest as Vitest Runner
  participant Config as vitest.config.mts / 包级 vitest.config.mts
  participant TestFiles as 测试文件 (ESM)
  rect rgb(245,250,255)
    Dev->>CLI: 运行 `pnpm test` / `pnpm run test:ci`
    CLI->>Vitest: 启动 Vitest(读取 Config)
    Vitest->>Config: 加载全局与覆盖率配置
    Vitest->>TestFiles: 使用 ESM `import` 加载测试文件
    alt 覆盖率开启
      Vitest->>Vitest: 使用 istanbul 收集 coverage
    end
    TestFiles-->>Vitest: 返回测试结果
    Vitest->>CLI: 输出测试结果与覆盖率报告
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • 建议重点复核:
    • packages/babel-plugin-transform-solid-jsx/vitest.config.mts 的 coverage/include 与 globals 配置是否与原行为一致。
    • packages/babel-plugin-transform-solid-jsx/test/unique-transform.spec.js 中的 ../dist/index.js 路径与打包输出是否匹配。
    • 仓根与各包新增/升级的 vite/rollup/vitest 版本与 CI 配置、脚本兼容性。

Possibly related PRs

Suggested reviewers

  • luckyadam
  • yoyo837
  • tutuxxx

Poem

🐰 我在代码地里蹦跳换新装,
把 Jest 的旧帽交给春风,
Vitest 把歌声带进测试场,
ESM 起舞,脚本换名忙,
胡萝卜报表叮咚响。 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确反映了主要变更内容:将babel-plugin-transform-solid-jsx包的测试工具从Jest迁移到Vitest。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1299d28 and 35fa29e.

📒 Files selected for processing (5)
  • package.json (2 hunks)
  • packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json (1 hunks)
  • packages/babel-plugin-transform-solid-jsx/package.json (1 hunks)
  • packages/babel-plugin-transform-taroapi/package.json (1 hunks)
  • packages/taro/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • packages/taro/package.json
🧰 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 中依赖提升的标准做法。
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: 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-25T22:16:50.118Z
Learnt from: ianzone
Repo: NervJS/taro PR: 18150
File: packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json:2356-2356
Timestamp: 2025-08-25T22:16:50.118Z
Learning: The file `packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json` is auto-generated by the post-build script `packages/taro-platform-h5/scripts/post-build.mjs`, which copies content from `taro-platform-h5/dist/definition.json`. This file should not be manually edited.

Applied to files:

  • packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json
  • packages/babel-plugin-transform-solid-jsx/package.json
  • packages/babel-plugin-transform-taroapi/package.json
📚 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/babel-plugin-transform-solid-jsx/package.json
  • 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). (6)
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
🔇 Additional comments (3)
packages/babel-plugin-transform-taroapi/package.json (1)

15-15: ✅ Vitest 快照更新命令正确更新。

--updateSnapshot(Jest 风格)变更为 --update(Vitest 标准标志)是正确的。此脚本将允许开发者通过 pnpm run updateSnapshot 正确更新快照。与其他测试脚本(line 12-14)的 Vitest 用法保持一致。

packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/package.json (1)

14-14: ✓ 快照更新脚本添加正确。

新增的 updateSnapshot 脚本使用了正确的 Vitest 命令 vitest run --update 来更新快照,与现有的 testtest:ci 脚本保持一致,符合当前 Vitest 迁移的整体方向。

packages/babel-plugin-transform-solid-jsx/package.json (1)

25-27: 测试脚本迁移正确,无需修改。

Jest 到 Vitest 的脚本替换映射正确:

  • test:ci 现在运行 Vitest 并生成覆盖率报告,相当于 CI 模式
  • testtest:coverage 的逻辑对应合理

devDependencies 的设计也符合最佳实践(第 37-39 行):Vitest 及其覆盖率工具在根目录 package.json 中集中管理,避免重复,符合 monorepo 依赖提升规范。虽然原脚本显式设置 NODE_ENV=test,但 Vitest 在 run 命令下会自动设置此变量,所以移除 cross-env NODE_ENV=test 是安全的。PR 作者已验证迁移后测试通过。

Tip

✨ Issue Enrichment is now available for GitHub issues!

CodeRabbit can now help you manage issues more effectively:

  • Duplicate Detection — Identify similar or duplicate issues
  • Related Issues & PRs — Find relevant issues and PR's from your repository
  • Suggested Assignees — Find the best person to work on the issue
  • Implementation Planning — Generate detailed coding plans for engineers and agents
Disable automatic issue enrichment

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

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 and usage tips.

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2de8374 and 51ab1dc.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • package.json (1 hunks)
  • packages/babel-plugin-transform-solid-jsx/jest.config.js (0 hunks)
  • packages/babel-plugin-transform-solid-jsx/package.json (1 hunks)
  • packages/babel-plugin-transform-solid-jsx/test/unique-transform.spec.js (1 hunks)
  • packages/babel-plugin-transform-solid-jsx/vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/babel-plugin-transform-solid-jsx/jest.config.js
🧰 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 中依赖提升的标准做法。
Learnt from: ianzone
Repo: NervJS/taro PR: 18150
File: packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json:2356-2356
Timestamp: 2025-08-25T22:16:50.118Z
Learning: The file `packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json` is auto-generated by the post-build script `packages/taro-platform-h5/scripts/post-build.mjs`, which copies content from `taro-platform-h5/dist/definition.json`. This file should not be manually edited.
📚 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
  • packages/babel-plugin-transform-solid-jsx/package.json
  • packages/babel-plugin-transform-solid-jsx/vitest.config.ts
📚 Learning: 2025-08-25T22:16:50.118Z
Learnt from: ianzone
Repo: NervJS/taro PR: 18150
File: packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json:2356-2356
Timestamp: 2025-08-25T22:16:50.118Z
Learning: The file `packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json` is auto-generated by the post-build script `packages/taro-platform-h5/scripts/post-build.mjs`, which copies content from `taro-platform-h5/dist/definition.json`. This file should not be manually edited.

Applied to files:

  • packages/babel-plugin-transform-solid-jsx/package.json
  • packages/babel-plugin-transform-solid-jsx/vitest.config.ts
  • packages/babel-plugin-transform-solid-jsx/test/unique-transform.spec.js
🧬 Code graph analysis (1)
packages/babel-plugin-transform-solid-jsx/test/unique-transform.spec.js (1)
packages/babel-plugin-transform-solid-jsx/rollup.config.mjs (1)
  • __filename (6-6)
⏰ 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-apple-darwin
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • 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 WASM / stable - wasm32-wasi
🔇 Additional comments (3)
packages/babel-plugin-transform-solid-jsx/test/unique-transform.spec.js (1)

1-7: ESM 迁移实现正确

测试文件已正确从 CommonJS 迁移到 ESModule:

  • 使用 import 语法替代 require
  • 通过 fileURLToPath(import.meta.url) 正确实现了 ESM 环境下的 __filename__dirname polyfill
  • 导入路径使用了明确的 .js 扩展名,符合 ESM 规范

该实现模式与项目中其他文件(如 rollup.config.mjs)保持一致。

packages/babel-plugin-transform-solid-jsx/package.json (1)

25-27: 测试脚本已正确迁移到 Vitest

测试脚本从 Jest 迁移到 Vitest 的更改正确:

  • test:ci:从 jest --ci -i 改为 vitest run --coverage
  • test:从 jest --no-cache 改为 vitest run
  • test:coverage:从 jest --coverage --no-cache 改为 vitest run --coverage

符合项目的 monorepo 管理模式,Vitest 依赖在根目录管理。

packages/babel-plugin-transform-solid-jsx/vitest.config.ts (1)

1-13: 需要检查包的具体结构和文件内容,继续验证:

需要检查具体包的结构,执行脚本获取更多信息:

Based on my research, I've identified an issue with the original review comment. Vitest documentation shows that to include uncovered files in the report, you should configure coverage.include with a pattern that will pick your source files, typically using patterns like 'src/**/*.{ts,tsx}'.

The original review comment suggests changing include: ['index.js'] to include: ['dist/index.js'], but this contradicts Vitest best practices. Istanbul coverage tracking is done by instrumenting user's source files, meaning adding additional Javascript in user's files, not in build output.

However, I need to verify the actual package structure to determine the correct configuration. Let me check the package structure:

基于我的验证,原始审查评论存在不准确之处。Vitest 官方文档推荐配置 coverage.include 以选择源文件,例如 'src/**/*.{ts,tsx}' 这样的模式。Istanbul 代码覆盖工具通过对用户源文件进行代码插装来追踪覆盖率,而非构建后的文件。

原始审查评论建议"如果应该覆盖构建后的代码,可能需要改为 include: ['dist/index.js']"与 Vitest 最佳实践相悖。覆盖率配置应该指向源文件,让 Vitest 在测试运行时自动转译。

不要按照原始审查评论的建议改为 dist/ 路径。

根据 Taro monorepo 的标准实践和已发现的文件位置(根目录和 src/ 目录都有 index.js),当前配置应该要么保持 include: ['index.js'](如果入口点在根目录),要么改为 include: ['src/index.ts'] 或类似的源文件模式(如果源代码在 src/ 目录)。

Likely an incorrect or invalid review comment.

Comment thread package.json Outdated
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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51ab1dc and b3c696a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • package.json (2 hunks)
  • packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/vitest.config.ts (0 hunks)
  • packages/babel-plugin-transform-solid-jsx/vitest.config.ts (1 hunks)
  • packages/babel-plugin-transform-taroapi/vitest.config.ts (0 hunks)
  • packages/babel-preset-taro/vitest.config.ts (0 hunks)
  • packages/css-to-react-native/vitest.config.ts (0 hunks)
  • packages/shared/vitest.config.ts (0 hunks)
  • packages/taro-extend/vitest.config.ts (0 hunks)
  • packages/taro-runtime/vitest.config.ts (0 hunks)
💤 Files with no reviewable changes (7)
  • packages/babel-preset-taro/vitest.config.ts
  • packages/babel-plugin-transform-react-jsx-to-rn-stylesheet/vitest.config.ts
  • packages/css-to-react-native/vitest.config.ts
  • packages/taro-runtime/vitest.config.ts
  • packages/taro-extend/vitest.config.ts
  • packages/babel-plugin-transform-taroapi/vitest.config.ts
  • packages/shared/vitest.config.ts
🧰 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 中依赖提升的标准做法。
Learnt from: ianzone
Repo: NervJS/taro PR: 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
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
  • packages/babel-plugin-transform-solid-jsx/vitest.config.ts
📚 Learning: 2025-08-25T22:16:50.118Z
Learnt from: ianzone
Repo: NervJS/taro PR: 18150
File: packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json:2356-2356
Timestamp: 2025-08-25T22:16:50.118Z
Learning: The file `packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json` is auto-generated by the post-build script `packages/taro-platform-h5/scripts/post-build.mjs`, which copies content from `taro-platform-h5/dist/definition.json`. This file should not be manually edited.

Applied to files:

  • packages/babel-plugin-transform-solid-jsx/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 - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
🔇 Additional comments (1)
packages/babel-plugin-transform-solid-jsx/vitest.config.ts (1)

1-12: 配置结构正确,coverage 提供程序默认为 v8

Vitest 配置符合 v4 迁移要求:

  • 未指定 coverage.provider 时默认使用 v8,与根目录 package.json 中的 @vitest/coverage-v8 依赖一致
  • environment: 'jsdom' 适用于浏览器环境测试
  • globals: true 启用全局测试 API

Comment thread package.json Outdated
Comment thread packages/babel-plugin-transform-solid-jsx/vitest.config.ts Outdated
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: 1

🧹 Nitpick comments (1)
packages/taro-vite-runner/src/mini/style.ts (1)

28-28: 类型断言安全。

使用类型断言访问内部 API 时,建议添加运行时检查以提高健壮性。

考虑应用以下改进:

-            const importedCss = (chunk as ExtendedOutputChunk).viteMetadata?.importedCss
+            const extendedChunk = chunk as ExtendedOutputChunk
+            const importedCss = extendedChunk.viteMetadata?.importedCss
             if (importedCss && importedCss.size > 0) {

这样可以提高代码可读性,便于调试。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5a5737 and 4f423ff.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • packages/taro-vite-runner/package.json (1 hunks)
  • packages/taro-vite-runner/src/h5/config.ts (2 hunks)
  • packages/taro-vite-runner/src/h5/mpa.ts (1 hunks)
  • packages/taro-vite-runner/src/mini/style.ts (2 hunks)
  • packages/taro/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/taro/package.json
🧰 Additional context used
🧠 Learnings (5)
📓 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 中依赖提升的标准做法。
Learnt from: ianzone
Repo: NervJS/taro PR: 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-25T22:16:50.118Z
Learnt from: ianzone
Repo: NervJS/taro PR: 18150
File: packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json:2356-2356
Timestamp: 2025-08-25T22:16:50.118Z
Learning: The file `packages/babel-plugin-transform-taroapi/tests/__mocks__/h5-definition.json` is auto-generated by the post-build script `packages/taro-platform-h5/scripts/post-build.mjs`, which copies content from `taro-platform-h5/dist/definition.json`. This file should not be manually edited.

Applied to files:

  • packages/taro-vite-runner/src/h5/mpa.ts
  • packages/taro-vite-runner/src/h5/config.ts
📚 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-vite-runner/package.json
📚 Learning: 2025-05-25T18:02:31.387Z
Learnt from: ianzone
Repo: NervJS/taro PR: 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/taro-vite-runner/package.json
  • packages/taro-vite-runner/src/h5/config.ts
📚 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-vite-runner/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-pc-windows-msvc
  • 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-apple-darwin
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
🔇 Additional comments (4)
packages/taro-vite-runner/package.json (1)

60-60: 依赖管理合理。

terser 保留在 devDependencies 中是合理的,因为:

  • Line 21 的 @rollup/plugin-terser 依赖于 terser
  • vite 已正确移至 peerDependencies(line 65)

这符合 monorepo 中的依赖提升策略。根据已有的学习记录,Vitest 相关依赖由根目录统一管理。

packages/taro-vite-runner/src/h5/config.ts (2)

131-131: 类型守卫增强了类型安全。

新增的运行时类型检查确保 middlewareMode 只在值为 'ssr''html' 字符串时才被赋值,有效防止了类型错误和潜在的运行时异常。


266-276: transformIndexHtml API 迁移已正确适配 Vite ^4,两处实现保持一致。

Vite v4 及更高版本(包括 v7)使用 orderhandler 替代了 Vite v3 的 enforcetransform 方式。代码审查中的变更符合此要求:

  • peerDependencies 声明 vite: ^4
  • ✓ config.ts(266-276 行):order: 'pre' + handler(html) — Vite v4+ 标准 API
  • ✓ mpa.ts(140-161 行):order: 'pre' + handler(html, ctx) — 两处实现一致

额外发现:这两个文件中还存在其他使用旧 API 的钩子,未进行迁移:

  • config.ts 第 175 行:插件对象上的 enforce: 'pre'(属于 taro:vite-h5-config 插件)
  • mpa.ts 第 72 行:插件对象上的 enforce: 'pre'(属于 taro:vite-h5-mpa 插件)

这些可能是独立的迁移工作项,建议确认是否需要同步更新以保持代码现代化一致性。

packages/taro-vite-runner/src/h5/mpa.ts (1)

140-161: API 迁移保持一致性。

transformIndexHtml 钩子的更新与 packages/taro-vite-runner/src/h5/config.ts (lines 266-276) 中的变更保持一致:

  • enforce: 'pre'order: 'pre'
  • transformhandler

这确保了整个代码库中 Vite API 使用的统一性。请参考前面对 config.ts 的审查意见,确认此 API 变更与目标 Vite 版本兼容。

Comment thread packages/taro-vite-runner/src/mini/style.ts Outdated
This was referenced Nov 15, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.63%. Comparing base (abec0af) to head (35fa29e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #18607      +/-   ##
==========================================
- Coverage   56.33%   52.63%   -3.70%     
==========================================
  Files         447      463      +16     
  Lines       23342    25108    +1766     
  Branches     5772     6618     +846     
==========================================
+ Hits        13149    13215      +66     
- Misses       8496     9729    +1233     
- Partials     1697     2164     +467     
Flag Coverage Δ
taro-cli 72.85% <ø> (ø)
taro-runtime 60.33% <ø> (ø)
taro-web 53.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 29 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.

@ianzone
Copy link
Copy Markdown
Contributor Author

ianzone commented Nov 24, 2025

@yoyo837 求合并

@ianzone
Copy link
Copy Markdown
Contributor Author

ianzone commented Nov 27, 2025

@yoyo837 兄弟帮忙看看?感谢

_setStorage();
export { Taro };"
`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这部分快照少了,符合预期吗?

var _styleSheet = _appStylStyleSheet;
render(<div style={_styleSheet["header"]} />);"
`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这部分快照也少了,符合预期吗?

@ianzone ianzone requested a review from yoyo837 November 27, 2025 02:45
@ianzone
Copy link
Copy Markdown
Contributor Author

ianzone commented Nov 28, 2025

@yoyo837 兄弟咋说?

@yoyo837
Copy link
Copy Markdown
Contributor

yoyo837 commented Nov 28, 2025

@yoyo837 兄弟咋说?

review了你没理会呢

@ianzone
Copy link
Copy Markdown
Contributor Author

ianzone commented Nov 28, 2025

@yoyo837 兄弟咋说?

review了你没理会呢

刚做了实验,将变更后的快照应用到当前的main分支中,测试依旧能通过,说明上一版本的vitest生成了快照但没覆盖之前jest的快照,这次快照变更清理的是jest遗留的快照

@yoyo837 yoyo837 added this to the 4.1.10 milestone Dec 2, 2025
@ianzone
Copy link
Copy Markdown
Contributor Author

ianzone commented Dec 2, 2025

@yoyo837 PR可以关了?

@yoyo837 yoyo837 merged commit ef4a0b2 into NervJS:main Dec 2, 2025
24 checks passed
@ianzone ianzone deleted the vitest branch December 2, 2025 07:08
Muyouz pushed a commit that referenced this pull request Dec 19, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Dec 19, 2025
27 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jan 8, 2026
27 tasks
Single-Dancer added a commit that referenced this pull request Jan 8, 2026
* Revert "chore: stencil update (#18649)"

This reverts commit 4e186a3.

* Revert "test(babel-plugin-transform-solid-jsx): vitest (#18607)"

This reverts commit ef4a0b2.

* fix: 目前 macos 无法正常执行测试,暂时跳过,等待后续优化

* chore(ci): 替换过期的macos镜像

---------

Co-authored-by: zhuqingan.3 <zhuqingan.3@jd.com>
Co-authored-by: Single-Dancer <chenchiajun@gmail.com>
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