test(babel-plugin-transform-solid-jsx): vitest#18607
Conversation
Walkthrough将多个包的测试框架从 Jest 迁移到 Vitest:移除包级 Jest 配置、添加 Vitest 配置文件、更新测试脚本与测试文件为 ESM,并在仓根与若干包中新增或升级 Vite/Rollup/Vitest 相关依赖与脚本。 Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used🧠 Learnings (3)📓 Common learnings📚 Learning: 2025-08-25T22:16:50.118ZApplied to files:
📚 Learning: 2025-08-08T02:32:58.265ZApplied to files:
⏰ 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)
🔇 Additional comments (3)
Tip ✨ Issue Enrichment is now available for GitHub issues!CodeRabbit can now help you manage issues more effectively:
Disable automatic issue enrichmentTo disable automatic issue enrichment, add the following to your issue_enrichment:
auto_enrich:
enabled: falseThanks 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.
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 (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.jsonpackages/babel-plugin-transform-solid-jsx/package.jsonpackages/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.jsonpackages/babel-plugin-transform-solid-jsx/vitest.config.tspackages/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和__dirnamepolyfill- 导入路径使用了明确的
.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 --coveragetest:从jest --no-cache改为vitest runtest: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']toinclude: ['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.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 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 (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.jsonpackages/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 提供程序默认为 v8Vitest 配置符合 v4 迁移要求:
- 未指定
coverage.provider时默认使用 v8,与根目录 package.json 中的@vitest/coverage-v8依赖一致environment: 'jsdom'适用于浏览器环境测试globals: true启用全局测试 API
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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.tspackages/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.jsonpackages/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)使用
order和handler替代了 Vite v3 的enforce和transform方式。代码审查中的变更符合此要求:
- ✓
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'transform→handler这确保了整个代码库中 Vite API 使用的统一性。请参考前面对 config.ts 的审查意见,确认此 API 变更与目标 Vite 版本兼容。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
@yoyo837 求合并 |
|
@yoyo837 兄弟帮忙看看?感谢 |
| _setStorage(); | ||
| export { Taro };" | ||
| `; | ||
|
|
| var _styleSheet = _appStylStyleSheet; | ||
| render(<div style={_styleSheet["header"]} />);" | ||
| `; | ||
|
|
|
@yoyo837 兄弟咋说? |
review了你没理会呢 |
刚做了实验,将变更后的快照应用到当前的main分支中,测试依旧能通过,说明上一版本的vitest生成了快照但没覆盖之前jest的快照,这次快照变更清理的是jest遗留的快照 |
|
@yoyo837 PR可以关了? |
* 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>
这个 PR 做了什么? (简要描述所做更改)
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
发布说明
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.