Skip to content

Update tests from Jest to Vitest #6112

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 18 commits into from
May 28, 2025

Conversation

joshblack
Copy link
Member

@joshblack joshblack commented May 22, 2025

Continue our refactor of tests from Jest to Vitest.

Changelog

New

Changed

  • Update the following tests from Jest to Vitest:
    • Radio
    • RadioGroup
    • RelativeTime
    • ProgressBar
    • ScrollableRegion
    • Textarea

Removed

Copy link

changeset-bot bot commented May 22, 2025

⚠️ No Changeset found

Latest commit: a0cc40e

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

@github-actions github-actions bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels May 22, 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

github-actions bot commented May 22, 2025

size-limit report 📦

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

@joshblack joshblack added the skip changeset This change does not need a changelog label May 22, 2025
@joshblack joshblack marked this pull request as ready for review May 22, 2025 19:14
@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 19:14
@joshblack joshblack requested a review from a team as a code owner May 22, 2025 19:14
@joshblack joshblack requested a review from hectahertz May 22, 2025 19:14
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 continues the migration of component tests from Jest to Vitest by updating configuration files and rewriting several test suites using Vitest’s APIs and React Testing Library.

  • Added Vitest test globs for newly migrated components in vitest.config.mts
  • Rewrote tests for Textarea, ScrollableRegion, RelativeTime, RadioGroup, Radio, ProgressBar to use Vitest and RTL
  • Updated snapshots and test setup for React 18’s act environment

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/react/vitest.config.mts Added test globs for Radio, RadioGroup, RelativeTime, ProgressBar, ScrollableRegion, Textarea
packages/react/src/Textarea/Textarea.test.tsx Replaced Jest utils with Vitest imports and RTL patterns
packages/react/src/ScrollableRegion/ScrollableRegion.test.tsx Switched global to window ResizeObserver and updated style assertions
packages/react/src/RelativeTime/RelativeTime.test.tsx Removed Jest helpers, now uses Vitest and RTL
packages/react/src/RadioGroup/RadioGroup.test.tsx Replaced Jest mocks with vi and removed legacy helpers
packages/react/src/Radio/Radio.test.tsx Switched from Jest to Vitest for mocks and assertions
packages/react/src/ProgressBar/snapshots/ProgressBar.test.tsx.snap Updated snapshot header and output for Vitest
packages/react/src/ProgressBar/ProgressBar.test.tsx Replaced Jest helpers with Vitest and RTL rendering
packages/react/jest.config.js Added paths for newly migrated test directories
packages/react/config/vitest/setup.ts Enabled IS_REACT_ACT_ENVIRONMENT for React 18 tests
Comments suppressed due to low confidence (1)

packages/react/src/RelativeTime/RelativeTime.test.tsx:3

  • Accessibility tests using axe were removed during this migration. Consider re-adding an axe-based test (e.g. expect(await axe.run(container)).toHaveNoViolations()) to maintain accessibility coverage for .
import {render} from '@testing-library/react'

checkExports('RadioGroup', {
default: RadioGroup,
RadioGroupContext,
vi.clearAllMocks()
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

The afterAll block clears mock calls but does not restore the original console.warn implementation. Consider using vi.restoreAllMocks() or calling mockRestore() on the spy to prevent stubbing console.warn in other tests.

Suggested change
vi.clearAllMocks()
vi.restoreAllMocks()

Copilot uses AI. Check for mistakes.

Comment on lines +4 to +29
{
"asFragment": [Function],
"baseElement": <body>



exports[`ProgressBar respects the "progress" prop 1`] = `
.c0 {
background-color: var(--bgColor-success-emphasis,var(--color-success-emphasis,#1f883d));
}

<span
className="ProgressBarContainer"
data-progress-bar-size="default"
data-progress-display="block"
>
<span
aria-label="Upload test.png"
aria-valuemax={100}
aria-valuemin={0}
aria-valuenow={80}
className="c0 ProgressBarItem"
role="progressbar"
style={
{
"--progress-bg": "var(--bgColor-success-emphasis)",
"--progress-width": "80%",
}
}
/>
</span>
<div>
<span
class="_ProgressBarContainer_1bos7_27"
data-progress-bar-size="default"
data-progress-display="block"
>
<span
aria-label="Upload test.png"
aria-valuemax="100"
aria-valuemin="0"
aria-valuenow="80"
class="sc-aXZVg lfjCwU _ProgressBarItem_1bos7_11"
role="progressbar"
style="--progress-width: 80%; --progress-bg: var(--bgColor-success-emphasis);"
/>
</span>
</div>
</body>,
"container": <div>
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

[nitpick] The snapshot includes the full Testing Library API, making it very verbose. Consider switching to a DOM-only snapshot (e.g. via asFragment() or toJSON()) to keep snapshots concise and easier to review.

Copilot uses AI. Check for mistakes.

Comment on lines +41 to +42
expect(screen.getByTestId('container')).toHaveStyle('overflow: auto')
expect(screen.getByTestId('container')).toHaveStyle('position: relative')
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

The toHaveStyle matcher only checks inline style attributes, but overflow and position come from CSS. Use getComputedStyle(container).overflow (and similarly for position) to assert these style rules reliably.

Suggested change
expect(screen.getByTestId('container')).toHaveStyle('overflow: auto')
expect(screen.getByTestId('container')).toHaveStyle('position: relative')
const containerStyles = getComputedStyle(screen.getByTestId('container'));
expect(containerStyles.overflow).toBe('auto');
expect(containerStyles.position).toBe('relative');

Copilot uses AI. Check for mistakes.

@github-actions github-actions bot requested a deployment to storybook-preview-6112 May 22, 2025 19:18 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-6112 May 22, 2025 19:32 Inactive
Copy link
Contributor

@hectahertz hectahertz left a comment

Choose a reason for hiding this comment

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

🙌🏻

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions bot requested a deployment to storybook-preview-6112 May 27, 2025 15:06 Abandoned
@joshblack joshblack added this pull request to the merge queue May 28, 2025
auto-merge was automatically disabled May 28, 2025 16:53

Pull Request is not mergeable

Merged via the queue into main with commit 41b4bdb May 28, 2025
35 checks passed
@joshblack joshblack deleted the refactor/update-tests-to-vitest-may-22-2025 branch May 28, 2025 16:59
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.

3 participants