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:更新测试脚本与配置,重构并新增多处测试以适配新框架;移除旧的 Jest 测试配置。
  • Documentation

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

@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

将 taro-runtime 的测试框架从 Jest 迁移到 Vitest:移除旧 Jest 配置与测试 tsconfig,新增 vitest.config.ts 并更新 package.json 测试脚本;大量测试文件从 src/__tests__ 移至 tests 并改为 ESM/Vitest 风格;修复多处拼写(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)、更新 npm test 脚本为 vitest,调整 tsconfig include/exclude。
测试用例重构与迁移(ESM/Vitest)
packages/taro-runtime/src/__tests__/*, packages/taro-runtime/tests/*, 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

需要额外关注的文件/区域:

  • packages/taro-runtime/vitest.config.tspackage.json 中测试脚本与全局标志的一致性。
  • packages/taro-runtime/src/constants/index.ts 对外导出的枚举改名可能影响外部引用(确认所有引用已更新)。
  • TaroWindow 导出改动与新增的 tests/bom/window.spec.ts 是否与外部使用兼容。
  • inner-html 的 Scanner 重命名及其 parser 调用链,确认无遗漏的导入路径。

Possibly related PRs

Suggested reviewers

  • yoyo837
  • tutuxxx

Poem

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

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标题清晰准确地反映了主要变更内容:将taro-runtime包从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 6f96df0 and 0377afc.

📒 Files selected for processing (1)
  • packages/taro-runtime/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/taro-runtime/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 - aarch64-apple-darwin
  • 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

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 (a018f9d) to head (0377afc).
⚠️ Report is 1 commits behind head on main.

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       21563    23342    +1779     
  Branches     5283     5773     +490     
==========================================
+ Hits        12070    13149    +1079     
- Misses       8013     8360     +347     
- Partials     1480     1833     +353     
Flag Coverage Δ
taro-cli 72.85% <ø> (ø)
taro-runtime 60.33% <88.88%> (+0.46%) ⬆️
taro-web 53.12% <ø> (ø)

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 86 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
This was referenced Nov 8, 2025
@ianzone
Copy link
Contributor Author

ianzone commented Nov 11, 2025

@yoyo837 求合并

@yoyo837 yoyo837 added this to the 4.1.9 milestone Nov 11, 2025
@yoyo837 yoyo837 merged commit 2de8374 into NervJS:main Nov 11, 2025
24 checks passed
@ianzone ianzone deleted the vitest branch November 11, 2025 01:23
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