Skip to content

refactor: update tests from Jest to Vitest #6214

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 2 commits into from
Jun 17, 2025

Conversation

joshblack
Copy link
Member

Part of: https://github.com/github/primer/issues/5336

Changelog

New

Changed

  • Update the following test files from Jest to VItest
    • FormControl.Validation
    • Pagehead
    • BaseStyles
    • Caret
    • CheckboxOrRadioGroup
    • SideNav
    • SubNavLink
    • ThemeProvider
    • filterObject
    • theme
    • themeGet
    • useSafeTimeout
    • SkeletonText

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 the Public API.

@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 16:29
@joshblack joshblack requested a review from a team as a code owner June 17, 2025 16:29
@joshblack joshblack requested a review from jonrohan June 17, 2025 16:29
Copy link

changeset-bot bot commented Jun 17, 2025

⚠️ No Changeset found

Latest commit: b7a7271

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 Jun 17, 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 tests from Jest to Vitest, updates test configurations, and refreshes snapshots to Vitest format.

  • Replace Jest imports and APIs with Vitest equivalents across many test files
  • Update vitest.config.browser.mts and jest.config.js to include/exclude the migrated tests
  • Refresh and expand snapshots for BaseStyles, SubNavLink, and ThemeProvider to the new Vitest snapshot schema

Reviewed Changes

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

Show a summary per file
File Description
packages/react/vitest.config.browser.mts Added explicit patterns for newly migrated test files
packages/react/src/hooks/tests/useSafeTimeout.test.tsx New Vitest-based tests for useSafeTimeout hook
packages/react/src/tests/* Converted many tests (Pagehead, Caret, BaseStyles, etc.) to Vitest syntax
packages/react/src/tests/snapshots/*.snap Refreshed snapshots for Vitest, showing full render object
packages/react/jest.config.js Updated ignore patterns to account for files moved to Vitest
Comments suppressed due to low confidence (2)

packages/react/src/tests/snapshots/SubNavLink.test.tsx.snap:1

  • The snapshot captures the entire render result with all utility methods, which is brittle. Instead, use render(<SubNav.Link />).asFragment() to snapshot only the HTML fragment you care about.
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

packages/react/src/tests/snapshots/BaseStyles.test.tsx.snap:1

  • Similarly, this snapshot includes low-level style hashes and full markup. Consider using asFragment() or container.firstChild to capture only the relevant element and its styles.
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

import {render, behavesAsComponent} from '../utils/testing'
import {render as HTMLRender} from '@testing-library/react'
import axe from 'axe-core'
import {render} from '@testing-library/react'
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

The axe-based accessibility test was removed. To maintain a11y coverage, re-add a test using axe.run to assert toHaveNoViolations().

Copilot uses AI. Check for mistakes.

import {render, behavesAsComponent, checkExports} from '../utils/testing'
import {render as HTMLRender} from '@testing-library/react'
import axe from 'axe-core'
import {screen, render} from '@testing-library/react'
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

The axe accessibility test was dropped during migration. Please reintroduce an a11y test (e.g., using axe.run) to ensure no violations for SideNav and its links.

Copilot uses AI. Check for mistakes.

@@ -1,44 +1,21 @@
import {render, within} from '@testing-library/react'
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

The within import is not used in this file. Removing unused imports improves readability and avoids confusion.

Copilot uses AI. Check for mistakes.

import {render, checkExports} from '../utils/testing'
import {render as HTMLRender} from '@testing-library/react'
import axe from 'axe-core'
import type {CaretProps} from '../Caret'
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

The imported CaretProps type is not used in this test. Consider removing it to keep the file focused.

Suggested change
import type {CaretProps} from '../Caret'
// Removed unused import

Copilot uses AI. Check for mistakes.

Copy link
Contributor

github-actions bot commented Jun 17, 2025

size-limit report 📦

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

@joshblack joshblack added the skip changeset This change does not need a changelog label Jun 17, 2025
@joshblack joshblack enabled auto-merge June 17, 2025 16:39
@github-actions github-actions bot requested a deployment to storybook-preview-6214 June 17, 2025 16:42 Abandoned
@joshblack joshblack added this pull request to the merge queue Jun 17, 2025
Merged via the queue into main with commit 0e0abc0 Jun 17, 2025
35 checks passed
@joshblack joshblack deleted the refactor/update-tests-to-vitest-jun-17 branch June 17, 2025 17:06
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy