Skip to content

Avoid deep imports and migrate tests#202

Open
QDyanbing wants to merge 2 commits into
react-component:masterfrom
QDyanbing:avoid-deep-imports
Open

Avoid deep imports and migrate tests#202
QDyanbing wants to merge 2 commits into
react-component:masterfrom
QDyanbing:avoid-deep-imports

Conversation

@QDyanbing
Copy link
Copy Markdown

@QDyanbing QDyanbing commented May 21, 2026

变更内容

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

验证

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

Summary by CodeRabbit

发布说明

  • 重构

    • 调整模块导入方式,增强代码可维护性
    • 补充类型声明导出
  • 测试

    • 升级测试框架至现代方案
  • 杂项

    • 升级至 React 18 支持
    • 更新依赖包版本

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

@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
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Warning

Rate limit exceeded

@QDyanbing has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 58 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2780383c-5608-4335-90bf-16d3f6ce531a

📥 Commits

Reviewing files that changed from the base of the PR and between 0e6791c and 7bc4aaf.

📒 Files selected for processing (1)
  • tests/props.spec.js

Walkthrough

本 PR 将 react-component/rate 从 Enzyme 测试框架迁移至 React Testing Library,同时升级 React 至 18.x、更新 @rc-component/util 依赖至 1.11.1、清理相关旧版依赖,并调整导入方式与公开 API 类型。

Changes

Enzyme 到 RTL 迁移与 React 18 升级

Layer / File(s) Summary
依赖升级与 Jest 配置更新
package.json, jest.config.js
@rc-component/util 升级至 ^1.11.1、React 升级至 18.x、移除 Enzyme 及相关依赖(enzyme、enzyme-adapter-react-16、enzyme-to-json、cheerio),并移除 jest 配置中的 enzyme-to-json 快照序列化器。
源码导入更新与类型导出
src/Rate.tsx, src/Star.tsx, src/index.tsx
调整 Rate 与 Star 组件的导入语句以使用更新的 @rc-component/util API(从深路径导入改为根包命名导入),新增 RateProps、RateRef、StarProps 的类型重导出。
测试框架迁移初始化
tests/setup.js, tests/simple.spec.js
格式化调整 setup.js;在 simple.spec.js 中完整替换测试框架导入,引入 React Testing Library、fireEvent,新增 DOM 查询与事件模拟工具函数。
属性渲染测试迁移
tests/props.spec.js
将 characterRender 用例从 Enzyme mount/wrapper.find 转换为 React Testing Library render/querySelectorAll,调整断言方式。
核心评分功能测试迁移
tests/simple.spec.js
将 rate 和 allowHalf 功能测试从 Enzyme mount/simulate 改写为 RTL render/fireEvent,覆盖点击、鼠标移动、获焦失焦、键盘事件(含 RTL)及 hover 行为验证。
扩展功能与事件测试迁移
tests/simple.spec.js
将 allowClear、focus & blur、autoFocus、events 和 html attributes 等测试改写为 RTL,验证清空行为、回调触发、事件处理与 HTML 属性透传。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • react-component/rate#198: 对 src/Rate.tsxsrc/Star.tsx@rc-component/util 导入的命名空间迁移工作与本 PR 直接重叠。

Suggested reviewers

  • zombieJ

Poem

🐰 酶测试说再见,RTL 新世代降临,
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 The pull request title "Avoid deep imports and migrate tests" accurately summarizes the two main changes: eliminating deep imports from @rc-component/util and migrating tests from Enzyme to React 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

socket-security Bot commented May 21, 2026

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

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​types/​react-dom@​17.0.26 ⏵ 18.3.710010076 +185100
Updated@​types/​react@​17.0.92 ⏵ 18.3.29100 +110079 +296100

View full report

Copy link
Copy Markdown
Contributor

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

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 migrates the testing framework from Enzyme to React Testing Library and updates React and its type definitions to version 18. It also refactors imports from @rc-component/util to use named exports and adds several type exports to the main entry point. A review comment identifies a potential flaw in the characterRender test where the DOM query might return an empty list, potentially leading to a false positive.

Comment thread tests/props.spec.js Outdated
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