Jest: Make the log method in BaseReporter respect the useStderr config option

Created on 18 Aug 2017  路  10Comments  路  Source: facebook/jest

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
When setting the useStderr option to false, Jest still writes to stderr when there are no test failures. This can currently be worked around by creating a custom reporter that overrides the log method in BaseReporter.

What is the expected behavior?
It would be nice to have BaseReporter respect the useStderr flag so that we don't have to use a custom reporter.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest 20.4, npm 5.0.3, Windows Server 2016

Most helpful comment

Would love Jest to print non-failures to stdout.
I also use a build tool that marks Jest output as ERROR. Not critical, but would be nice not to explain to every new person that it's OK.
https://github.com/eirslett/frontend-maven-plugin/issues/584

All 10 comments

I'm willing to submit a PR, just want to know if this would be a desired change. I'm not familiar with the background on why Jest logs to stderr.

we currently print all reporting to stderr. I was thinking about changing it to stdout, but couldn't justify the change. what's your use case for it?

The build tool we use to manage our monorepos treats anything logged to the console as a warning. This means a clean build where the tests pass writes to stderr, which we treat as, a 'success with warnings'. When a project gets this build status, we don't cache the result for incremental builds.

We think that having our build chain treating stderr logs as warnings is the behavior we want, so we're looking at ways to modify Jest's behavior. We're currently using a custom reporter to prevent Jest from writing to stderr.

@cpojer do you have any thought?
i always though it is strange that we print everything to stderr when it's just a normal output.
i also think having something like #4212 might still be a good idea to reduce the overall complexity
cc @mjesun

Yeah, I mean console.error goes to stderr by default in node, I don't think there is anything wrong with that. We need two pipes to make --json work, which is the most important thing, other than that we could possibly change things.

@christiango if you're willing to submit the PR, one thing that you might expect is that all our integration tests will fail, because they usually read from stderr :)
here's an example: https://github.com/facebook/jest/blob/master/integration_tests/__tests__/jest_require_mock.test.js#L58

I can look into it if you all think it's a worthwhile change. Do you guys have any background on the intent of the useStdErr flag? I imagine this is something we'd want to respect here.

@christiango it's either --json or --listTest flags that produce a JSON output in stdout.
sometimes we pipe jest output like this: jest --listTests --findRelatedTests some_file.js | some_other_lib_that_expects_json_in_stdin
if there's anything else printed in stdout it'll break JSON, that's why we use --useStderr :)

Would love Jest to print non-failures to stdout.
I also use a build tool that marks Jest output as ERROR. Not critical, but would be nice not to explain to every new person that it's OK.
https://github.com/eirslett/frontend-maven-plugin/issues/584

i'm working on it right now as part of https://github.com/facebook/jest/issues/4471

Was this page helpful?
0 / 5 - 0 ratings