jest-community / jest-junit

A Jest reporter that creates compatible junit xml files
Apache License 2.0
483 stars 109 forks source link

Is there a way to capture STDERR (either from console.error or process.stderr.write)? #218

Closed CMCDragonkai closed 2 years ago

CMCDragonkai commented 2 years ago

I have tests that tests code that prints log messages to STDERR.

STDERR is the standard way of outputting log messages on unix operating systems.

I'm wondering why includeConsoleOutput doesn't affect STDERR.

Can we get an option to also include STDERR? Maybe something like includeConsoleError?

I'd prefer that it also captured process.stderr.write, but could settle for console.error.

palmerj3 commented 2 years ago

See this old issue here for a detailed explanation about why this isn't available. TL;DR jest no longer sends this data to reporters. https://github.com/jest-community/jest-junit/issues/45

CMCDragonkai commented 2 years ago

I'm confused, in your issue #45 it says it is available. So I'm not just asking about process.stderr, but I'm asking about console.log and console.error. Does console.error work?

palmerj3 commented 2 years ago

None of them work and haven't for years. If jest fixes the bug then it would work in jest-junit by enabling the "includeConsoleOutput" option.

domino14 commented 8 months ago

console.log works with this:

JEST_JUNIT_INCLUDE_CONSOLE_OUTPUT=true npx jest --coverage --reporters=jest-junit