Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the log method in BaseReporter respect the useStderr config option #4296

Closed
christiango opened this issue Aug 18, 2017 · 13 comments
Closed
Labels

Comments

@christiango
Copy link
Contributor

christiango commented Aug 18, 2017

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

@christiango christiango changed the title Make the log method in BaseReporter respect useStderr Make the log method in BaseReporter respect the useStderr config option Aug 18, 2017
@christiango
Copy link
Contributor Author

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.

@aaronabramov
Copy link
Contributor

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?

@christiango
Copy link
Contributor Author

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.

@aaronabramov
Copy link
Contributor

@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

@cpojer
Copy link
Member

cpojer commented Aug 22, 2017

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.

@aaronabramov
Copy link
Contributor

@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

@christiango
Copy link
Contributor Author

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.

@aaronabramov
Copy link
Contributor

@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 :)

@mihhail-lapushkin
Copy link

mihhail-lapushkin commented Sep 16, 2017

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.
eirslett/frontend-maven-plugin#584

@aaronabramov
Copy link
Contributor

i'm working on it right now as part of #4471

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 26, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants