Repository navigation
test: keep antd styles out of jsdom to speed up scene tests - #1317
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
清空 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
What Changed
src/test/setup.ts: keep the style nodes antd injects empty during unit tests; keep onedisplay: nonerule for antd's hidden state classessrc/test/setup.test.ts: two guard tests for the aboveObjectTypeResourceGraph.test.tsx,ObjectMetricTrialDrawer.test.tsx: accessible-name matchers tolerate missing whitespaceDEVELOPMENT_GUIDE.md: note that unit tests run without antd stylesWhy
ci-qualitytakes about 10 minutes and is bounded by single test files, not by sharding. On a recent full run onmain,AgentConfigScene.test.tsxtook 647s andEvalWorkspaceScene.test.tsx416s; the 10 slowest files were 57% of all test time. A CPU profile ofAgentConfigScene.test.tsxshowed 87% of the time in jsdom'sgetComputedStyle: 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
data-rc-orderbefore writing the CSS. The setup overridesHTMLStyleElement.prototype.innerHTMLso those nodes stay empty; styles a test writes itself are untouched.display: nonestate classes. A wildcard ([class*="-hidden"]) was tried first and wrongly hidant-form-item-required-mark-hiddenlabels.Descriptionsrow). The affected matchers now accept either form.src/test/setup.tsis referenced only fromtest.setupFiles.Testing
Test notes:
vitest --run --maxWorkers=50%, 14-core arm64): 671 files / 6575 tests passed in 131s. After merging the latestmain, the 35 test files changed there were rerun and pass.AgentConfigScene.test.tsxalone: 310s before, 15s after, 65/65 passing.tsc -b,vite build,pnpm audit --prod.Risk & Rollback
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.data-rc-order, tests slow down again rather than break; a guard test insetup.test.tsfails in that case.Additional Notes
ci-qualityrun took 365s against 676–797s for recent full runs onmain; the slowest unit shard took 205s against 652s. The run is now bounded by the serialci-quality checksjob (346s).ant-form-item-hidden, added after the automated review pointed it out.🤖 Generated with Claude Code