Skip to content

refactor: update tests from Jest to Vitest #6227

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 8 commits into from
Jun 23, 2025

Conversation

joshblack
Copy link
Member

@joshblack joshblack commented Jun 20, 2025

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

Changelog

New

Changed

Update the following tests from Jest to Vitest:

  • Box
  • Flash
  • InlineMessage
  • Octicon
  • Pagination
  • internal/utils
  • utils
  • storybook

Removed

Copy link

changeset-bot bot commented Jun 20, 2025

⚠️ No Changeset found

Latest commit: 06cd152

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 20, 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 Jun 20, 2025

size-limit report 📦

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

@github-actions github-actions bot requested a deployment to storybook-preview-6227 June 20, 2025 16:48 Abandoned
@joshblack joshblack added the skip changeset This change does not need a changelog label Jun 20, 2025
@github-actions github-actions bot requested a deployment to storybook-preview-6227 June 20, 2025 18:17 Abandoned
@joshblack joshblack marked this pull request as ready for review June 20, 2025 18:18
@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 18:18
@joshblack joshblack requested a review from a team as a code owner June 20, 2025 18:18
@joshblack joshblack enabled auto-merge June 20, 2025 18:18
@joshblack joshblack requested review from TylerJDev and removed request for jonrohan and francinelucca June 20, 2025 18:19
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 refactors the test suite from Jest to Vitest across several packages, updating test configs, test files, and story imports to align with Vitest’s APIs and eliminate legacy Jest patterns.

  • Updated Vitest configurations to include React plugin, global defines, and expanded test globs.
  • Migrated individual component tests (e.g., Box, Flash, InlineMessage, Octicon, Pagination, internal/utils, utils, storybook) from Jest to Vitest, removing snapshots and axe checks.
  • Fixed import paths for ReactRouterLikeLink in stories and examples.

Reviewed Changes

Copilot reviewed 22 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/react/vitest.config.mts Added React plugin, defined __DEV__, and expanded test include
packages/react/vitest.config.browser.mts Added test globs for Box, Flash, InlineMessage, Octicon, Pagination, internal/utils, and utils
packages/react/src/stories/deprecated/ActionList.stories.tsx Updated ReactRouterLikeLink import path
packages/react/src/internal/utils/tests/toggleSxComponent.test.tsx Migrated to Vitest imports and updated style assertions
packages/react/src/internal/utils/tests/toggleStyledComponent.test.tsx Migrated to Vitest imports and updated style assertions
packages/react/src/internal/utils/tests/hasInteractiveNodes.test.ts Added Vitest imports
packages/react/src/internal/utils/tests/getResponsiveAttributes.test.ts Added Vitest imports
packages/react/src/tests/storybook.test.tsx Migrated to Vitest, replaced require with dynamic import, and added top-level await
packages/react/src/tests/Pagination/Pagination.test.tsx Removed old Jest-based Pagination test
packages/react/src/Pagination/PaginationModel.test.tsx Migrated to Vitest imports and updated model import path
packages/react/src/Pagination/Pagination.test.tsx Added new Vitest-based Pagination test
packages/react/src/Pagination/Pagination.features.stories.tsx Fixed ReactRouterLikeLink import path
packages/react/src/Octicon/Octicon.test.tsx Migrated to Vitest, removed legacy utils/axe tests, added new assertions
packages/react/src/NavList/NavList.test.tsx Fixed ReactRouterLikeLink import path
packages/react/src/NavList/NavList.stories.tsx Fixed ReactRouterLikeLink import path
packages/react/src/InlineMessage/InlineMessage.test.tsx Migrated to Vitest imports
packages/react/src/Flash/tests/Flash.test.tsx Migrated to Vitest imports
packages/react/src/Button/LinkButton.features.stories.tsx Fixed ReactRouterLikeLink import path
packages/react/src/Box/snapshots/Box.test.tsx.snap Removed Jest snapshot file for Box
packages/react/src/Box/Box.test.tsx Introduced comprehensive Vitest tests for Box styling props
packages/react/src/ActionList/ActionList.examples.stories.tsx Fixed ReactRouterLikeLink import path
packages/react/jest.config.js Updated Jest config to include newly migrated tests
Comments suppressed due to low confidence (1)

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

  • Accessibility tests using axe-core have been removed. It’s helpful to include an aXe accessibility check to catch regressions in component markup.
import {render, screen} from '@testing-library/react'

})
})

function getClassName(className: string): string {
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

The helper getClassName assumes two classes are always generated and picks the second one, which can be brittle if class generation changes. Consider using a regex or filtering logic to reliably select the correct class, or using a utility to extract the generated class.

Copilot uses AI. Check for mistakes.

Comment on lines +110 to +129
function getCSSRuleForClass(className: string, mediaText?: string): CSSStyleRule {
for (const sheet of document.styleSheets) {
for (const rule of sheet.cssRules) {
if (mediaText) {
if (rule instanceof CSSMediaRule && rule.media.mediaText === mediaText) {
for (const innerRule of rule.cssRules) {
if (innerRule instanceof CSSStyleRule && innerRule.selectorText === `.${className}`) {
return innerRule
}
}
}
} else if (rule instanceof CSSStyleRule) {
if (rule.selectorText === `.${className}`) {
return rule
}
}
}
}

throw new Error(`CSS rule for class "${className}" not found`)
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

Searching through all document.styleSheets and their rules can be expensive and might slow down tests. Consider caching the target stylesheet or limiting the search scope to improve test performance.

Suggested change
function getCSSRuleForClass(className: string, mediaText?: string): CSSStyleRule {
for (const sheet of document.styleSheets) {
for (const rule of sheet.cssRules) {
if (mediaText) {
if (rule instanceof CSSMediaRule && rule.media.mediaText === mediaText) {
for (const innerRule of rule.cssRules) {
if (innerRule instanceof CSSStyleRule && innerRule.selectorText === `.${className}`) {
return innerRule
}
}
}
} else if (rule instanceof CSSStyleRule) {
if (rule.selectorText === `.${className}`) {
return rule
}
}
}
}
throw new Error(`CSS rule for class "${className}" not found`)
const cssRuleCache = new Map<string, CSSStyleRule>();
function getCSSRuleForClass(className: string, mediaText?: string): CSSStyleRule {
const cacheKey = mediaText ? `${className}|${mediaText}` : className;
if (cssRuleCache.has(cacheKey)) {
return cssRuleCache.get(cacheKey)!;
}
for (const sheet of document.styleSheets) {
for (const rule of sheet.cssRules) {
if (mediaText) {
if (rule instanceof CSSMediaRule && rule.media.mediaText === mediaText) {
for (const innerRule of rule.cssRules) {
if (innerRule instanceof CSSStyleRule && innerRule.selectorText === `.${className}`) {
cssRuleCache.set(cacheKey, innerRule);
return innerRule;
}
}
}
} else if (rule instanceof CSSStyleRule) {
if (rule.selectorText === `.${className}`) {
cssRuleCache.set(cacheKey, rule);
return rule;
}
}
}
}
throw new Error(`CSS rule for class "${className}" not found`);

Copilot uses AI. Check for mistakes.

@joshblack joshblack added this pull request to the merge queue Jun 23, 2025
Merged via the queue into main with commit 94f6112 Jun 23, 2025
35 checks passed
@joshblack joshblack deleted the refactor/update-tests-to-vitest-jun-20 branch June 23, 2025 13:54
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