Skip to content

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

Open
tay1orjones wants to merge 3 commits into
mainfrom
tay1orjones-testing-api-migration
Open

tay1orjones wants to merge 3 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: 442c963

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 on lines 136 to 140
### Storybook Interaction Tests

We use [Storybook interactions tests](https://storybook.js.org/docs/react/writing-tests/interaction-testing) to simulate and test some complex user interactions. They are particularly useful for cases where writing unit tests is not practical due to the limitation of the mock browser functionalities of JSDOM. For example testing out a component's overflow behaviour whose responsiveness is managed by its own dynamic width.
We use [Storybook interactions tests](https://storybook.js.org/docs/react/writing-tests/interaction-testing) to simulate and test complex user interactions in story scenarios. For example, testing a component's overflow behaviour whose responsiveness is managed by its own dynamic width.

Storybook tests are authored within the components's source directory with the file name of `interactions.stories.tsx`

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.

Honestly I think we can remove this whole section 😅 lol. These should likely use playwright instead

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.

omg I agree! Agents seem to always want to put things into play functions on stories where they should actually be in playwright tests. I bet this is why. Will update.

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

@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

This branch was successfully deployed

2 active deployments
storybook-preview-8527 — 442c9630 Deployed Oct 13, 2026 by github-actions[bot]
github-pages — 442c9630 Deployed Oct 13, 2026 by tay1orjones via deploy-preview #33633
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.

2 participants