Skip to content

internal: Capture extraneous console output in tests#3773

Merged
ntucker merged 1 commit intomasterfrom
suppress-test-console-noise
Mar 8, 2026
Merged

internal: Capture extraneous console output in tests#3773
ntucker merged 1 commit intomasterfrom
suppress-test-console-noise

Conversation

@ntucker
Copy link
Collaborator

@ntucker ntucker commented Mar 8, 2026

Motivation

Test runs were noisy with console.error, console.warn, console.info, and console.log messages leaking to stderr/stdout. These messages (React act() warnings, post-unmount dispatch info, InteractionManager deprecation warnings, etc.) are expected side effects of the code under test but were cluttering test output, making it harder to spot real issues.

Solution

Add jest.spyOn(console, ...) with mockImplementation(() => {}) across 28 test files in react, rest, and vue packages. Spies are scoped to beforeAll/afterAll to avoid timing issues with @testing-library cleanup ordering.

Key changes:

  • Console spies: Added to all test files with leaking output — console.error (React act warnings, error boundaries), console.warn (RN InteractionManager deprecation), console.info (post-unmount dispatch messages), console.log (reset fetch logging)
  • useSuspense.web.tsx: Wrapped testDispatchFetch endpoint calls in act(), scoped "reset promises" test into describe('unmount handling') with dedicated console.info spy
  • useSuspense.native.tsx: Added console.warn/console.error spies, documented why native testDispatchFetch can't await endpoint calls (nock doesn't intercept native fetch)
  • AsyncBoundary.web.tsx: Replaced direct console.error = jest.fn() assignment with proper jest.spyOn pattern
  • Console assertion tests: Where tests assert on consoleSpy.mock.calls.length, spies now use mockImplementation to suppress output while preserving call tracking, with mockRestore() in cleanup

Open questions

N/A

Made with Cursor


Note

Low Risk
Primarily test-only changes plus TypeScript declaration updates; low runtime risk, with minor chance of masking unexpected console output or slightly altering type inference for path params in the playground.

Overview
Reduces test noise by silencing expected console output across React/React Native/Vue/REST test suites via scoped jest.spyOn(console, ...) mocks (with proper restore), and replaces a few ad-hoc console.error = jest.fn() patterns.

Tightens a couple of tests for correctness/stability (e.g., wrapping endpoint execution in act() and scoping unmount-related cases), and updates the playground editor *.d.ts REST path-arg types to better handle * wildcards, optional }-terminated tokens, and array-valued params.

Written by Cursor Bugbot for commit 4988ad2. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link

changeset-bot bot commented Mar 8, 2026

⚠️ No Changeset found

Latest commit: 4988ad2

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
Copy link
Contributor

github-actions bot commented Mar 8, 2026

Size Change: 0 B

Total Size: 80.4 kB

ℹ️ View Unchanged
Filename Size
examples/test-bundlesize/dist/App.js 3.18 kB
examples/test-bundlesize/dist/polyfill.js 307 B
examples/test-bundlesize/dist/rdcClient.js 10.2 kB
examples/test-bundlesize/dist/rdcEndpoint.js 6.33 kB
examples/test-bundlesize/dist/react.js 59.7 kB
examples/test-bundlesize/dist/webpack-runtime.js 726 B

compressed-size-action

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.05%. Comparing base (1a20f4e) to head (4988ad2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3773   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files         151      151           
  Lines        2832     2832           
  Branches      554      554           
=======================================
  Hits         2777     2777           
  Misses         11       11           
  Partials       44       44           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Spy on console.error, console.warn, console.info, and console.log in
test files where expected output was leaking to stderr/stdout. Uses
jest.spyOn with mockImplementation in beforeAll/afterAll to suppress
noise while keeping assertions on console call counts intact.

Key changes:
- Add console spies to 28 test files across react, rest, and vue packages
- Wrap act() around async endpoint calls in testDispatchFetch (web)
- Scope 'reset promises' test into describe('unmount handling') with
  dedicated console.info spy for post-unmount dispatch messages
- Fix AsyncBoundary test to use spyOn instead of direct console assignment
- Fix jest.config.js formatting (cosmetic)

Made-with: Cursor
@ntucker ntucker force-pushed the suppress-test-console-noise branch from 4fc3432 to 4988ad2 Compare March 8, 2026 16:09
@ntucker ntucker merged commit 74b7a5f into master Mar 8, 2026
24 checks passed
@ntucker ntucker deleted the suppress-test-console-noise branch March 8, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant