-
Notifications
You must be signed in to change notification settings - Fork 622
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
Conversation
|
👋 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! |
There was a problem hiding this 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
andjest.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()
orcontainer.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' |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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.
import type {CaretProps} from '../Caret' | |
// Removed unused import |
Copilot uses AI. Check for mistakes.
size-limit report 📦
|
Part of: https://github.com/github/primer/issues/5336
Changelog
New
Changed
Removed
Rollout strategy
This is a change to our internal test setup and does not impact the Public API.