feat(test): capture stdout/stderr in JUnit reporter#35198
Open
lunadogbot wants to merge 1 commit into
Open
Conversation
The JUnit reporter previously dropped all test output because the captured stdout/stderr was a single global stream with no way to tell which test or step produced it. Tag each `TestEvent::Output` with the stream it came from (`TestStdioStream::Stdout`/`Stderr`) and have the JUnit reporter track the currently-running test/step (mirroring the existing LSP reporter). Output is then attributed to the active test case and emitted as `<system-out>`/`<system-err>` elements, matching the convention used by other JUnit producers like Vitest. Closes #20152
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.
Closes #20152.
Problem
The JUnit reporter dropped all test output. The captured stdout/stderr arrived as a single global stream with no way to tell which test or step produced it, so
report_outputwas a no-op with a TODO.Solution
Within a worker, tests run sequentially, so output between a test's
WaitandResultbelongs to that test — and the channel's existing stdio-sync mechanism already guarantees correct interleaving of output and lifecycle events. The LSP reporter already relies on this to attribute output to acurrent_test; this PR applies the same approach to the JUnit reporter.TestEvent::Output(Vec<u8>)becomesTestEvent::Output(TestStdioStream, Vec<u8>), where the newTestStdioStreamenum distinguishesStdout/Stderr. EachTestStreamnow records which stream it reads from.current_testis set onreport_wait/report_step_waitand restored/cleared on the corresponding results (mirroring the LSP reporter's stack-like handling), so step output is attributed to the step and pre/post-step output to the parent test.system_out/system_errbuffers and serialized as<system-out>/<system-err>elements — matching the convention used by other JUnit producers such as Vitest.report_outputtrait signature across all reporters; pretty/dot/tap/compound/LSP ignore the stream and keep their prior behavior.Example
Tests
junit_capture_outputcovering stdout, stderr, and per-step attribution.junitandjunit_multiple_test_files.outfiles, whose existingconsole.log/console.errortests now show captured output.hide_stacktraces,junit_nested,junit_console_formatting, and thejunit_pathintegration test are unaffected.https://claude.ai/code/session_013BQKi6tsSyAeFT3UsBgAfR
Generated by Claude Code