Skip to content

Add Vitest console enforcement#7844

Open
joshblack wants to merge 5 commits into
mainfrom
copilot/remove-test-console-warnings
Open

Add Vitest console enforcement#7844
joshblack wants to merge 5 commits into
mainfrom
copilot/remove-test-console-warnings

Conversation

@joshblack
Copy link
Copy Markdown
Member

Closes N/A

Adds a shared @primer/vitest-config package that enables vitest-fail-on-console in CI and via PRIMER_TEST_FAIL_ON_CONSOLE=true, then updates the repository Vitest configurations to consume that shared setup.

This also updates tests to explicitly handle expected console output or avoid interactions that produced console noise, without changing component source.

Changelog

New

  • Added private shared Vitest setup package for console enforcement.

Changed

  • Updated Vitest configs to include shared console enforcement setup.
  • Updated tests to pass with console enforcement enabled.

Removed

  • N/A

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; test/tooling-only change with no published runtime API or behavior change.

Testing & Reviewing

  • npm run build
  • PRIMER_TEST_FAIL_ON_CONSOLE=true npx vitest run
  • npm run type-check
  • npm run lint
  • npm run lint:css
  • npm run format:diff

Merge checklist

joshblack and others added 2 commits May 15, 2026 11:09
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joshblack joshblack added the skip changeset This change does not need a changelog label May 15, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

⚠️ No Changeset found

Latest commit: e68c7d0

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 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joshblack joshblack marked this pull request as ready for review May 15, 2026 16:32
@joshblack joshblack requested a review from a team as a code owner May 15, 2026 16:32
@joshblack joshblack requested review from Copilot and jonrohan May 15, 2026 16:32
@github-actions github-actions Bot requested a deployment to storybook-preview-7844 May 15, 2026 16:36 Abandoned
Copy link
Copy Markdown
Contributor

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

Adds shared Vitest console enforcement through a private workspace package and wires it into the repository’s Vitest project configs, with related test updates to handle existing console output.

Changes:

  • Adds @primer/vitest-config with shared vitest-fail-on-console setup.
  • Updates React, styled-react, doc-gen, and postcss Vitest configs/package dependencies.
  • Adjusts tests to wrap async updates, mock expected console output, or avoid console noise.
Show a summary per file
File Description
packages/vitest-config/* New shared Vitest setup package for console enforcement.
packages/*/vitest.config* Consumes shared setup in node/browser Vitest projects.
packages/*/package.json Adds workspace dependency on shared Vitest config.
packages/react/src/**/*.test.tsx Updates tests for console enforcement compatibility.
package-lock.json Locks new workspace package and dependency updates.

Copilot's findings

  • Files reviewed: 39/40 changed files
  • Comments generated: 12

Comment on lines +16 to +18
/^Warning: Unexpected return value from a callback ref in .+\. A callback ref should not return a function\./.test(
message,
)
}).toThrow(
'The `Tooltip` component expects a single React element that contains interactive content. Consider using a `<button>` or equivalent interactive element instead.',
)
}, 'The `Tooltip` component expects a single React element that contains interactive content. Consider using a `<button>` or equivalent interactive element instead.')
Comment on lines +66 to +75
function expectRenderError(callback: () => void, error: string | RegExp, expectedConsoleErrors = 3) {
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
try {
expect(callback).toThrow(error)
const messages = consoleError.mock.calls.map(args => args.map(String).join(' '))
expect(messages).toHaveLength(expectedConsoleErrors)
if (typeof error === 'string') {
expect(messages.join('\n')).toContain(error)
} else {
expect(messages.join('\n')).toMatch(error)
Comment on lines +244 to +248
function expectRenderError(callback: () => void, error: string | RegExp, expectedConsoleErrors = 3) {
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
try {
expect(callback).toThrow(error)
const messages = consoleError.mock.calls.map(args => args.map(String).join(' '))
Comment on lines +205 to +209
function expectRenderError(callback: () => void, error: string | RegExp, expectedConsoleErrors = 4) {
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
try {
expect(callback).toThrow(error)
const messages = consoleError.mock.calls.map(args => args.map(String).join(' '))
Comment on lines +23 to +26
const messages = consoleError.mock.calls.map(args => args.map(String).join(' '))
expect(messages).toHaveLength(1)
expect(messages[0]).toContain('non-boolean attribute')
expect(messages[0]).toContain('inline')
Comment on lines +312 to +322
expect(messages).toHaveLength(5)
expect(
messages.some(message => message.includes('React does not recognize') && message.includes('popoverTarget')),
).toBe(true)
expect(
messages.every(
message =>
(message.includes('React does not recognize') && message.includes('popoverTarget')) ||
message.includes('Unexpected return value from a callback ref'),
),
).toBe(true)
Comment on lines +52 to +62
expect(messages).toHaveLength(7)
expect(messages.some(message => message.includes('React does not recognize') && message.includes('groupId'))).toBe(
true,
)
expect(
messages.every(
message =>
(message.includes('React does not recognize') && message.includes('groupId')) ||
message.includes('Unexpected return value from a callback ref'),
),
).toBe(true)
Comment on lines +11 to +19
const {container} = render(<ActionList className="test-class" items={[]} />)

expect(container.firstElementChild).toHaveClass(classes.List)
expect(container.firstElementChild).toHaveClass('test-class')
const messages = consoleError.mock.calls.map(args => args.map(String).join(' '))
expect(messages).toHaveLength(1)
expect(messages[0]).toContain('React does not recognize')
expect(messages[0]).toContain('groupId')
consoleError.mockRestore()
Comment on lines +164 to +171
expect(messages).toHaveLength(12)
expect(
messages.every(
message =>
message.includes('Unexpected return value from a callback ref') ||
message.includes('React does not recognize'),
),
).toBe(true)
In React 19, errors thrown during rendering no longer trigger console.error
the same number of times as React 18. Additionally, React 19 natively
supports `popover`/`popoverTarget` attributes (removing the "React does not
recognize" warning) and allows callback refs to return cleanup functions
(removing the "Unexpected return value from a callback ref" warning).

- Simplify `expectRenderError` in Group, Heading, UnderlineNav, Tooltip,
  and UnderlinePanels tests — keep `toThrow` assertion and console spy,
  remove brittle count/content checks
- Update AnchoredOverlay, ConfirmationDialog, and deprecated ActionMenu
  tests — keep console spy to suppress React 18 prop warnings, remove
  version-specific count assertions

Co-authored-by: joshblack <3901764+joshblack@users.noreply.github.com>
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.

4 participants