Skip to content

Conversation

ianzone
Copy link
Contributor

@ianzone ianzone commented Jun 29, 2025

这个 PR 是什么类型? (至少选择一个)

  • 错误修复 (Bugfix) issue: fix typo

Summary by CodeRabbit

  • 新特性

    • 新增 Array.prototype.findIndex 的 polyfill 支持。
    • 新增多个 Vitest 测试用例,覆盖 DOM、样式、事件、缓存、历史、Location、MutationObserver 等核心功能。
    • 增加 Vitest 测试配置及测试辅助工具。
  • 修复

    • 统一并修正 DESTROY 相关常量拼写错误,保证生命周期和事件监听正常触发。
    • 规范参数、变量、类名大小写及拼写,提升代码一致性。
    • 修正文档、注释和参数命名中的拼写及格式。
  • 重构

    • 测试框架由 Jest 切换为 Vitest,相关配置文件及脚本同步调整。
    • 移除旧的 Jest 配置、测试相关文件及多余的 changelog 文件。
  • 文档

    • 更新部分文档和注释,提升参数说明和代码示例的准确性。
  • 依赖升级

    • 升级 Vitest 及相关代码覆盖率依赖版本。
  • 样式

    • 优化部分注释和文档中的格式与标点。

Copy link

coderabbitai bot commented Jun 29, 2025

Walkthrough

本次变更主要聚焦于 Taro 相关包的测试体系升级与代码规范修正。具体包括将测试框架从 Jest 迁移至 Vitest,新增和完善了大量 Vitest 单元测试,修复了各处拼写错误(如 DESTORY→DESTROY、Scaner→Scanner、isParentBinded→isParentBound 等),统一参数命名风格,完善了 polyfill 实现,并同步调整了相关文档和配置文件,删除了部分旧的配置和 changelog 文件。

Changes

文件/路径分组 变更摘要
packages/taro-runtime/jest.config.js
packages/taro-runtime/tsconfig.test.json
packages/eslint-plugin-taro/CHANGELOG.md
packages/taro-components/CHANGELOG.md
删除 Jest 配置、测试 tsconfig 及部分 changelog 文件
packages/taro-runtime/vitest.config.ts
packages/taro-runtime/tests/setup.ts
新增 Vitest 配置及测试环境初始化脚本
packages/taro-runtime/package.json
package.json
测试脚本由 Jest 切换为 Vitest,依赖版本同步升级
packages/taro-runtime/tests/* 新增/重写大量 Vitest 单元测试,覆盖 DOM、事件、样式、polyfill、缓存、location、history 等模块
packages/taro-runtime/src/constants/index.ts 枚举成员拼写修正:DESTORY→DESTROY
packages/taro-runtime/src/bom/history.ts
packages/taro-runtime/src/bom/location.ts
packages/taro-runtime/src/bom/window.ts
packages/taro-runtime/src/dsl/common.ts
packages/taro-platform-harmony-cpp/src/runtime/framework/native-page.ts
packages/taro-platform-harmony-cpp/src/runtime/framework/page.ts
packages/taro-platform-harmony/src/runtime-framework/react/native-page.ts
packages/taro-platform-harmony/src/runtime-framework/react/page.ts
packages/taro-platform-harmony/src/runtime-framework/solid/page.ts
packages/taro-framework-react/src/runtime/connect-native.ts
统一 DESTORY→DESTROY,参数 reactdom→reactDOM,变量命名风格统一
packages/taro-runtime/src/utils/index.ts
packages/taro-runtime/src/dom/event.ts
工具函数 isParentBinded→isParentBound,相关调用同步
packages/taro-runtime/src/polyfill/array.ts 新增 Array.prototype.findIndex polyfill
packages/taro-runtime/src/tests/mutation.spec.js 删除旧 MutationObserver 测试
packages/taro-runtime/src/dom-external/inner-html/parser.ts
packages/taro-runtime/src/dom-external/inner-html/scanner.ts
packages/taro-runtime/tests/html.spec.ts
Scaner→Scanner,修正导入路径与相关调用
packages/taro-api/src/interceptor/index.ts 导出函数参数名修正 promiseifyApi→promisifyApi
packages/taro-runtime/tests/utils.ts 新增 delay 辅助函数
packages/shared/src/shortcuts.ts 注释拼写修正
packages/taro-router/README.md 文档参数命名统一 reactdom→reactDOM
.github/ISSUE_TEMPLATE/config.yml
.github/ISSUE_TEMPLATE/feature_request.yml
issue 模板描述与标签优化,细节调整
CONTRIBUTING.md 代码块语言标记 json→js
packages/taro-api/jest.config.js 移除 moduleNameMapper 相关配置
packages/taro-runtime/tsconfig.json 移除对 src/tests 的排除

Sequence Diagram(s)

sequenceDiagram
  participant TestRunner as Vitest
  participant Setup as setup.ts
  participant Source as 源代码模块
  participant Polyfill as Polyfill
  participant Tests as 各测试用例

  TestRunner->>Setup: 运行测试前初始化环境变量与全局特性
  TestRunner->>Polyfill: 加载并应用 Array/DOM polyfill
  TestRunner->>Source: 加载被测模块
  TestRunner->>Tests: 执行单元测试
  Tests->>Source: 调用/断言模块行为
  Tests->>Polyfill: 验证 polyfill 功能
Loading

Suggested reviewers

  • luckyadam
  • tutuxxx
  • yoyo837

Poem

兔子翻书页,测试新世界,
Vitest 跳跃,Jest 悄然离开。
拼写修正,风格统一,
新增 polyfill,DOM 测试齐。
代码整洁,文档清晰,
Taro 生态,跃然纸上欢喜!

(兔兔:(_/)\
( •_•)
/>🍃 代码如春风~)


📜 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 96382a3 and 373b24f.

⛔ Files ignored due to path filters (2)
  • packages/taroize/__tests__/__snapshots__/wxml.test.ts.snap is excluded by !**/*.snap
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 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). (6)
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot requested a review from tutuxxx June 29, 2025 05:36
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: 1

