Skip to content

[codex] upgrade tests to React 18#359

Merged
zombieJ merged 1 commit into
masterfrom
codex/react-18-upgrade
May 20, 2026
Merged

[codex] upgrade tests to React 18#359
zombieJ merged 1 commit into
masterfrom
codex/react-18-upgrade

Conversation

@zombieJ
Copy link
Copy Markdown
Member

@zombieJ zombieJ commented May 20, 2026

Summary

  • Raise React and React DOM peer/dev dependencies to React 18.
  • Drop Enzyme and the Enzyme adapter from dev dependencies.
  • Convert the test suite to Testing Library render/fireEvent/act APIs.

Validation

  • npm run lint
  • bunx tsc --noEmit
  • npm run compile
  • bun run test -- --coverage --silent

Summary by CodeRabbit

  • 兼容性更新

    • 最低 React 要求从 16.9.0 提升到 18.0.0
  • 开发依赖

    • 更新若干开发依赖版本(包括 React/React DOM 与测试/渲染相关库)
  • 测试

    • 大量测试从 Enzyme 迁移到 React Testing Library,测试用例改为基于 DOM 查询与 fireEvent/act,若干异步/定时器相关断言同步调整

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
virtual-list Ready Ready Preview, Comment May 20, 2026 8:16am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

本 PR 升级 package.json 中的 peer/dev 依赖以支持 React 18,并将大量测试从 Enzyme 重写为 @testing-library/react(包含导入、辅助函数、事件触发、act 包裹和断言适配)。

Changes

依赖升级与测试迁移

Layer / File(s) Summary
React 及测试库依赖升级
package.json
peerDependencies 中 react/react-dom 最低版本从 >=16.9.0 提升到 >=18.0.0;devDependencies 中升级 @testing-library/reactrc-test,并将 dev 依赖的 react/react-dom 升至 ^18.3.1
测试引入与辅助函数迁移
tests/*
统一将测试导入从 Enzyme/react-dom/test-utils 切换为 @testing-library/react,新增/改写 genNode/genListgetHoldergetScrollOffset 等测试工具以基于 DOM 断言。
List 测试适配 DOM 断言
tests/list.test.js
将 List 相关测试从读取组件 props 改为基于渲染后样式与 translateY/height 的 DOM 检查,使用 rerender 驱动状态切换并改用 onLibResize 触发高度收集。
scroll.test 的全面迁移与 act() 修正
tests/scroll.test.js
将大量滚动、滚动条与边界测试改写为 RTL,使用 createEvent/fireEventact 包裹 scrollTojest.runAllTimers(),并用 DOM 查询替换 Enzyme 实例断言。
scrollWidth 的 act 包裹
tests/scrollWidth.test.tsx
为 ref 的 scrollTo 调用添加 act(() => ...) 包裹以保证断言前更新完成。
Firefox 专用测试迁移
tests/scroll-Firefox.test.js
将 UL 节点获取改为 container.querySelector('ul') 并直接断言 scrollTop 以替代 Enzyme instance 用法。
mock/props/test 的 RTL 重写
tests/mock.test.js, tests/props.test.js
将测试断言从 Enzyme wrapper 转为 DOM 查询(containerquerySelectortextContent),移除对 Enzyme 的依赖并保持原断言语义。
触摸交互测试迁移
tests/touch.test.js
触摸滚动测试改为使用 RTL 渲染、在 act 内触发触摸事件并显式 unmount() 清理。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • afc163

Poem

🐰 我在草丛间跳跃写测试,
把旧的 mount 换成 render 的节拍,
act 把时序轻轻包裹,定时器也乖,
依赖升级到十八号,代码安然入睡,
小胡萝卜祝合并顺利 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确反映了主要变更内容——升级React和测试相关依赖至React 18,并更新测试代码以适配React 18。
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/react-18-upgrade

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.

@zombieJ zombieJ marked this pull request as ready for review May 20, 2026 08:07
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (8d2ead3) to head (4e7fda9).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #359   +/-   ##
=======================================
  Coverage   97.48%   97.48%           
=======================================
  Files          19       19           
  Lines         796      796           
  Branches      189      191    +2     
=======================================
  Hits          776      776           
  Misses         20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

Copy link
Copy Markdown

@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 upgrades the project to React 18, updating peer and development dependencies including React, React DOM, and testing libraries like @testing-library/react and enzyme. Additionally, it updates test files to wrap scrollTo calls within act() blocks to ensure compatibility with React 18's rendering behavior. I have no feedback to provide as there were no review comments.

@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 20, 2026

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@​13.4.010010010087100

View full report

@zombieJ zombieJ force-pushed the codex/react-18-upgrade branch from eb6a208 to 4e7fda9 Compare May 20, 2026 08:15
@zombieJ zombieJ merged commit 5334600 into master May 20, 2026
11 of 12 checks passed
@zombieJ zombieJ deleted the codex/react-18-upgrade branch May 20, 2026 08:20
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