fix(jest-console): buffer console output in CustomConsole for reporters#16155
Open
ahnpnl wants to merge 1 commit into
Open
fix(jest-console): buffer console output in CustomConsole for reporters#16155ahnpnl wants to merge 1 commit into
ahnpnl wants to merge 1 commit into
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
8bf58d0 to
9235c0a
Compare
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
f91156c to
2da52ad
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a long-standing gap where, in verbose mode (notably when Jest forces verbose: true for single-file runs), CustomConsole did not provide a console buffer—so TestResult.console stayed empty and reporters couldn’t access console output. The change makes CustomConsole both print live output and also buffer entries so reporters can consume them.
Changes:
- Add
ConsoleBuffertracking toCustomConsoleand implementgetBuffer()to return buffered entries. - Update
DefaultReporterto avoid printing the buffered “Console” section when running in verbose mode. - Add unit tests for
CustomConsole.getBuffer()behavior and add a changelog entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/jest-reporters/src/DefaultReporter.ts | Adds a guard to avoid printing the buffered Console section in verbose mode (but the guard currently uses only global verbose). |
| packages/jest-console/src/CustomConsole.ts | Implements buffering in CustomConsole (tracks messages + origin stack) and returns it via getBuffer(). |
| packages/jest-console/src/tests/CustomConsole.test.ts | Adds coverage verifying getBuffer() returns undefined when empty and buffers log/error/warn while still printing live. |
| CHANGELOG.md | Documents the fix under ## main → ### Fixes. |
ebe47f2 to
1b6b435
Compare
1b6b435 to
8b591b5
Compare
CustomConsole.getBuffer() returned undefined, causing TestResult.console to be empty when verbose mode was active. Reporters relying on TestResult.console (e.g. custom reporters) received no console data. Added buffer tracking to CustomConsole so it both prints live to stdout (preserving verbose UX) and populates the buffer for reporters. Closes jestjs#6441
8b591b5 to
59f9bc1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6441
When running a single test file, Jest forces
verbose: true(source), which causesrunTestto useCustomConsoleinstead ofBufferedConsole.CustomConsole.getBuffer()returnedundefined, soTestResult.consolewas never populated — reporters (including custom reporters) received no console data.This PR adds buffer tracking to
CustomConsoleso it both:getBuffer()returns aConsoleBuffer, populatingTestResult.consolefor reportersChanges
packages/jest-console/src/CustomConsole.ts:_buffer: ConsoleBufferfield_addToBuffer()private method that captures stack origin (matchingBufferedConsole.writebehavior)_log()and_logError()now also write to the buffergetBuffer()returns the buffer (instead of alwaysundefined)packages/jest-reporters/src/DefaultReporter.ts:● Consolesection when the effective verbose setting (config.verbose ?? globalConfig.verbose) is true, sinceCustomConsolealready prints output inline — avoids double-printingpackages/jest-console/src/__tests__/CustomConsole.test.ts:getBuffer()behaviore2e/__tests__/__snapshots__/executeTestsOnceInMpr.ts.snap:Test plan
console.test.ts,consoleDebugging.test.ts,consoleLogOutputWhenRunInBand.test.ts,testRetries.test.ts,jest.config.ts.test.ts,jest.config.js.test.ts,executeTestsOnceInMpr.tsyarn jest packages/jest-console --no-coverageyarn lintyarn build