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

Provide a --simple-output option #2471

Closed
jlongster opened this issue Dec 29, 2016 · 10 comments
Closed

Provide a --simple-output option #2471

jlongster opened this issue Dec 29, 2016 · 10 comments

Comments

@jlongster
Copy link

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

A feature!

What is the current behavior?

Currently Jest (as do many modern CLI tools) outputs fancy text to the terminal for a better experience. This does things like only painting part of the terminal, colors, and other stuff like that.

The problem is if you get too fancy you break interop with all other unix tools. For example, do jest | less and it won't work. You'll see lots of weird characters and the output is not paged.

I really want to get a list of all currently failing tests. Just a raw list, don't want to see a huge amount of actual/expected output (the diffs can be very large). I'm migrating a test suite over to new code so my goal is to make all these tests pass. Right now it's very hard to track just the failing tests.

Doing jest | grep FAIL would work if I could grep the output, but I can't.

What is the expected behavior?

Provide some sort of --simple-output which just dumps raw text and newlines to the terminal, without any of the fancy stuff. This would let me grep the output and the test failures, or do anything you want to with any of the normal unix tools.

@thymikee
Copy link
Collaborator

@jlongster thanks for adding this issue. Something similar was already discussed here: #2292 and there's also a temporary solution: #2292 (comment) while we don't have --simple-output or --no-interactive or --no-status

@jlongster
Copy link
Author

Cool,thanks! While CI=true seems to remove the summary output at the bottom, it still does not interact well with less or grep. I'm wondering if it's using a different type of newline or something.

@thymikee
Copy link
Collaborator

As a workaround you can redirect stderr (which holds results) to stdout

CI=true npm test 2>&1 | grep fail -i

But having --no-status, or --no-interactive would still be great to have

@jlongster
Copy link
Author

Ah nice, thanks! I thought everything was piped to stdout because the --useStderr option exists.

@saada
Copy link

saada commented Jan 10, 2017

A workaround we came up with is to create a file test.sh that would allow you to handle non-interactive shells gracefully while maintaining the exit code.

#!/bin/bash
if [ "`tty`" != "not a tty" ]
then
  echo 'Interactive shell'
  ./node_modules/.bin/jest ./spec/$1/*
  EXIT_CODE=$?
  exit $EXIT_CODE
else
  echo 'Non interactive shell'
  ./node_modules/.bin/jest ./spec/$1/* > ./jest-output.log 2>&1
  EXIT_CODE=$?

  cat ./jest-output.log
  rm ./jest-output.log

  exit $EXIT_CODE
fi

while in package.json

"scripts": {
  "test-unit": "sh test.sh unit",
  "test-integration": "sh test.sh integration"

}

This is obviously temporary until a proper fix is merged to master.
Please add that flag as a feature since a lot of people use Jenkins for CI.

@kirbysayshi
Copy link

kirbysayshi commented Feb 1, 2017

I came across this issue today when trying to get debug (https://github.com/visionmedia/debug) output to appear while debugging a test case. Had to solve it using the workarounds in other issues, namely:

$ CI=true DEBUG=* ./node_modules/.bin/jest --env=jsdom --watch

Without CI=true no output from the debug module will be seen (or it will be seen briefly if a test is slow, but jest will erase it).

The watch/automatic mode of jest is really cool! Has really changed my workflows. But taking over stderr/stdout has also caused me to spend more time than I'd like to admit trying to have confidence in my debug output.

@ollwenjones
Copy link

ollwenjones commented Mar 3, 2017

I'm trying to run Jest inside a maven process, and it hangs every time, and I don't know but I suspect it's related to the clever output. 👍

@ollwenjones
Copy link

I confirmed the CI=true made it work inside the maven build. 🍻 Since we are using frontend-maven-plugin I had to add environment variables in the pom like so:

...
  <configuration>
    ...
    <environmentVariables>
      <CI>true</CI>
    </environmentVariables>
  </configuration>
...

@cpojer
Copy link
Member

cpojer commented Dec 15, 2017

I think for now we aren't interested in doing this but if anybody feels strongly, please send a PR :)

@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

6 participants