-
Notifications
You must be signed in to change notification settings - Fork 624
Migrate batch of components from Jest to Vitest #6356
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
|
Co-authored-by: joshblack <3901764+joshblack@users.noreply.github.com>
👋 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! |
size-limit report 📦
|
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.
@copilot remove the snapshot test that is currently failing for Hidden and fix the type errors that show up when running type-check
Co-authored-by: joshblack <3901764+joshblack@users.noreply.github.com>
Fixed both issues in commit c325650:
All tests are now passing and |
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 three React components (Link, Popover, and Header) from Jest to Vitest testing framework, along with updating an existing Hidden component snapshot. The migration is part of a broader effort to modernize the testing infrastructure for the Primer React design system.
Key changes include:
- Migrated test files from Jest to Vitest with updated imports and syntax
- Replaced snapshot-based assertions with explicit DOM attribute and style checks
- Updated configuration files to route these components to Vitest instead of Jest
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
vitest.config.browser.mts | Added Header, Link, and Popover test patterns to Vitest include list |
jest.config.js | Added Header, Link, and Popover paths to Jest ignore patterns |
Link/tests/Link.test.tsx | Migrated from Jest to Vitest with DOM assertions replacing snapshots |
Popover/Popover.test.tsx | Migrated from Jest to Vitest, replaced snapshots with attribute checks |
Header/Header.test.tsx | Migrated from Jest to Vitest, updated test assertions to check DOM properties |
Hidden/Hidden.test.tsx | Removed snapshot test case |
Various snapshot files | Updated snapshot headers from Jest to Vitest format |
}) | ||
|
||
it('respects hoverColor prop', () => { | ||
expect(render(<Link hoverColor="accent.fg" />)).toMatchSnapshot() | ||
const {container} = render(<Link hoverColor="accent.fg" />) | ||
expect(container.firstChild).toHaveStyle('--fgColor-accent: #0969da') |
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 hardcoded color value '#0969da' makes this test brittle to design token changes. Consider using a more flexible assertion or checking for the CSS custom property presence instead of its exact value.
expect(container.firstChild).toHaveStyle('--fgColor-accent: #0969da') | |
expect(container.firstChild).toHaveStyle('--fgColor-accent') |
Copilot uses AI. Check for mistakes.
it('respects the "sx" prop when "muted" prop is also passed', () => { | ||
const {container} = render(<Link muted sx={{color: 'fg.onEmphasis'}} />) | ||
expect(container.firstChild).toHaveAttribute('data-muted', 'true') | ||
expect(container.firstChild).toHaveStyle('color: rgb(89, 99, 110)') |
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 hardcoded RGB color value 'rgb(89, 99, 110)' makes this test brittle to design token changes. Consider using a more flexible assertion that doesn't rely on exact color values.
expect(container.firstChild).toHaveStyle('color: rgb(89, 99, 110)') | |
expect(container.firstChild).toHaveStyle('color: var(--fgColor-onEmphasis)') |
Copilot uses AI. Check for mistakes.
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.
@copilot merge in the latest changes from main
and address the merge conflicts
Resolved conflicts in: - packages/react/jest.config.js: Added both Portal and Popover to modulePathIgnorePatterns - packages/react/vitest.config.browser.mts: Added both Portal and Popover to include patterns
Merged latest changes from main and resolved all conflicts in commit afbaf71. Both Portal (from main) and Popover (from our branch) are now properly included in the Jest and Vitest configurations. All 55 tests are passing successfully. |
This PR migrates a batch of components from Jest to Vitest testing framework as part of the ongoing migration effort.
Components Migrated
Changes Made
Configuration Updates
vitest.config.browser.mts
include patternsjest.config.js
modulePathIgnorePatternsTest File Migrations
describe
,expect
,it
,vi
)render
fromutils/testing
with@testing-library/react
behavesAsComponent
usage (replaced with direct component tests)checkExports
usage (no longer needed in Vitest migration)toHaveNoViolations
globalThis.console
instead ofglobal.console
)Test Improvements
All 38 tests across the 5 components are now passing with Vitest! 🎉
Fixes #6355.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.