Skip to content

test: keep antd styles out of jsdom to speed up scene tests - #1317

Merged
sh00tg0a1 merged 3 commits into
mainfrom
chore/test-skip-antd-css
Nov 11, 2026
Merged

sh00tg0a1 merged 3 commits into
mainfrom
chore/test-skip-antd-css

Conversation

@sh00tg0a1

@sh00tg0a1 sh00tg0a1 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Pull Request

What Changed

  • src/test/setup.ts: keep the style nodes antd injects empty during unit tests; keep one display: none rule for antd's hidden state classes
  • src/test/setup.test.ts: two guard tests for the above
  • ObjectTypeResourceGraph.test.tsx, ObjectMetricTrialDrawer.test.tsx: accessible-name matchers tolerate missing whitespace
  • DEVELOPMENT_GUIDE.md: note that unit tests run without antd styles

Why

  • Related Issue: none; submitted directly at the maintainer's request.
  • Related Feature: not applicable
  • Background: ci-quality takes about 10 minutes and is bounded by single test files, not by sharding. On a recent full run on main, AgentConfigScene.test.tsx took 647s and EvalWorkspaceScene.test.tsx 416s; the 10 slowest files were 57% of all test time. A CPU profile of AgentConfigScene.test.tsx showed 87% of the time in jsdom's getComputedStyle: each *ByRole({ name }) query checks every node for hidden state, and jsdom 27 matches every stylesheet rule against the element. antd's CSS-in-JS puts thousands of rules in <head>.

How

  • Key implementation points:
    • rc-util tags every style node it injects with data-rc-order before writing the CSS. The setup overrides HTMLStyleElement.prototype.innerHTML so those nodes stay empty; styles a test writes itself are untouched.
    • Closed dropdowns, tooltips, popovers, drawers and inactive tab panes stay in the DOM and are hidden only by a state class, so the setup adds one rule listing antd's display: none state classes. A wildcard ([class*="-hidden"]) was tried first and wrongly hid ant-form-item-required-mark-hidden labels.
    • Without antd's layout, adjacent inline elements join without a space in accessible names (for example a Descriptions row). The affected matchers now accept either form.
  • Breaking changes (API, config, database, etc.): none. Test environment only; src/test/setup.ts is referenced only from test.setupFiles.

Testing

  • Unit tests passed locally
  • Integration tests passed locally — not applicable, test-only change
  • Verified in test environment — not applicable

Test notes:

  • Full suite locally (vitest --run --maxWorkers=50%, 14-core arm64): 671 files / 6575 tests passed in 131s. After merging the latest main, the 35 test files changed there were rerun and pass.
  • AgentConfigScene.test.tsx alone: 310s before, 15s after, 65/65 passing.
  • Alternative measured: upgrading jsdom to 31.0.0 without the setup change gives the same speed (125s) but fails 82 tests in 33 files.
  • Pre-commit checks run: format, license headers, type-aware ESLint (whole repo), tsc -b, vite build, pnpm audit --prod.

Risk & Rollback

  • Potential risks:
    • Tests no longer see antd's CSS apart from the hidden state classes. An assertion that relies on any other antd style would not hold.
    • A negative assertion such as queryByRole("row", { name: "label value" }) could pass vacuously now that the name has no space. One such case was found and fixed; the search covered common roles and single-line calls only.
    • The hidden state class list is hand-written from antd 5.29 and needs updating if antd adds one.
    • If antd stops tagging its style nodes with data-rc-order, tests slow down again rather than break; a guard test in setup.test.ts fails in that case.
  • Rollback plan: revert this commit.

Additional Notes

  • CI on this PR (full unit scope): the whole ci-quality run took 365s against 676–797s for recent full runs on main; the slowest unit shard took 205s against 652s. The run is now bounded by the serial ci-quality checks job (346s).
  • The hidden state list also covers ant-form-item-hidden, added after the automated review pointed it out.

🤖 Generated with Claude Code

sh00tg0a1 and others added 2 commits November 11, 2026 14:19
jsdom answers getComputedStyle() by matching every stylesheet rule against
the element, and Testing Library asks for it on each node when a *ByRole
query resolves an accessible name. With antd's CSS-in-JS rules in <head>,
scene tests spent about 90% of their CPU time in selector matching; one
file alone took over ten minutes on CI and bounded the whole run.

The test setup now keeps the style nodes antd injects empty and only keeps
a display:none rule for antd's hidden state classes, so closed overlays stay
out of role queries. Two tests that matched accessible names relying on
antd's layout now tolerate missing whitespace.

Co-Authored-By: Claude <noreply@anthropic.com>
@sh00tg0a1 sh00tg0a1 added the by-agent Issue or pull request produced by an agent label Nov 11, 2026
Comment thread src/test/setup.ts Resolved

@github-actions github-actions 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.

清空 rc-util 注入样式、只保留隐藏状态类规则的思路成立,测试与文档改动一致;没有阻塞项。保留列表漏了 Form.Item hidden 用的状态类,已贴 inline 建议补上。

影响范围与未覆盖面
  • 影响范围:所有 jsdom 单测都会改走这套样式环境:凡是依赖 antd CSS 隐藏、却不在列表里的元素,在测试里会被当成可见,*ByRole 能查到它,toBeVisible() 也会断言成功(假阳性)。
  • 未覆盖:本地没装 node_modules,没有对照 antd 5.29 / rc-util 的源码逐条核对 display:none 状态类的完整列表,也没有核实 injectCSS/updateCSS 是否都走 innerHTML 写入。

有异议或想再评一轮,请回复 /review——普通回帖不会触发复评,且回帖人需为本仓 OWNER/MEMBER/COLLABORATOR。

Form.Item hidden relies on the ant-form-item-hidden state class, which the
hidden state list in the test setup missed.

Co-Authored-By: Claude <noreply@anthropic.com>
@sh00tg0a1
sh00tg0a1 marked this pull request as ready for review November 11, 2026 13:52
@sh00tg0a1
sh00tg0a1 merged commit 3f11f07 into main Nov 11, 2026
31 checks passed
@sh00tg0a1
sh00tg0a1 deleted the chore/test-skip-antd-css branch November 11, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

by-agent Issue or pull request produced by an agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant