Skip to content

test: use playwright browser locators in Button and TreeView tests - #8527

Merged
tay1orjones merged 6 commits into
mainfrom
tay1orjones-testing-api-migration
Oct 20, 2026
Merged

tay1orjones merged 6 commits into
mainfrom
tay1orjones-testing-api-migration

Conversation

@tay1orjones

@tay1orjones tay1orjones commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Document the hybrid locator/RTL pattern and its exceptions.

Changed

  • Use Vitest browser locators, browser-backed interactions, and condition-based assertions in Button and TreeView.

Removed

  • Fixed sleeps and waiting helpers in the pilot suites.

Rollout strategy

  • No changes needed in github/github-ui
  • Needs changes in github/github-ui
  • Ships with feature flag(s)
  • Not sure
  • None

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 React act boundaries; 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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3051e4e7-3e74-4dcd-b1f4-1314e3b9b56e
@changeset-bot

changeset-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: aa67d0f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@tay1orjones tay1orjones added the skip changeset This change does not need a changelog label Oct 12, 2026
@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tay1orjones tay1orjones changed the title pilot browser locators in Button and TreeView tests test: use playwright browser locators in Button and TreeView tests Oct 14, 2026
@tay1orjones

Copy link
Copy Markdown
Contributor Author

My understanding is that integration tests aren't needed when changing only test files, but please correct me if I'm wrong here.

@tay1orjones tay1orjones added integration-tests: skipped manually Changes in this PR do not require an integration test and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Oct 14, 2026
@tay1orjones
tay1orjones marked this pull request as ready for review October 14, 2026 19:14
@tay1orjones
tay1orjones requested a review from a team as a code owner October 14, 2026 19:14
@tay1orjones
tay1orjones requested review from joshblack and a balanced review from Copilot and removed request for Copilot October 14, 2026 19:14
@tay1orjones
tay1orjones enabled auto-merge October 14, 2026 19:35

@joshblack joshblack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread contributor-docs/testing.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it'd be worth rolling this into a testing skill similar to what we do for style-guide or not really?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm happy to try it out in a follow up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshblack curious what you think 👀 #8572

@tay1orjones
tay1orjones added this pull request to the merge queue Oct 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 14, 2026
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
Copilot AI balanced review requested due to automatic review settings October 19, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 act imports.
  • 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

@tay1orjones

Copy link
Copy Markdown
Contributor Author

@copilot resolve conflicts

…pi-migration

# Conflicts:
#	packages/react/src/TreeView/TreeView.test.tsx

Co-authored-by: tay1orjones <3360588+tay1orjones@users.noreply.github.com>

Copilot AI commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve conflicts

Resolved the conflicts with main in merge commit 79f3d38. Preserved the TreeView regression tests and adapted the new IconButton tests to browser locators; the targeted suites pass (123 tests).

@tay1orjones tay1orjones added integration-tests: skipped manually Changes in this PR do not require an integration test and removed integration-tests: skipped manually Changes in this PR do not require an integration test labels Oct 19, 2026
@github-actions
github-actions Bot temporarily deployed to storybook-preview-8527 October 19, 2026 20:13 Inactive
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
@github-actions
github-actions Bot temporarily deployed to storybook-preview-8527 October 20, 2026 14:37 Inactive
@tay1orjones
tay1orjones added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit ffa1708 Oct 20, 2026
54 checks passed
@tay1orjones
tay1orjones deleted the tay1orjones-testing-api-migration branch October 20, 2026 15:43

This branch was successfully deployed

1 active and 1 inactive deployments
storybook-preview-8527 — aa67d0f7 Deployed Oct 20, 2026 by github-actions[bot]
github-pages — aa67d0f7 Deployed Oct 20, 2026 by tay1orjones via deploy-preview #33771
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: skipped manually Changes in this PR do not require an integration test skip changeset This change does not need a changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants