Repository navigation
test: use playwright browser locators in Button and TreeView tests - #8527
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3051e4e7-3e74-4dcd-b1f4-1314e3b9b56e
|
|
Restore the programmatic click for the pointer-only TreeView chevron. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3051e4e7-3e74-4dcd-b1f4-1314e3b9b56e
Keep RTL rendering and scoped act boundaries for manual updates. Await Vitest browser interactions directly without forcing act mode for the entire browser suite. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3051e4e7-3e74-4dcd-b1f4-1314e3b9b56e
|
|
||
| // @ts-expect-error this is needed for act() from React | ||
| // @see https://react.dev/reference/react/act#error-the-current-testing-environment-is-not-configured-to-support-act | ||
| globalThis.IS_REACT_ACT_ENVIRONMENT = true |
There was a problem hiding this comment.
Removing this override lets Button and TreeView tests await browser interactions directly. The eight test suites unrelated to those (DataTableGrouping, UnderlinePanels, etc) still perform manual timer, hydration, or observer updates. RTL’s act enables the environment for those operations and restores it afterward, whereas React’s raw act doesn’t.
|
My understanding is that integration tests aren't needed when changing only test files, but please correct me if I'm wrong here. |
joshblack
left a comment
There was a problem hiding this comment.
Looks great! Just have a couple comments/questions. If you're interested, would be great to have a testing skill that loads testing.md (or I guess translate testing.md into the skill plus references format we've been doing) but that could totally be in a separate PR
There was a problem hiding this comment.
Do you think it'd be worth rolling this into a testing skill similar to what we do for style-guide or not really?
There was a problem hiding this comment.
Yeah I'm happy to try it out in a follow up
There was a problem hiding this comment.
@joshblack curious what you think 👀 #8572
Remove the Storybook interaction testing recommendation and point component interaction tests to the browser locator pilot. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3051e4e7-3e74-4dcd-b1f4-1314e3b9b56e
There was a problem hiding this comment.
🔵 Needs a closer look
The shared act-environment change affects all browser suites, and full-suite compatibility remains unverified.
No open issues 🎉
What changed in this PR
Establishes a browser-locator migration pattern for Primer React tests while retaining React Testing Library rendering and lifecycle helpers.
Changes:
- Migrates Button and TreeView queries, interactions, and eventual assertions to Vitest browser APIs.
- Removes the global React act-environment override and standardizes manual
actimports. - Documents the hybrid testing pattern and its exceptions.
| File | Description |
|---|---|
| packages/react/src/TreeView/TreeView.test.tsx | Migrates locators and interactions while preserving explicit focus and timer checks. |
| packages/react/src/Spinner/Spinner.test.tsx | Imports act from RTL. |
| packages/react/src/Skeleton/__tests__/SkeletonBox.test.tsx | Imports act from RTL. |
| packages/react/src/ScrollableRegion/ScrollableRegion.test.tsx | Imports act from RTL. |
| packages/react/src/RelativeTime/RelativeTime.test.tsx | Imports act from RTL. |
| packages/react/src/Portal/Portal.test.tsx | Imports act from RTL. |
| packages/react/src/hooks/__tests__/useMedia.test.tsx | Imports act from RTL. |
| packages/react/src/experimental/UnderlinePanels/UnderlinePanels.test.tsx | Imports act from RTL. |
| packages/react/src/DataTable/__tests__/DataTableGrouping.test.tsx | Imports act from RTL. |
| packages/react/src/Button/__tests__/Button.test.tsx | Migrates browser queries and interactions; replaces fixed sleeps. |
| packages/react/config/vitest/browser/setup.ts | Removes the global act-environment override. |
| contributor-docs/testing.md | Documents locator migration guidance and exceptions. |
Review effort: Balanced
|
@copilot resolve conflicts |
…pi-migration # Conflicts: # packages/react/src/TreeView/TreeView.test.tsx Co-authored-by: tay1orjones <3360588+tay1orjones@users.noreply.github.com>
Resolved the conflicts with |
Import act from RTL so hydration and unmount configure the React act environment for each operation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3051e4e7-3e74-4dcd-b1f4-1314e3b9b56e
Related to github/primer#6369.
Use Button and TreeView to establish a bounded locator migration pattern before converting more browser tests. Keep RTL rendering and lifecycle APIs, along with the existing synchronous event, focus, and timer contracts.
Changelog
New
Changed
Removed
Rollout strategy
Testing & Reviewing
Run
CI=true VITEST_FAIL_ON_CONSOLE=true npm test -- --run --project=@primer/react packages/react/src/Button/__tests__/Button.test.tsx packages/react/src/TreeView/TreeView.test.tsx. Review the exact-name selectors after expansion, detached-node checks, intentional synthetic events, and fake-timer boundaries against their original assertions. Browser interactions use awaited Reactactboundaries; the pointer-only TreeView chevron retains its programmatic click.On the original pilot commit
e8d2a7b69, 20 local before/after runs measured median suite times of 60.3 -> 200.2 ms for Button and 311.8 -> 950.5 ms for TreeView, excluding startup. These measurements precede the CI fixes; they don't measure the current revision or establish a flakiness improvement.Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com