Skip to content

Conversation

@ianzone
Copy link
Contributor

@ianzone ianzone commented Jul 22, 2025

这个 PR 做了什么? (简要描述所做更改)
将 taro-runtime 的 jest 测试改为 vitest 测试

这个 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

  • Bug Fixes

    • 修复卸载阶段拼写错误,确保页面上下文、历史与位置能正确清理。
  • Refactor

    • 将窗口类导出以供外部使用;重命名上下文动作枚举项与内部扫描器类;重命名公共工具函数以提升一致性。
  • Chores / Tests

    • 测试框架迁移至 Vitest:更新测试脚本、配置并重构/新增多处测试以适配新框架。
  • Documentation

    • 更新 README 中的事件文档链接。

@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

将 taro-runtime 从 Jest 迁移到 Vitest:移除旧 Jest 配置、引入 vitest.config.ts、更新 npm test 脚本;大量测试文件改为 ESM/Vitest 风格并搬迁到 tests 目录;修复多处拼写(CONTEXT_ACTIONS.DESTROY)、导出 TaroWindow、重命名 Scaner→Scanner、重命名 isParentBinded→isParentBound,更新相关引用与文档链接。

Changes

Cohort / File(s) Summary
测试框架迁移:配置与脚本
packages/taro-runtime/jest.config.js, packages/taro-runtime/tsconfig.test.json, packages/taro-runtime/vitest.config.ts, packages/taro-runtime/package.json, packages/taro-runtime/tsconfig.json
移除 Jest 配置与测试 tsconfig,新增 Vitest 配置(全局特性标志、coverage、setup)、更新 package.json 测试脚本为 vitest,并调整 tsconfig 包含项。
测试用例重构与迁移(ESM/Vitest)
packages/taro-runtime/src/__tests__/*, packages/taro-runtime/tests/*.spec.ts, packages/taro-runtime/tests/bom/window.spec.ts, packages/taro-runtime/tests/utils.ts
删除旧的 src/__tests__ Jest 测试,新增/迁移测试到 tests 目录并改用 Vitest 的 ESM 导入(describe/test/expect/vi),少量类型与可选链修正,调整测试依赖路径。
上下文销毁动作常量修正
packages/taro-runtime/src/constants/index.ts, packages/taro-runtime/src/bom/{history.ts,location.ts,window.ts}, packages/taro-runtime/src/dsl/common.ts, 多个 runtime/framework 文件(.../page.ts, native-page.ts 等)
将枚举与字符串常量 CONTEXT_ACTIONS.DESTORY 重命名为 CONTEXT_ACTIONS.DESTROY,并在所有触发/监听处同步更新。
TaroWindow 导出与测试
packages/taro-runtime/src/bom/window.ts, packages/taro-runtime/tests/bom/window.spec.ts
TaroWindow 改为导出类(export class TaroWindow),修正生命周期事件引用,新增针对 TaroWindow 初始化、属性复制与生命周期事件的单元测试。
inner-html 扫描器重命名与对齐
packages/taro-runtime/src/dom-external/inner-html/{scanner.ts,parser.ts}, packages/taro-runtime/tests/html.spec.ts
导出类名由 ScanerScanner,parser 改为 new Scanner(...).scan();更新测试导入路径与名称。
工具函数重命名与引用更新
packages/taro-platform-harmony/src/runtime-ets/utils/index.ts, packages/taro-runtime/src/utils/index.ts, packages/taro-runtime/src/dom/event.ts
导出函数 isParentBinded 重命名为 isParentBound,并在使用处同步更新导入与调用。
小修正与文档更新
packages/taro-runtime/README.md, 若干 platform/runtime 文件
更新 README 中的 Events 链接,修正注释拼写与少量格式;修正多个平台/框架中 DESTROY 拼写错误。

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Page as 页面/组件
    participant PageCfg as Page Config [ONUNLOAD]
    participant Win as TaroWindow
    participant Loc as TaroLocation
    participant His as TaroHistory

    Note over PageCfg,Win: 卸载流程(已修正为 CONTEXT_ACTIONS.DESTROY)
    PageCfg->>Win: trigger(CONTEXT_ACTIONS.DESTROY, pageId)
    Win->>Loc: trigger(CONTEXT_ACTIONS.DESTROY, pageId)
    Win->>His: trigger(CONTEXT_ACTIONS.DESTROY, pageId)
    Loc-->>Loc: 删除 pageId 对应的 Location 缓存
    His-->>His: 删除 pageId 对应的 History 缓存
    Win-->>PageCfg: 卸载完成通知
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • yoyo837
  • tutuxxx

Poem

小兔在代码间轻跳,
Jest 褪去换新装。
DESTROY 喊声随风到,
Scanner 改名步更俏。
测试跑通庆一跳 🐰✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed PR 标题"test(taro-runtime): vitest"准确反映了此拉取请求的主要变更。根据原始摘要,该 PR 的核心目标是将 taro-runtime 包的测试框架从 Jest 迁移到 Vitest,包括删除 Jest 配置文件、添加新的 Vitest 配置、重构测试文件使用 Vitest 的导入风格(将 it 改为 test)、更新所有相关测试脚本等。标题简洁明确地传达了这一主要目的,使团队成员在浏览历史时能够快速理解这是一个测试框架迁移的拉取请求。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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 b0298bc and 6f96df0.

📒 Files selected for processing (2)
  • packages/taro-runtime/package.json (1 hunks)
  • packages/taro-runtime/src/dsl/common.ts (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 中依赖提升的标准做法。
📚 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/taro-runtime/package.json
🧬 Code graph analysis (1)
packages/taro-runtime/src/dsl/common.ts (2)
packages/taro-runtime/src/bom/window.ts (1)
  • taroWindowProvider (110-110)
packages/taro-runtime/src/index.ts (1)
  • taroWindowProvider (17-17)
⏰ 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). (3)
  • 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-pc-windows-msvc
🔇 Additional comments (3)
packages/taro-runtime/package.json (2)

25-26: 验证 Vitest 配置已包含原 Jest CI flags。

从 Jest 迁移到 Vitest 时,原 "test:ci" 脚本包含的关键 flags 已被简化:

  • 原: jest --ci -i --coverage --silent
  • 现: vitest run --coverage

缺失的 flags(--ci, -i, --silent)需要确认已在 vitest.config.ts 中配置,特别是 -i(单进程)标志对 CI 环境的稳定性很重要。请确保 Vitest 配置中包含相应的串行执行设置。

考虑在 CI 脚本中显式保留这些标志以增强清晰度和可维护性:

- "test:ci": "vitest run --coverage"
+ "test:ci": "vitest run --coverage --reporter=verbose"

或在 vitest.config.ts 中创建专用 CI 配置。


39-45: 依赖管理遵循 monorepo 最佳实践。

Vitest 依赖不在此包的 devDependencies 中声明,而是在根 package.json 中统一管理,这符合 pnpm 工作区的标准做法。rollup-plugin-ts 的移除也是合适的。

根据学习记录,此做法在 Taro 项目中一致应用。

packages/taro-runtime/src/dsl/common.ts (1)

175-175: 拼写修正正确。

CONTEXT_ACTIONS.DESTORY 修正为 CONTEXT_ACTIONS.DESTROY 是正确的拼写更正。根据 AI 摘要,此修正与整个运行时代码库中的其他类似修正保持一致,确保了常量命名的正确性。


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.

@coderabbitai coderabbitai bot requested review from tutuxxx and yoyo837 July 22, 2025 09:07
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: 2

🧹 Nitpick comments (2)
packages/taro-runtime/package.json (1)

25-26: 脚本切换到 Vitest ✅
脚本已对齐新框架,参数简单明了。可考虑再加一个 test:watch 方便本地调试:

"test:watch": "vitest"
packages/taro-runtime/tests/style.spec.ts (1)

11-13: 环境变量清理 OK,但建议使用 Vitest API
可用 afterAll 的别名 vi.afterAll,避免同时引入多个同名函数后混淆。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1e8dc9 and 2c02ceb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (19)
  • packages/taro-runtime/jest.config.js (0 hunks)
  • packages/taro-runtime/package.json (1 hunks)
  • packages/taro-runtime/src/__tests__/event.spec.js (0 hunks)
  • packages/taro-runtime/src/__tests__/mutation.spec.js (0 hunks)
  • packages/taro-runtime/src/__tests__/react.spec.js (0 hunks)
  • packages/taro-runtime/tests/class.spec.ts (6 hunks)
  • packages/taro-runtime/tests/dom.spec.ts (13 hunks)
  • packages/taro-runtime/tests/event.spec.ts (1 hunks)
  • packages/taro-runtime/tests/eventSource.spec.ts (4 hunks)
  • packages/taro-runtime/tests/exports.spec.ts (2 hunks)
  • packages/taro-runtime/tests/html.spec.ts (16 hunks)
  • packages/taro-runtime/tests/location.spec.ts (14 hunks)
  • packages/taro-runtime/tests/mutation.spec.ts (1 hunks)
  • packages/taro-runtime/tests/react.spec.ts (1 hunks)
  • packages/taro-runtime/tests/style.spec.ts (1 hunks)
  • packages/taro-runtime/tests/utils.ts (1 hunks)
  • packages/taro-runtime/tsconfig.json (1 hunks)
  • packages/taro-runtime/tsconfig.test.json (0 hunks)
  • packages/taro-runtime/vitest.config.ts (1 hunks)
🧠 Learnings (14)
📓 Common learnings
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 文件。
packages/taro-runtime/tsconfig.json (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/package.json (2)

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

Learnt from: ianzone
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 文件。

packages/taro-runtime/tests/style.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/class.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/exports.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/vitest.config.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/react.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/html.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/eventSource.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/dom.spec.ts (3)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

Learnt from: Single-Dancer
PR: #17653
File: packages/taro-components-advanced/src/components/water-flow/node.ts:83-95
Timestamp: 2025-05-06T06:55:44.077Z
Learning: 在 Taro 的 getRectSizeSync 函数中,如果找不到指定的节点,函数会一直处于 pending 状态而不是抛出错误。在这种情况下,使用 try/catch 处理不够充分,需要添加超时处理如 Promise.race 来避免无限等待。

packages/taro-runtime/tests/location.spec.ts (2)

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

Learnt from: ianzone
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 文件。

packages/taro-runtime/tests/event.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/mutation.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

💤 Files with no reviewable changes (5)
  • packages/taro-runtime/tsconfig.test.json
  • packages/taro-runtime/src/tests/event.spec.js
  • packages/taro-runtime/jest.config.js
  • packages/taro-runtime/src/tests/react.spec.js
  • packages/taro-runtime/src/tests/mutation.spec.js
🧰 Additional context used
🧠 Learnings (14)
📓 Common learnings
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 文件。
packages/taro-runtime/tsconfig.json (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/package.json (2)

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

Learnt from: ianzone
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 文件。

packages/taro-runtime/tests/style.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/class.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/exports.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/vitest.config.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/react.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/html.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/eventSource.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/dom.spec.ts (3)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

Learnt from: Single-Dancer
PR: #17653
File: packages/taro-components-advanced/src/components/water-flow/node.ts:83-95
Timestamp: 2025-05-06T06:55:44.077Z
Learning: 在 Taro 的 getRectSizeSync 函数中,如果找不到指定的节点,函数会一直处于 pending 状态而不是抛出错误。在这种情况下,使用 try/catch 处理不够充分,需要添加超时处理如 Promise.race 来避免无限等待。

packages/taro-runtime/tests/location.spec.ts (2)

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

Learnt from: ianzone
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 文件。

packages/taro-runtime/tests/event.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

packages/taro-runtime/tests/mutation.spec.ts (2)

Learnt from: ianzone
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 文件。

Learnt from: ianzone
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 目录。不要假设包中存在测试目录结构。

⏰ 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-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • 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 - aarch64-apple-darwin
🔇 Additional comments (38)
packages/taro-runtime/tests/utils.ts (1)

2-2: 👍 显式声明 Promise<void> 很好
补充返回类型让 TS 推导更准确,符合 “self-documenting code” 的理念。无其他问题。

packages/taro-runtime/tests/class.spec.ts (1)

10-10: 导航器注释掉是否仍需?
若 runtime 内部有对 navigator 的访问,Vitest 将抛出 ReferenceError。请确认后决定保留或删除该注释。

packages/taro-runtime/tests/style.spec.ts (1)

1-4: 测试文件已 ESM 化 👍
引入方式统一为 ESM,提高一致性,无明显问题。

packages/taro-runtime/tests/exports.spec.ts (3)

1-1: LGTM! 正确的 Vitest 导入语法

使用显式导入的方式从 vitest 导入测试函数,这是推荐的做法。


3-3: LGTM! 改用源码导入路径

../src/index 直接导入源码而不是构建后的分发版本,这在测试环境中是合适的做法。


10-10: LGTM! 统一使用 test 函数

it 更改为 test 以保持与 Vitest API 的一致性,这是正确的迁移做法。

Also applies to: 19-19, 25-25, 30-30

packages/taro-runtime/tests/eventSource.spec.ts (4)

1-3: LGTM! 正确的 Vitest 迁移

显式导入 Vitest 测试工具并改用源码导入路径,符合迁移最佳实践。


8-8: LGTM! 提高代码清晰度

显式赋值 document 变量提高了代码的可读性和明确性。


20-20: LGTM! 函数增强

createDiv 函数添加可选的类型化 id 参数,这是一个很好的改进。


29-29: LGTM! 统一测试函数命名

将测试函数从 it 更改为 test 以保持与 Vitest API 的一致性。

Also applies to: 53-53

packages/taro-runtime/tests/html.spec.ts (5)

1-9: LGTM! 完整的 Vitest 迁移导入

所有导入语句都已正确更新为使用源码路径和显式 Vitest 函数导入,迁移工作完整。


17-17: LGTM! 显式传递 document 参数

明确传递 document 对象到 parser 函数,提高了代码的清晰度。


22-22: LGTM! 统一测试函数命名

所有测试用例都已从 it 更改为 test,与 Vitest API 保持一致。

Also applies to: 42-42, 62-62, 93-93, 115-115, 137-137, 151-151, 171-171, 216-216, 253-253, 285-285, 317-317, 341-341, 347-347, 356-356, 379-379


327-327: LGTM! 测试内容微调

将换行符替换为空格的内容调整是合理的测试数据修改。

Also applies to: 336-336


380-380: LGTM! 参数类型改进

transformText 函数的参数添加类型注解,提高了代码质量。

packages/taro-runtime/tests/react.spec.ts (3)

1-3: LGTM! 正确的 Vitest 导入设置

使用了完整的 Vitest 测试工具导入,包括 vi 用于模拟函数,这是正确的设置。


5-11: LGTM! 合适的测试环境设置

正确设置了 React 框架环境变量,并在测试结束后进行了清理,这是良好的测试实践。


13-25: LGTM! 完整的事件处理测试

测试覆盖了事件创建、监听器注册和事件分发的完整流程,验证逻辑正确且全面。

packages/taro-runtime/vitest.config.ts (3)

1-3: LGTM! 正确的配置文件导入

导入了必要的 path 工具和 Vitest 配置定义函数,设置正确。


6-14: LGTM! 完整的功能特性标志配置

定义了所有必要的 DOM 相关功能特性标志,确保运行时功能的完整性,这些配置对于 taro-runtime 的正常工作至关重要。


15-22: LGTM! 完整的测试配置

测试文件匹配模式、代码覆盖率配置和设置文件路径都配置正确,为 Vitest 测试提供了完整的运行环境。

packages/taro-runtime/tests/dom.spec.ts (5)

1-1: 迁移到 Vitest 框架的导入设置正确

正确地导入了 Vitest 的测试函数,替换了 Jest 的隐式全局变量。


3-3: 运行时导入路径更新合理

从构建后的分发版本改为直接从源代码导入,这在测试环境中更加合适。


17-226: 测试方法名称统一更新

所有测试用例都正确地从 it 更新为 test,与 Vitest 约定保持一致。


132-132: 添加可选链操作符提高代码健壮性

insertAdjacentHTML 测试中添加了可选链操作符,这是一个很好的改进,可以防止在节点可能为 undefined 时出现运行时错误。

Also applies to: 135-138, 147-148


8-10: 确认:在 dom.spec.ts 中移除 global.navigator 不会影响现有测试

在 dom.spec.ts 的用例中,并未直接访问或依赖全局的 navigator;所有 DOM 操作测试均基于从 src/index 导出的 windowdocument 实例。
而对 navigator 的验证在 exports.spec.ts 中通过:

  • runtime.window.navigatorruntime.navigator 均已从 bom/navigator 正常导出并在测试中校验,不依赖 global.navigator

结论:可安全保留注释,所有当前用例均能通过。

packages/taro-runtime/tests/location.spec.ts (6)

1-3: Vitest 迁移设置正确

正确地从 Jest 迁移到 Vitest,包括导入语句和运行时模块路径的更新。


6-516: 测试方法名称和模拟函数更新完整

所有测试用例都正确地从 it 更新为 test,模拟函数从 jest.fn() 更新为 vi.fn(),保持了 Vitest 框架的一致性。


121-121: 错误处理类型转换改进

在 URL 构造函数测试中添加了错误类型转换 (error as Error),这提高了 TypeScript 类型安全性。

Also applies to: 129-129, 137-137, 145-145


171-178: URL 构造函数测试参数调整

将 URL 对象改为字符串作为 base 参数,这是一个合理的简化。


239-285: Router 模拟对象属性增强

Current.router 模拟对象中添加了 $taroPathonReadyonHideonShow 属性,使模拟对象更完整。


397-397: 缓存访问添加可选链

在访问缓存条目时添加了可选链操作符,提高了代码的健壮性。

Also applies to: 501-502

packages/taro-runtime/tests/event.spec.ts (2)

1-11: 新事件测试套件设置完善

正确使用 Vitest 框架,导入了必要的测试函数和运行时模块。测试环境清理设置合理。


12-245: 事件系统测试覆盖全面

测试套件全面覆盖了事件系统的关键功能:

  • 事件监听器的添加、移除和触发
  • 事件冒泡和阻止传播
  • 多个处理程序和一次性选项
  • 默认行为阻止
  • 立即停止传播

测试用例结构清晰,使用了适当的中文描述,mock 函数使用一致。

packages/taro-runtime/tests/mutation.spec.ts (4)

1-23: MutationObserver 测试套件设置规范

测试套件正确使用了 Vitest 框架,生命周期钩子设置合理,包括观察器的初始化和清理。


24-91: appendChild 变异测试覆盖完整

测试用例全面覆盖了 appendChild 操作的变异观察,包括首个节点、兄弟节点和深层树结构的情况,断言结构完整。


93-169: replaceChild 变异测试场景全面

测试用例涵盖了 replaceChild 操作的各种场景,包括单节点和多节点的替换,正确验证了变异记录的结构。


171-284: removeChild 变异测试逻辑严谨

测试用例详细验证了 removeChild 操作的变异观察,包括单个节点、多个兄弟节点和深层结构的移除,异步测试模式使用正确。

@codecov
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 56.33%. Comparing base (7420fda) to head (6f96df0).

Files with missing lines Patch % Lines
packages/taro-runtime/src/dsl/common.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #18056      +/-   ##
==========================================
+ Coverage   55.97%   56.33%   +0.35%     
==========================================
  Files         416      447      +31     
  Lines       21560    23339    +1779     
  Branches     5267     5768     +501     
==========================================
+ Hits        12069    13148    +1079     
- Misses       7904     8368     +464     
- Partials     1587     1823     +236     
Flag Coverage Δ
taro-cli 72.85% <ø> (ø)
taro-runtime 60.33% <88.88%> (+0.46%) ⬆️
taro-web 53.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/taro-runtime/src/bom/history.ts 98.27% <100.00%> (+58.27%) ⬆️
packages/taro-runtime/src/bom/location.ts 90.72% <ø> (+74.16%) ⬆️
packages/taro-runtime/src/bom/window.ts 91.83% <100.00%> (+28.04%) ⬆️
packages/taro-runtime/src/constants/index.ts 100.00% <100.00%> (ø)
...taro-runtime/src/dom-external/inner-html/parser.ts 78.83% <100.00%> (-0.89%) ⬇️
...aro-runtime/src/dom-external/inner-html/scanner.ts 81.30% <ø> (ø)
packages/taro-runtime/src/dom/event.ts 93.87% <100.00%> (ø)
packages/taro-runtime/src/utils/index.ts 59.32% <100.00%> (+33.92%) ⬆️
packages/taro-runtime/src/dsl/common.ts 0.96% <0.00%> (ø)

... and 50 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
Contributor Author

ianzone commented Jul 22, 2025

@yoyo837 辛苦合一下哈

This was referenced Jul 26, 2025
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