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

--listTests should always print to stdout #4388

Closed
aaronabramov opened this issue Aug 29, 2017 · 5 comments
Closed

--listTests should always print to stdout #4388

aaronabramov opened this issue Aug 29, 2017 · 5 comments

Comments

@aaronabramov
Copy link
Contributor

if we run jest with --listTests --json arguments the output will be printed to stderr which is incorrect.
We need to change these lines to use console.log https://github.com/facebook/jest/blob/master/packages/jest-cli/src/run_jest.js#L117-L122

also this test needs to be fixed to use stdout
https://github.com/facebook/jest/blob/master/integration_tests/__tests__/list_tests.test.js#L40-L42

@jseminck
Copy link
Contributor

I'd like to tackle this!

@jseminck
Copy link
Contributor

jseminck commented Aug 30, 2017

@aaronabramov does the else statement also need to be changed to use console.log?

Because if we force both outputs to be printed to console.log, then the argv.useStderr flag would not be taken into account anymore? Is that what you want? (if I understand the code correctly):

const outputStream = argv.json || argv.useStderr ? process.stderr : process.stdout;

It also specifically has this comment:

  // If we output a JSON object, we can't write anything to stdout, since
  // it'll break the JSON structure and it won't be valid.

See: https://github.com/facebook/jest/blob/master/packages/jest-cli/src/cli/index.js#L59

@aaronabramov
Copy link
Contributor Author

@jseminck yep! that's exactly what the bug is :)
when we use --useStderr we redirect all "non data" output to stderr so that the "data" output does not get polluted.
and by "data output" i mean one of:

  • JSON output when using --json
  • JSON output when using --json --listTests
  • \n separated list when using --listTests

so yes. both if and else should output to console.log while outputStream is used for everything else

@jseminck
Copy link
Contributor

Thanks for the explanation! PR is up. 😄 Do we also need an additional test then to make sure --listTests --useStdErr is still printed to stdout ?

@cpojer cpojer closed this as completed Sep 1, 2017
@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 May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants