Skip to content

Update vitest config and TreeView tests to Vitest #6236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 27, 2025

Conversation

joshblack
Copy link
Member

Updates our TreeView tests from Jest to Vitest. This PR also includes some changes I needed to land in order to convert the tests, namely:

  • The vitest browser environment is now set up so that our styles should match how they appear in storybook
  • Our test suite will now fail in CI if a console.* method is logged (helps to prevent act() warnings from sneaking in)

Changelog

New

Changed

  • Update TreeView tests from Jest to Vitest
  • Update vitest setup files
    • Split browser-config into specific setup file
    • Use shared setup config across Node.js and browser tests
  • Use postcss preset for transforming CSS files in vitest

Removed

Rollout strategy

  • None; if selected, include a brief description as to why

This is a change to our internal test setup and does not impact our public API.

@Copilot Copilot AI review requested due to automatic review settings June 25, 2025 21:54
@joshblack joshblack requested a review from a team as a code owner June 25, 2025 21:54
@joshblack joshblack requested a review from hectahertz June 25, 2025 21:54
Copy link

changeset-bot bot commented Jun 25, 2025

⚠️ No Changeset found

Latest commit: 08fc3ca

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

@joshblack joshblack added the skip changeset This change does not need a changelog label Jun 25, 2025
@github-actions github-actions bot added the staff Author is a staff member label Jun 25, 2025
@joshblack joshblack requested a review from TylerJDev June 25, 2025 21:54
@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 Jun 25, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates existing Jest tests to Vitest for the TreeView suite and refines the Vitest setup for both Node and browser environments, including style transformations and stricter console logging checks.

  • Convert TreeView tests from Jest to Vitest (imports, timers, userEvent)
  • Update Vitest configs to include shared setup files, PostCSS, and browser CSS
  • Introduce vitest-fail-on-console in common setup and remove legacy cleanup

Reviewed Changes

Copilot reviewed 18 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/react/vitest.config.mts Added shared setup.ts for node-based tests
packages/react/vitest.config.browser.mts Configured PostCSS, scoped class names, and browser setup files
packages/react/src/hooks/tests/useAnchoredPosition.test.tsx Switched to async/waitFor and Vitest imports
packages/react/src/TreeView/TreeView.test.tsx Fully migrated TreeView tests to Vitest; timers, userEvent, act
packages/react/config/vitest/setup.ts Replaced manual cleanup with vitest-fail-on-console
packages/react/config/vitest/browser/setup.ts Added global CSS imports and DOM cleanup for browser tests
packages/react/src/AnchoredOverlay/AnchoredOverlay.test.tsx Converted tests to async/userEvent and Vitest imports
Comments suppressed due to low confidence (5)

packages/react/src/TreeView/TreeView.test.tsx:211

  • This test body is entirely commented out, so no assertions run. Either remove or re-enable the test logic to ensure this behavior is actually verified.
  it('should include `aria-expanded` when a SubTree contains content', async () => {

packages/react/src/TreeView/TreeView.test.tsx:1467

  • You replaced an async findByRole with a synchronous getByRole for an element that appears during an async state. This may flake if the loading node isn't present immediately. Consider using findByRole or waitFor.
    const loadingItem = getByRole('treeitem', {name: 'Loading...'})

packages/react/src/TreeView/TreeView.test.tsx:1530

  • vi.waitFor isn't imported; Vitest doesn’t expose waitFor on vi by default. Import waitFor from @testing-library/react (or from Vitest if supported) to use it.
    await vi.waitFor(() => {

packages/react/config/vitest/setup.ts:3

  • You removed the cleanup() call for React testing in the node setup. Without calling cleanup after each test, rendered DOM nodes may leak between tests. Re-introduce cleanup() in an afterEach hook.
const failConsoleMessages = process.env.CI === 'true'

packages/react/src/AnchoredOverlay/AnchoredOverlay.test.tsx:1

  • act should be imported from @testing-library/react (or react-dom/test-utils), not from react itself. Please correct the import to ensure the testing helper works correctly.
import {act, useCallback, useState} from 'react'

@@ -18,16 +18,19 @@ const Component = ({callback}: {callback: (hookReturnValue: ReturnType<typeof us
)
}

it('should should return a position', () => {
it('should should return a position', async () => {
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

[nitpick] The test description has a duplicated word: should should. Please remove the extra should so it reads should return a position.

Suggested change
it('should should return a position', async () => {
it('should return a position', async () => {

Copilot uses AI. Check for mistakes.

Comment on lines +278 to +280
await act(async () => {
await user.click(button)
})
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

[nitpick] Wrapping user.click in act is usually unnecessary with @testing-library/user-event, which already handles React act internally. You can simplify to await user.click(button).

Suggested change
await act(async () => {
await user.click(button)
})
await user.click(button)

Copilot uses AI. Check for mistakes.

expect(button).toHaveFocus()

// Move focus to tree
const item1 = getByRole('treeitem', {name: /Item 1/})
const toggle = item1.querySelector('.PRIVATE_TreeView-item-toggle')
await user.click(toggle!)
const toggle = item1.querySelector('.PRIVATE_TreeView-item-toggle') as HTMLElement
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

Querying by an internal class name is brittle. Consider exposing a data-testid or using an accessible query (e.g., getByRole or getByLabelText) to select the toggle element.

Copilot uses AI. Check for mistakes.

@joshblack joshblack enabled auto-merge June 25, 2025 21:56
Copy link
Contributor

github-actions bot commented Jun 25, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 92.51 KB (0%)
packages/react/dist/browser.umd.js 92.56 KB (0%)

@github-actions github-actions bot requested a deployment to storybook-preview-6236 June 25, 2025 21:59 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-6236 June 25, 2025 22:12 Inactive
@github-actions github-actions bot requested a deployment to storybook-preview-6236 June 25, 2025 22:33 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-6236 June 25, 2025 22:47 Inactive
@github-actions github-actions bot requested a deployment to storybook-preview-6236 June 26, 2025 19:25 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-6236 June 26, 2025 19:38 Inactive
Copy link
Member

@TylerJDev TylerJDev left a comment

Choose a reason for hiding this comment

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

LGTM!

@joshblack joshblack added this pull request to the merge queue Jun 27, 2025
Merged via the queue into main with commit 5ba1d6c Jun 27, 2025
35 checks passed
@joshblack joshblack deleted the refactor/update-tests-to-vitest-6-25 branch June 27, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm skip changeset This change does not need a changelog staff Author is a staff member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants