I'm trying to generate test reports in plain text but for some reason Jest keeps adding characters to the output that are breaking the text, I assume it's replacing the previous line with the results of the test but I don't need that feature for test reports.
Do you want to request a *feature or report a bug?*
Bug
What is the current behavior?
It's adding a bunch of [K and [1A to my output and I can't use it.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can npm install and npm test.
Just try jest > yourfile.txt
What is the expected behavior?
I wish I could generate test reports in plain text
Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system.
Running your tests with the --no-color flag should make it work 馃槃
npm run test -- --no-color
After reading your comments in #608 I agree that it would be great to be able to customize this through other ways other than argv
Disabling the colorized output doesn't fix the issue. It's using special characters to replace the previous line in the shell buffer.
Try to save that output to a text file, like npm run test -- --no-color > results.txt and you will see the problem.
Yeah, Jest adds a lot of special characters to provide a better output in interactive terminals... I don't think that there is a way to disable it with command line args
Jest does not add any characters when it is a non interactive terminal or when you are running it in CI, which means that you could simulate a CI build to prevent those special characters from showing up. I know that this solution seems weird, but I can't think of anything else. I wonder if it would make sense to have --interactive, --no-interactive flags to override it.
In the mean you can run CI=true npm test, but you might also have to redirect stderr, depending on which output you are interested on (Jest uses stderr for several things). CI=true npm test > yourfile.txt 2>&1.
@rogeliog sweet, thanks for your answer! Closing this.
@rogeliog I totally agree we should have --no-interactive or --no-status, especially also to disable the concurrent runner output. If anybody wants to send a PR for this it would be greatly appreciated.
@cpojer I can help with this
go for it!
I've been trying to figure out how to use tee to see both the output file and get something in the terminal (since CI emails that). Any ideas on making that work?
BTW if you pass the output through cat, the terminal is considered non-interactive, and doesn't do the fancy formatting. e.g.
yarn jest --no-color | cat
@JaneCoder Wouldn't passing the output of just to the tee command work?
yarn jest 2>&1 | tee jest.log
Has this ever been resolved? Still broken with vim-test and vim-dispatch
@JaneCoder Wouldn't passing the output of just to the
teecommand work?
yarn jest 2>&1 | tee jest.log
this worked for me. give it a go @vegerot , i am using it like so in my package.json:
"scripts": {
"test": "jest 2>&1 | tee reports/acceptance-test-results.txt",
Most helpful comment
Yeah, Jest adds a lot of special characters to provide a better output in interactive terminals... I don't think that there is a way to disable it with command line args
Jest does not add any characters when it is a non interactive terminal or when you are running it in CI, which means that you could simulate a CI build to prevent those special characters from showing up. I know that this solution seems weird, but I can't think of anything else. I wonder if it would make sense to have
--interactive, --no-interactiveflags to override it.In the mean you can run
CI=true npm test, but you might also have to redirect stderr, depending on which output you are interested on (Jest uses stderr for several things).CI=true npm test > yourfile.txt 2>&1.