Skip to content

Avoid deep imports and migrate tests#227

Merged
zombieJ merged 1 commit into
react-component:masterfrom
QDyanbing:avoid-deep-imports
Jun 8, 2026
Merged

Avoid deep imports and migrate tests#227
zombieJ merged 1 commit into
react-component:masterfrom
QDyanbing:avoid-deep-imports

Conversation

@QDyanbing

@QDyanbing QDyanbing commented May 21, 2026

Copy link
Copy Markdown
Contributor

变更内容

  • 升级 @rc-component/util 到包含根入口导出的版本,并升级 @rc-component/father-plugin
  • @rc-component/util/lib/... 深路径导入调整为从 @rc-component/util 根入口导入。
  • 将剩余 Enzyme 测试迁移到 Testing Library。
  • 移除 enzymeenzyme-adapter-react-16enzyme-to-jsoncheerioregenerator-runtime 和 enzyme snapshot serializer/setup 配置。
  • 测试环境 dev 依赖对齐到 React 18,运行时 peerDependencies 保持不变。

验证

  • npm test -- --runInBand 通过。
  • npm run lint 通过,保留既有 react-hooks/exhaustive-deps warning。

Summary by CodeRabbit

发布说明

  • Chores

    • 升级 React 支持版本至 18.0,更新相关依赖包至最新兼容版本
    • 更新测试工具链依赖,替换测试框架以适应新版本
  • Tests

    • 迁移测试用例至新的测试框架,确保测试覆盖率与执行效果一致

Review Change Stack

@vercel

vercel Bot commented May 21, 2026

Copy link
Copy Markdown

@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d79cdccb-b0bb-4474-b810-62ca99fc13f3

📥 Commits

Reviewing files that changed from the base of the PR and between 084d692 and 174f4c8.

📒 Files selected for processing (7)
  • jest.config.js
  • package.json
  • src/SingleObserver/index.tsx
  • src/index.tsx
  • tests/Collection.spec.js
  • tests/index.spec.js
  • tests/setup.js
💤 Files with no reviewable changes (2)
  • jest.config.js
  • tests/setup.js

概览

该 PR 完成了从 Enzyme 到 React Testing Library 的测试框架迁移,同时升级 React 版本至 18.x,更新 @rc-component/util 导入,移除过时依赖,并重构测试全局 mock 以支持新的测试方式。

变更清单

测试框架迁移与依赖升级

层级 / 文件(s) 摘要
依赖版本及配置更新
package.json, jest.config.js
升级 React 16→18,@rc-component/util ^1.2.0→^1.11.1,@testing-library/react ^12.1.5→^16.0.1,@rc-component/father-plugin ^2.0.2→^2.2.0;移除 Enzyme、enzyme-adapter、enzyme-to-json、cheerio、regenerator-runtime;Jest 配置移除 snapshotSerializers。
测试全局 ResizeObserver mock 重构
tests/setup.js
移除 Enzyme adapter 配置与 wrapper 原型扩展,使用新 ResizeObserver 全局 mock 实现:构造时保存回调,observe(target) 时立即触发,unobserve() 为空实现。
源码导入路径更新
src/SingleObserver/index.tsx, src/index.tsx
@rc-component/util 相关函数(getDOM、supportRef、useComposeRef、getNodeRef、toArray、warning)的导入从深层路径调整为从包入口直接导入。
Collection 测试迁移
tests/Collection.spec.js
将导入从 Enzyme + regenerator-runtime 改为 React Testing Library + 本地 triggerResize/waitPromise;测试从 mount/wrapper.triggerResize 改为 render/container/querySelector,断言改为基于获取的 DOM 节点验证 onBatchResize 回调参数。
主组件测试全面迁移
tests/index.spec.js
迁移导入(React Testing Library render、本地 triggerResize/elementListeners/waitPromise);重写 10+ 个测试用例(children 警告、ref 支持、onResize 基本与偏移变化、精度检验、disabled/unmount、多种子类型、renderProps)从 Enzyme mount/wrapper 模式改为 render/container DOM 查询与触发模式。

🎯 4 (复杂) | ⏱️ ~60 分钟

相关 PR

建议审阅者

  • zombieJ
  • Wxh16144

🐰 从酶到库,测试焕新妆,
React 十八登场,框架现模样;
导入整整齐齐,依赖理清爽,
组件观察者,齐声来欢唱! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确总结了主要变更:避免深层导入并迁移测试,涵盖了包版本升级、导入方式重构和Enzyme到Testing Library的迁移这三个核心内容。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​testing-library/​react@​16.3.29910010087100

View full report

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request upgrades the library to React 18 and migrates the entire test suite from Enzyme to React Testing Library. Key changes include updating dependencies in package.json, simplifying utility imports from @rc-component/util, and refactoring test files to use render and DOM-based queries instead of Enzyme's mount and wrapper methods. I have no feedback to provide.

@QDyanbing

Copy link
Copy Markdown
Contributor Author

Refs ant-design/ant-design#58115

antd 侧统一跟踪 rc 包 es/lib 深路径引用问题。

@zombieJ zombieJ merged commit 81f5707 into react-component:master Jun 8, 2026
4 of 5 checks passed
@QDyanbing QDyanbing deleted the avoid-deep-imports branch June 13, 2026 08:54
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