🧹 Nitpick comments (3)
packages/taro-platform-harmony/src/runtime-framework/react/native-page.ts (1)

418-428: reactDOM 参数补充类型,保持一致性

此处把参数统一为 reactDOM 很好,但依旧缺少类型声明,TS 检查时会丢失静态约束。

-function createNativeComponentConfig (
-  Component,
-  react: typeof React,
-  reactDOM,
-  componentConfig
+function createNativeComponentConfig (
+  Component: any,
+  react: typeof React,
+  reactDOM: typeof ReactDOM,
+  componentConfig: any
 )
packages/taro-platform-harmony-cpp/src/runtime/framework/native-page.ts (1)

448-456: 未声明类型的 reactDOM 参数

与上面的 React 版实现相同,这里也建议显式标注参数类型,避免后续修改导致的类型漂移。

-export function createNativeComponentConfig (
-  Component,
-  compName: string,
-  react: typeof React,
-  reactDOM,
-  componentConfig: any = {}
+export function createNativeComponentConfig (
+  Component: any,
+  compName: string,
+  react: typeof React,
+  reactDOM: typeof ReactDOM,
+  componentConfig: any = {}
 )
packages/taro-framework-react/src/runtime/connect-native.ts (1)

346-354: reactDOM 参数缺少类型声明

三个工厂函数(createH5NativeComponentConfigcreateNativeComponentConfig 等)均引入了未经类型限定的 reactDOM,与其他文件保持一致可读性更佳。

-function createH5NativeComponentConfig (
-  Component,
-  react: typeof React,
-  reactDOM: typeof ReactDOM,
+function createH5NativeComponentConfig (
+  Component: any,
+  react: typeof React,
+  reactDOM: typeof ReactDOM,
 )

其余类似处同理。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d1d8b7d and 7ae9c31.

⛔ Files ignored due to path filters (1)
  • packages/eslint-plugin-taro/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (18)
  • packages/eslint-plugin-taro/CHANGELOG.md (0 hunks)
  • packages/shared/src/shortcuts.ts (1 hunks)
  • packages/taro-components/CHANGELOG.md (0 hunks)
  • packages/taro-framework-react/src/runtime/connect-native.ts (2 hunks)
  • packages/taro-platform-harmony-cpp/src/runtime/framework/native-page.ts (2 hunks)
  • packages/taro-platform-harmony-cpp/src/runtime/framework/page.ts (1 hunks)
  • packages/taro-platform-harmony/src/runtime-framework/react/native-page.ts (2 hunks)
  • packages/taro-platform-harmony/src/runtime-framework/react/page.ts (1 hunks)
  • packages/taro-platform-harmony/src/runtime-framework/solid/page.ts (1 hunks)
  • packages/taro-router/README.md (2 hunks)
  • packages/taro-runtime/src/__tests__/location.spec.js (2 hunks)
  • packages/taro-runtime/src/bom/history.ts (1 hunks)
  • packages/taro-runtime/src/bom/location.ts (1 hunks)
  • packages/taro-runtime/src/bom/window.ts (1 hunks)
  • packages/taro-runtime/src/constants/index.ts (1 hunks)
  • packages/taro-runtime/src/dsl/common.ts (1 hunks)
  • packages/taroize/src/template.ts (2 hunks)
  • packages/taroize/src/wxml.ts (15 hunks)
💤 Files with no reviewable changes (2)
  • packages/eslint-plugin-taro/CHANGELOG.md
  • packages/taro-components/CHANGELOG.md
🧰 Additional context used
🧠 Learnings (12)
packages/taro-runtime/src/bom/location.ts (1)
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-platform-harmony/src/runtime-framework/solid/page.ts (1)
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-platform-harmony-cpp/src/runtime/framework/page.ts (1)
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-platform-harmony/src/runtime-framework/react/page.ts (1)
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/src/dsl/common.ts (1)
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-router/README.md (1)
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/src/bom/window.ts (1)
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/src/__tests__/location.spec.js (1)
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 目录。不要假设包中存在测试目录结构。
packages/taroize/src/wxml.ts (3)
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 文件。
Learnt from: Single-Dancer
PR: NervJS/taro#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 来避免无限等待。
Learnt from: Single-Dancer
PR: NervJS/taro#17653
File: packages/taro-components-advanced/src/components/water-flow/node.ts:83-95
Timestamp: 2025-05-06T06:55:44.077Z
Learning: 在 Taro 的 water-flow 组件中,getRectSizeSync 函数如果找不到指定的节点,会一直处于 pending 状态而不是抛出错误。在这种情况下,应该使用 Promise.race 添加超时机制,而不是仅依赖 try/catch 来处理错误。
packages/taro-platform-harmony/src/runtime-framework/react/native-page.ts (1)
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-platform-harmony-cpp/src/runtime/framework/native-page.ts (1)
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-framework-react/src/runtime/connect-native.ts (1)
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 文件。
🧬 Code Graph Analysis (3)
packages/taro-runtime/src/dsl/common.ts (2)
packages/taro-runtime/src/bom/window.ts (1)
  • taroWindowProvider (112-112)
packages/taro-runtime/src/index.ts (1)
  • taroWindowProvider (17-17)
packages/taro-platform-harmony/src/runtime-framework/react/native-page.ts (2)
packages/taro-platform-harmony/src/runtime-ets/bom/window.ts (1)
  • window (48-48)
packages/taro-framework-react/src/runtime/react-meta.ts (1)
  • reactMeta (10-13)
packages/taro-framework-react/src/runtime/connect-native.ts (2)
packages/taro-framework-react/src/runtime/react-meta.ts (1)
  • reactMeta (10-13)
packages/taro-framework-react/src/runtime/connect.ts (1)
  • setReconciler (21-94)
🪛 Biome (1.9.4)
packages/taroize/src/wxml.ts

[error] 455-456: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • 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
🔇 Additional comments (16)
packages/shared/src/shortcuts.ts (1)

9-9: 注释拼写修正已生效 👍

注释由 “Attrtibutes” 更正为 “Attributes”,提高了可读性,无功能影响。

packages/taro-runtime/src/constants/index.ts (1)

60-60: 拼写修正正确!

将枚举成员 DESTORY 修正为 DESTROY 是正确的拼写更正,保持了相同的值 '3'

packages/taro-runtime/src/bom/location.ts (1)

86-86: 常量使用更新正确!

正确使用了修正后的 CONTEXT_ACTIONS.DESTROY 常量,事件监听器注册逻辑保持不变。

packages/taro-runtime/src/bom/history.ts (1)

77-77: 常量使用更新正确!

正确使用了修正后的 CONTEXT_ACTIONS.DESTROY 常量,缓存清理逻辑保持不变。

packages/taro-runtime/src/__tests__/location.spec.js (1)

373-373: 测试注释更新正确!

测试用例中的注释正确更新为 CONTEXT_ACTIONS.DESTROY,与代码实现保持一致。

Also applies to: 471-471

packages/taro-runtime/src/bom/window.ts (1)

79-82: 常量使用更新正确!

所有三处都正确使用了修正后的 CONTEXT_ACTIONS.DESTROY 常量,页面卸载时的上下文清理逻辑保持不变。

packages/taro-platform-harmony/src/runtime-framework/solid/page.ts (1)

155-155: 拼写错误修正正确

CONTEXT_ACTIONS.DESTORY 修正为 CONTEXT_ACTIONS.DESTROY 是必要的拼写错误修复,确保了上下文销毁事件名称的正确性。

packages/taro-platform-harmony/src/runtime-framework/react/page.ts (1)

155-155: 拼写错误修正正确

与其他平台文件保持一致,将 CONTEXT_ACTIONS.DESTORY 修正为 CONTEXT_ACTIONS.DESTROY,确保了跨平台代码的命名一致性。

packages/taro-platform-harmony-cpp/src/runtime/framework/page.ts (1)

157-157: 拼写错误修正正确

在 harmony-cpp 平台中同样修正了 CONTEXT_ACTIONS.DESTORYCONTEXT_ACTIONS.DESTROY,完善了整个代码库中事件命名的一致性。

packages/taro-router/README.md (2)

7-7: 参数命名规范修正正确

reactdom 修正为 reactDOM 符合 JavaScript 的 camelCase 命名规范,提升了 API 文档的专业性。


29-29: 参数说明命名规范修正正确

与函数签名保持一致,将参数说明中的 reactdom 修正为 reactDOM,确保了文档的一致性。

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

175-175: 核心运行时文件拼写错误修正正确

在运行时核心文件中将 CONTEXT_ACTIONS.DESTORY 修正为 CONTEXT_ACTIONS.DESTROY,与其他平台文件保持一致,完善了整个代码库的拼写错误修复。

packages/taro-platform-harmony/src/runtime-framework/react/native-page.ts (1)

320-324: 事件常量已纠正,但请确认所有订阅方也已同步修改

window.trigger(CONTEXT_ACTIONS.DESTROY, $taroPath) 的拼写修复消除了潜在的事件对不上号问题 👍。
建议 grep 全仓库,确认没有遗漏的 DESTORY 监听或触发代码,以避免运行期出现「事件未触发」的隐性 Bug。

packages/taro-platform-harmony-cpp/src/runtime/framework/native-page.ts (1)

328-332: DESTROY 常量修复 👍

卸载时改为 CONTEXT_ACTIONS.DESTROY 与常量定义保持一致,逻辑正确。

packages/taro-framework-react/src/runtime/connect-native.ts (1)

244-249: 拼写修正已到位,但请排查遗留代码

CONTEXT_ACTIONS.DESTROY 已替换成功。推荐执行一次:

rg DESTORY packages | wc -l

确认仓库中不再存在旧拼写。

packages/taroize/src/template.ts (1)

17-18: 同步修正 import 与调用,依赖关系已恢复

template.ts 中的 import 与 path.traverse 调用已同步使用新函数名,编译时不会再出现找不到符号的问题。

Also applies to: 213-214

Copy link

codecov bot commented Jun 29, 2025

Codecov Report

Attention: Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.

Project coverage is 55.52%. Comparing base (da3decb) to head (d597632).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
packages/taro-runtime/src/bom/window.ts 33.33% 2 Missing ⚠️
packages/taro-runtime/src/polyfill/array.ts 88.88% 2 Missing ⚠️
packages/taro-runtime/src/dom/event.ts 0.00% 1 Missing ⚠️
packages/taro-runtime/src/dsl/common.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17928      +/-   ##
==========================================
+ Coverage   54.98%   55.52%   +0.53%     
==========================================
  Files         417      442      +25     
  Lines       21693    23323    +1630     
  Branches     5359     5788     +429     
==========================================
+ Hits        11928    12949    +1021     
- Misses       8120     8497     +377     
- Partials     1645     1877     +232     
Flag Coverage Δ
taro-cli 72.42% <ø> (ø)
taro-runtime 61.40% <77.77%> (+1.53%) ⬆️
taro-web 53.19% <ø> (ø)

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/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/utils/index.ts 96.61% <100.00%> (+71.21%) ⬆️
packages/taro-runtime/src/dom/event.ts 25.51% <0.00%> (ø)
packages/taro-runtime/src/dsl/common.ts 22.61% <0.00%> (ø)
packages/taro-runtime/src/bom/window.ts 61.22% <33.33%> (-2.57%) ⬇️
packages/taro-runtime/src/polyfill/array.ts 88.67% <88.88%> (ø)

... and 48 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.

@coderabbitai coderabbitai bot requested review from luckyadam and yoyo837 June 29, 2025 16:14
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: 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 c6632d8 and 92296f5.

📒 Files selected for processing (1)
  • packages/taro-runtime/src/__tests__/window.spec.js (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/taro-runtime/src/__tests__/window.spec.js (5)
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 文件。
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: Single-Dancer
PR: NervJS/taro#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 来避免无限等待。
Learnt from: Single-Dancer
PR: NervJS/taro#17653
File: packages/taro-components-advanced/src/components/water-flow/node.ts:83-95
Timestamp: 2025-05-06T06:55:44.077Z
Learning: 在 Taro 的 water-flow 组件中,getRectSizeSync 函数如果找不到指定的节点,会一直处于 pending 状态而不是抛出错误。在这种情况下,应该使用 Promise.race 添加超时机制,而不是仅依赖 try/catch 来处理错误。
Learnt from: Single-Dancer
PR: NervJS/taro#17653
File: packages/taro-components-advanced/src/components/water-flow/node.ts:83-95
Timestamp: 2025-05-06T06:55:44.077Z
Learning: 在 Taro 的 water-flow 组件中,getRectSizeSync 函数如果找不到指定的节点并且重试次数用尽,会一直处于 pending 状态而不是抛出错误,因为它在 retryTimes <= 0 时直接返回而不 resolve 或 reject Promise。应该使用 Promise.race 添加超时机制来解决这个问题。
🧬 Code Graph Analysis (1)
packages/taro-runtime/src/__tests__/window.spec.js (2)
packages/taro-runtime/src/bom/window.ts (1)
  • document (86-88)
packages/taro-extend/src/jquery/sizzle.js (1)
  • doc (587-587)
🪛 Biome (1.9.4)
packages/taro-runtime/src/__tests__/window.spec.js

[error] 458-458: A global variable should not be reassigned.

Assigning to a global variable can override essential functionality.

(lint/suspicious/noGlobalAssign)

⏰ Context from checks skipped due to timeout of 90000ms (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 (2)
packages/taro-runtime/src/__tests__/window.spec.js (2)

3-728: 优秀的测试覆盖率和结构

这个测试套件为 Taro 运行时的 window 对象提供了全面且结构良好的测试覆盖。测试正确使用了修正后的 CONTEXT_ACTIONS.DESTROY 常量,涵盖了属性验证、事件处理、上下文操作、定时器和边界情况等各个方面。


289-290: 合理处理测试环境差异

在处理 setTimeoutrequestAnimationFrame 等 API 时,代码通过注释说明了测试环境与浏览器环境的差异,这是一个thoughtful的处理方式。这些注释掉的断言为未来可能的测试环境改进保留了参考。

Also applies to: 302-303, 404-406

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 (10)
packages/taro-runtime/tests/exports.spec.ts (1)

5-5: 修正测试套件命名不一致问题

测试套件名称 "style" 与实际测试内容不符。该测试主要验证运行时模块的各种导出(BOM、DOM、事件、DSL),而不是样式相关功能。

建议修改为更准确的名称:

-describe('style', () => {
+describe('exports', () => {
packages/taro-runtime/tests/class.spec.ts (1)

10-10: 建议移除注释掉的代码

注释掉的 global.navigator = runtime.navigator 代码如果不需要,建议直接删除以保持代码整洁。

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

15-15: 建议改进测试用例的命名

测试用例名称"works"过于通用,建议使用更具描述性的名称,例如"should handle style property operations correctly"。

- it('works', () => {
+ it('should handle style property operations correctly', () => {

19-19: 建议添加注释说明内部属性的使用

测试中使用了_usedStyleProp这个内部属性,建议添加注释说明为什么需要测试这个内部状态。

+ // 验证内部属性追踪机制
  expect(style._usedStyleProp.size).toBe(1)
packages/taro-runtime/tests/eventSource.spec.ts (1)

65-65: 建议验证硬编码的数字

测试中使用了硬编码的数字10和3,建议添加注释说明这些数字的来源,或者使用更明确的计算方式。

+ // 总共创建了10个节点:1个container + 1个list + 4个list的子节点 + 4个嵌套节点
  expect(eventSource.size).toBe(10)
packages/taro-runtime/tests/dsl-common.spec.ts (1)

88-110: ID生成器测试与其他文件重复

这个测试与utils-functions.spec.ts中的ID生成器测试有重复。建议将ID生成器的测试统一到一个文件中,避免重复。

考虑将ID生成器测试移到utils-functions.spec.ts中,因为它是一个工具函数。

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

65-108: 建议增强 BOM 模块测试的深度

当前的 Navigator、getComputedStyle 和 Document 模块测试过于基础,仅检查模块是否存在。建议添加功能性测试来验证这些模块的实际行为。

例如,可以添加如下测试:

describe('BOM - Navigator', () => {
  it('should provide navigator-like functionality', async () => {
    const navigatorModule = await import('../src/bom/navigator')
    
    expect(navigatorModule).toBeDefined()
-   expect(Object.keys(navigatorModule).length).toBeGreaterThanOrEqual(0)
+   // 测试具体的 navigator 属性和方法
+   expect(navigatorModule.userAgent).toBeDefined()
+   expect(typeof navigatorModule.platform).toBe('string')
  })
})
packages/taro-runtime/tests/html.spec.ts (1)

14-20: 建议完成或移除跳过的测试

当前有一个被跳过的测试,注释说"测试还没写完"。建议要么完成这个测试,要么如果不需要就移除它,以保持测试套件的完整性。

是否需要我帮助实现这个测试或者建议如何完成它?

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

17-17: 修正测试描述中的拼写错误

测试描述中的 "childeNodes" 应该是 "childNodes"。

-    it('childeNodes 有任何类型', () => {
+    it('childNodes 有任何类型', () => {

160-160: 修正测试描述中的拼写错误

测试描述中的 "textContext" 应该是 "textContent"。

-    it('textContext', () => {
+    it('textContent', () => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 92296f5 and 3a688f6.

⛔ Files ignored due to path filters (1)
  • packages/taroize/__tests__/__snapshots__/wxml.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (22)
  • packages/taro-runtime/package.json (1 hunks)
  • packages/taro-runtime/src/bom/window.ts (1 hunks)
  • packages/taro-runtime/src/polyfill/array.ts (1 hunks)
  • packages/taro-runtime/tests/bom.spec.ts (1 hunks)
  • packages/taro-runtime/tests/cache.spec.ts (1 hunks)
  • packages/taro-runtime/tests/class.spec.ts (1 hunks)
  • packages/taro-runtime/tests/dom-style.spec.ts (1 hunks)
  • packages/taro-runtime/tests/dom.spec.ts (1 hunks)
  • packages/taro-runtime/tests/dsl-common.spec.ts (1 hunks)
  • packages/taro-runtime/tests/event.spec.ts (1 hunks)
  • packages/taro-runtime/tests/eventSource.spec.ts (1 hunks)
  • packages/taro-runtime/tests/exports.spec.ts (1 hunks)
  • packages/taro-runtime/tests/html.spec.ts (1 hunks)
  • packages/taro-runtime/tests/location.spec.ts (1 hunks)
  • packages/taro-runtime/tests/mutation.spec.ts (1 hunks)
  • packages/taro-runtime/tests/polyfill-array.spec.ts (1 hunks)
  • packages/taro-runtime/tests/react.spec.ts (1 hunks)
  • packages/taro-runtime/tests/setup.ts (1 hunks)
  • packages/taro-runtime/tests/style.spec.ts (1 hunks)
  • packages/taro-runtime/tests/utils-functions.spec.ts (1 hunks)
  • packages/taro-runtime/tests/utils.ts (1 hunks)
  • packages/taro-runtime/vitest.config.ts (1 hunks)
✅ Files skipped from review due to trivial changes (5)
  • packages/taro-runtime/tests/utils.ts
  • packages/taro-runtime/package.json
  • packages/taro-runtime/src/bom/window.ts
  • packages/taro-runtime/tests/setup.ts
  • packages/taro-runtime/vitest.config.ts
🧰 Additional context used
🧠 Learnings (16)
📓 Common learnings
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 文件。
Learnt from: Single-Dancer
PR: NervJS/taro#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/react.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/cache.spec.ts (1)
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/exports.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/eventSource.spec.ts (1)
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/tests/polyfill-array.spec.ts (1)
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/utils-functions.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/class.spec.ts (1)
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/tests/html.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/event.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/dsl-common.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/bom.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/dom.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/dom-style.spec.ts (1)
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/tests/mutation.spec.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/tests/location.spec.ts (1)
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 目录。不要假设包中存在测试目录结构。
🧬 Code Graph Analysis (7)
packages/taro-runtime/tests/react.spec.ts (1)
packages/taro-runtime/src/bom/window.ts (1)
  • document (86-88)
packages/taro-runtime/tests/eventSource.spec.ts (2)
packages/taro-runtime/src/bom/window.ts (1)
  • document (86-88)
packages/taro-runtime/src/dom/event.ts (1)
  • target (65-88)
packages/taro-runtime/tests/utils-functions.spec.ts (2)
packages/taro-runtime/src/index.ts (1)
  • TaroText (26-26)
packages/taro-runtime/src/utils/index.ts (5)
  • isText (61-63)
  • isComment (65-67)
  • isHasExtractProp (69-74)
  • shortcutAttr (93-104)
  • customWrapperCache (106-106)
packages/taro-runtime/tests/style.spec.ts (2)
packages/taro-runtime/src/bom/window.ts (1)
  • document (86-88)
packages/taro-platform-harmony/src/runtime-ets/dom/element/element.ts (1)
  • style (254-256)
packages/taro-runtime/tests/bom.spec.ts (2)
packages/taro-runtime/src/bom/window.ts (3)
  • setTimeout (100-102)
  • clearTimeout (104-106)
  • taroWindowProvider (112-112)
packages/taro-runtime/src/index.ts (2)
  • raf (14-14)
  • caf (14-14)
packages/taro-runtime/tests/dom-style.spec.ts (2)
packages/taro-runtime/src/bom/window.ts (1)
  • document (86-88)
packages/taro-platform-harmony/src/runtime-ets/dom/element/element.ts (1)
  • style (254-256)
packages/taro-runtime/tests/mutation.spec.ts (2)
packages/taro-runtime/src/bom/window.ts (1)
  • document (86-88)
packages/taro-runtime/src/index.ts (1)
  • MutationObserver (27-27)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
🔇 Additional comments (28)
packages/taro-runtime/src/polyfill/array.ts (1)

56-81: 新增的 findIndex polyfill 实现正确

这个新增的 handleArrayFindIndexPolyfill 函数完全遵循了 ECMAScript 规范,实现方式与现有的 findincludes polyfill 保持一致。函数正确处理了 this 上下文验证、类型检查、以及 thisArg 参数传递。

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

1-21: React 集成测试实现良好

测试文件结构合理,正确设置了 React 框架环境变量,并在测试后进行了清理。事件处理测试覆盖了 React 集成的核心功能,验证了 tap 事件的分发和监听器调用。

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

1-131: Array polyfill 测试覆盖全面且结构良好

测试文件展现了优秀的测试实践:

  • 使用 beforeEach/afterEach 正确保存和恢复原生方法,确保测试隔离
  • 动态导入 polyfill 函数避免了副作用
  • 全面测试了 includes、find、findIndex 三个 polyfill 的功能
  • 覆盖了边界情况,包括 null、undefined、0、false、空字符串等特殊值
  • 验证了回调函数的参数传递(value、index、array)
packages/taro-runtime/tests/exports.spec.ts (1)

10-33: 导出验证测试实现正确

测试全面验证了运行时模块的关键导出,包括 BOM 对象、DOM 类、事件系统和 DSL 配置功能。测试逻辑正确,覆盖了模块的主要 API 接口。

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

1-94: 缓存工具测试覆盖全面且实现优秀

测试文件展现了出色的测试设计:

  • 全面测试了 RuntimeCache 的核心功能:set、get、has、delete
  • 测试了各种数据类型,包括字符串、数字、复杂对象和嵌套结构
  • 正确处理边界情况,如空值、null、undefined 的过滤逻辑
  • 验证了多个缓存实例的独立性
  • 使用 beforeEach 确保每个测试都有干净的缓存实例

测试逻辑清晰,覆盖了缓存工具的所有关键场景。

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

1-109: 测试文件结构良好,覆盖了核心功能

这个测试文件很好地覆盖了DOM元素的class属性和classList API的核心功能。测试逻辑清晰,包含了主要的使用场景。


57-58: 测试用例可以更简洁

这个测试用例验证了classList.add()的幂等性(添加相同class不会重复),逻辑正确。

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

1-43: 测试文件整体结构良好

这个测试文件有效地验证了Style类的核心功能,包括属性设置、获取、删除和cssText操作。测试逻辑正确,覆盖了主要的使用场景。

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

1-76: 测试文件结构良好,覆盖了核心功能

这个测试文件很好地验证了eventSource模块的节点删除功能,包括单个节点删除和整个节点树删除。测试逻辑清晰,使用了适当的生命周期钩子。


26-51: 测试用例的文档注释很有帮助

使用HTML注释来描述DOM结构是一个很好的做法,让测试用例更容易理解。

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

1-209: 测试文件组织良好,覆盖面广

这个测试文件很好地组织了各种工具函数的测试,包含了节点类型检查、属性工具、组件工具等多个方面。测试逻辑清晰,覆盖了边界情况。


185-187: ID生成器测试验证了正确的序列

测试正确地验证了ID生成器的序列性,从'AA'开始递增。这个测试逻辑是正确的。

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

1-112: 测试文件结构良好,覆盖了主要功能

这个测试文件很好地验证了DSL通用功能,包括页面实例管理、安全执行、组件配置等。测试逻辑清晰,覆盖了主要的使用场景。


60-64: 测试用例验证了错误处理

测试正确地验证了safeExecute函数在处理不存在的页面实例时的行为,返回undefined是合理的。

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

12-63: RAF 测试实现得很好

RequestAnimationFrame 测试使用了正确的模拟和清理模式,包括:

  • 在 beforeEach/afterEach 中正确设置和恢复全局函数
  • 60fps 的合理模拟实现
  • 异步测试模式的正确使用
packages/taro-runtime/tests/dom-style.spec.ts (1)

1-101: 样式类测试覆盖全面且实现良好

这个测试套件很好地覆盖了 Style 类的各个方面:

  • 初始化状态验证
  • 属性设置和获取
  • CSS 变量处理
  • cssText 的 getter/setter
  • removeProperty 方法
  • 边缘情况处理(空值、不存在的属性)

测试结构清晰,使用了合适的 beforeEach 设置,并且涵盖了重要的边缘情况。

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

1-185: 事件处理测试非常全面

这个测试套件很好地覆盖了事件系统的各个方面:

  • addEventListener 和 removeEventListener 的基本功能
  • 事件选项(如 { once: true })的正确处理
  • 事件名称的小写化规范化
  • 事件传播控制(stopPropagation、preventDefault、stopImmediatePropagation)
  • 多个事件处理器的管理
  • 边缘情况处理(空事件移除、无监听器的事件分发)

测试使用了适当的 spy 函数和异步模式,代码质量很高。

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

22-391: HTML 解析和 CSS 选择器测试非常全面

这个测试套件对 HTML 解析和 CSS 功能的测试覆盖非常全面:

  • 各种 CSS 选择器(标签、ID、类、属性选择器)
  • CSS 组合器(后代、子元素、相邻兄弟、通用兄弟)
  • CSS 特异性和排序
  • 特殊标签处理(如 script 标签的跳过)
  • 自定义文本转换功能

测试用例设计得很好,覆盖了复杂的选择器组合和边缘情况。

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

1-284: MutationObserver 测试实现优秀

这个测试套件对 MutationObserver 功能进行了全面而精确的测试:

  • 覆盖了所有主要的 DOM 变更操作(appendChild、replaceChild、removeChild)
  • 正确验证了变更记录的结构(target、type、previousSibling、nextSibling、addedNodes、removedNodes)
  • 包含了子树观察(subtree)的测试
  • 使用了正确的异步测试模式
  • 测试组织清晰,包含适当的设置和清理

测试覆盖了各种场景,包括单节点、多节点和深层树结构的变更,确保 MutationObserver 的行为符合预期。

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

5-14: 测试环境设置合理

正确设置了 Vitest 测试环境,包括 FRAMEWORK 环境变量和全局对象的配置,afterAll 清理也很到位。


127-149: insertAdjacentHTML 测试覆盖全面

测试覆盖了 insertAdjacentHTML 的所有四个位置选项(beforebegin, afterbegin, beforeend, afterend),验证逻辑正确且全面。


261-310: 锚点元素 URL 解析测试详尽

全面测试了锚点元素的 URL 解析功能,包括各种 URL 组件(protocol, host, pathname, search, hash 等),测试用例覆盖了不同的 URL 格式。

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

6-53: parseUrl 函数测试覆盖全面

测试用例涵盖了完整 URL、不完整 URL、边界情况等多种场景,包括协议默认处理和路径规范化,测试逻辑正确。


116-146: URL 构造函数错误处理测试完整

正确测试了各种无效 URL 构造的错误情况,包括空参数、无效协议、无效基础 URL 等,错误类型和消息验证准确。


164-186: URL 构造测试用例来源权威

测试用例参考了 MDN 官方文档,确保了实现与标准的一致性,这是很好的做法。


338-347: 事件触发和模拟处理正确

使用 vi.fn() 正确模拟了 window.trigger 方法,并验证了 hashchange 事件的触发次数,测试逻辑清晰。


349-378: 上下文操作测试覆盖完整

全面测试了 CONTEXT_ACTIONS 的各种操作(INIT, RESTORE, RECOVER, DESTROY),包括缓存管理和状态恢复,验证了复杂的生命周期管理逻辑。


442-476: History 上下文操作测试详尽

History 对象的上下文操作测试与 Location 类似但更复杂,正确验证了历史记录长度、缓存状态和位置恢复,测试设计合理。

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: 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 3a688f6 and 8d638e5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • package.json (2 hunks)
  • packages/taro-runtime/jest.config.js (0 hunks)
  • packages/taro-runtime/src/__tests__/mutation.spec.js (0 hunks)
  • packages/taro-runtime/src/dom/event.ts (2 hunks)
  • packages/taro-runtime/src/utils/index.ts (1 hunks)
  • packages/taro-runtime/tests/utils-functions.spec.ts (1 hunks)
  • packages/taro-runtime/tsconfig.json (0 hunks)
  • packages/taro-runtime/vitest.config.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • packages/taro-runtime/tsconfig.json
  • packages/taro-runtime/jest.config.js
  • packages/taro-runtime/src/tests/mutation.spec.js
✅ Files skipped from review due to trivial changes (3)
  • packages/taro-runtime/src/dom/event.ts
  • package.json
  • packages/taro-runtime/src/utils/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/taro-runtime/tests/utils-functions.spec.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
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 文件。
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 目录。不要假设包中存在测试目录结构。
packages/taro-runtime/vitest.config.ts (2)
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 文件。
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 目录。不要假设包中存在测试目录结构。
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi

This was referenced Jul 12, 2025
@ianzone ianzone closed this Jul 17, 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.

1 participant