-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Jest is using stderr
as output
#5064
Comments
Running into this as well. Am not using the |
I'm running into this issue using Visual Studio Online Build using a Windows host. If I switch to use a Linux host everything works as expected. Example Scripts and output below from both hosts: From the Windows host, using PowerShell: Output: Starting: PowerShell Script Task : PowerShell Finishing: PowerShell Script From the Linux host using bash: Output: Starting: Shell Script visualStudioOnlineBuildTest.sh Task : Shell Script
Finishing: Shell Script visualStudioOnlineBuildTest.sh |
In case anyone else runs into this...the problem is with Microsoft and how they implement the PowerShell task for Visual Studio Online Build. Solution for me, change my PowerShell script to: |
I've also noticed that |
Having the same issue - I'm wrapping Jest invokation in PHP Symfony process, no additional flags for jest is used - output is in stderr |
Experiencing the same issue using frontend-maven-plugin when executing npm run unit. Not using --useStderr option. Maven output is
"frontend-maven-plugin takes all output from stderr and forwards it as ERROR logs, and all output from stdout forwarded as INFO logs." - eirslett/frontend-maven-plugin#584. Maven pom snippet:
|
PR: #6583 |
With the same problem. Hopefully the PR will be approved soon, this will hinder some CI platforms. |
Is there any progress on this, bumped into this issue today with our CI (teamcity) treats stderr as an error even when the tests pass. |
Same problem ... would be nice if PR gets approved soon |
tried to help with the PR, but there are tons of e2e integration tests failing. For the time being, I created a reporter that uses stdout instead and published the package in case anybody can benefit from it: https://github.com/chrisgalvan/jest-standard-reporter |
Have there been any updates on this? Jest is currently very noisy in our CI pipeline because of this bug. |
Sets up a test of a static page using selenium-webdriver * Adds a test page at src/index.html * Adds a test of it at tests/index.test.ts * Removes placeholder tests * Adds a yarn serve (I wanted it for testing purposes but thought it might be nice to keep) * Switches to windows-2019 vmImage for testing (because it has selenium webdriver binaries avaiable) * Remove code coverage (there is no non-test js/ts code to cover) * Switch to jest-standard-output reporter to work around jestjs/jest#5064 * Update documenation * Enable use of the CHROMEDRIVER env var in pipelines agents
It seems someone has made a package to address this issue => https://github.com/chrisgalvan/jest-standard-reporter |
Yes, the author of that package himself announced it on this thread already (literally two comments above yours! 😄) |
@SimenB I was working on this and managed to get it working as per our discussion on #6583. However, there's one major issue preventing me from completing this piece of work. I'd like to ask you and the team for guidance on what's the desired behaviour for coverage reports so that I know how to proceed. Currently, in the tests for coverage reports, the snapshots contain only the coverage reports themselves since they are written to Now, with reporters writing to This prevents me from generating any meaningful snapshots since it's not possible to determine the order in which they are going to finish. I have a few ideas on how to proceed, but I'd like to ask the maintainers what they think would be the most viable solution:
I'd go for the first option since currently we already output the test result entries anyway (but on different streams). This may annoy users who rely on it being output to Do you agree? |
@lucasfcosta Do I understand correctly that at the moment coverage output on stdout and reporter output on stderr can already be interleaved? If so, I agree that 1 would only make it slightly worse (unless you redirect one of the streams like a typical console run it doesn't change anything, but ofc 2 would still be the proper fix if you wanna invest the time). But I must say that I've never seen PASS/FAIL appearing below coverage so I'm wondering why it happened in your test... |
Hi @jeysal, Sorry, I should've been clearer in my explanation. I was also a bit confused before actually digging deeper into the issue. I'm sorry about that. Let me explain in more detail: Currently, the reason why the coverage doesn't get mixed up with the entries is that we do print to separate streams which have separate flushing behaviour in different reporters. Since the This appears to have been a "lucky"/"useful" bug, thus why we never caught the coverage being interleaved into the tests. Once you have all the output being instantly flushed (as would happen before due to I still have to dig deeper into this to find the proper fix and investigate the differences between the two reporters. Even though the debouncing is not being used at all I'd rather fix it (even if it's a separate preliminary PR) than remove it altogether as just seems incorrect to me. For the moment I'll focus on fixing the I'll keep you up to date, sorry for the hassle (I tend to be long-winded as you might have noticed 😅 ) |
Sorry for stupid question, but how can I tell programmatically that tests failed, when I run them from CLI, if stderr is always nonempty and return code is always 0, no matter if tests fail or pass? Edit: |
I'm running into the same problem. none of the following things worked for me. cross-env CI=true npm run test tried running tests with --coverage option, all tests are passing, but when running the task through PowerShell in Azure DevOps, it is always treating it as an error. appreciate any help !! |
Hello everyone, this is a very long piece of work. I have started working on it and put some considerable effort in. However, I don't think I'll manage to get back to it as I've got a few conferences scheduled until the end of the year. I'd be happy to walk someone through what needs to be done though. It's a small change to the main code-base, but one which requires many tests to be updated, including tooling around them. I think I'd only be able to get this done by next year. I'll hopefully try to make some room for fixing my other PRs before that, but for this specific one I'm afraid will have to wait. I'm sorry for that. |
Hey @vejandla please use |
npm run test > out 2>error # jest
Facebook. This... is huge 😂 |
However, when I think about it, when should it be output to stdout and stderr? If all tests passed, I think we can all agree the summary should be outputted to stdout. However, if at least one, or all tests failed, should it still be output to stdout, or to stderr? Or should it be split between the two? EDIT: Nvm, found it, it's here: |
IMO should be split, only errors should be output to stderr, most CI and other tools use it to print differently (red console for example). If you are trying to see what tests failed, should be able to point to the one that failed not the entire suite. |
See for details: jestjs/jest#5064 (comment) Relate to #1484
Here's how to simply customize this for yourself https://github.com/lukaw3d/jest-fixed-default-reporter#implementation |
Hi there. Exeperiencing the same behaviour when running jest from nodejs exec tool and handling outputs with a callback. P.S. (I know that I could just react to first comment in issue, I'e already done that). |
that's clever @lukaw3d do you mind if I move your approach to jest-standard-reporter? |
Sure! |
My ci pipeline is failing because of it :( |
Pretty strange if no errors, it's using stderr. I was writing a little script to automate multiple tests in my mono repo, and wanted an option that would repeat the jest output. My code wasn't checking stderr since was relying on the exitCode for the |
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. |
not stale |
Luckily, I ran the jest command using nodejs and collected the reporter information in stderr and treated it as stdout. |
Here a workaround (tested with node v20 and jest v29). This workaround is inspired by https://github.com/lukaw3d/jest-fixed-default-reporter#implementation but updated in order to use File: StdoutSummaryReporter.js import { SummaryReporter } from '@jest/reporters'
class FixedSummary extends SummaryReporter {
_hasFailures = false;
_write(string) {
super._write(string)
// little hack in order to detect if there was a failure
// the _write method will only be called if there was a failure ... see line 183 in
// ./node_modules/@jest/reporters/build/SummaryReporter.js
this._hasFailures = true;
}
log (message) {
if (this._hasFailures) {
process.stderr.write(`${message}\n`)
} else {
process.stdout.write(`${message}\n`)
}
}
}
export default FixedSummary File: StdoutReporter.js import { DefaultReporter } from '@jest/reporters'
class Fixed extends DefaultReporter {
log (message) {
if (message.startsWith('FAIL ')) {
process.stderr.write(`${message}\n`)
} else {
process.stdout.write(`${message}\n`)
}
}
}
export default Fixed File: jest.conf.js const jestConfig = {
...
reporters: [
'./test/unit/StdoutReporter.js',
['./test/unit/StdoutSummaryReporter.js', {summaryThreshold: 1} ]
],
...
} |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
jest output is using
stderr
.If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can
yarn install
andyarn test
.This repo (https://github.com/easingthemes/jest-output) has
task.js
file which usesnodejs spawn
to runnpm test
(jest
) and print output by type.command:
Output:
What is the expected behavior?
Not using
stderr
for output, usestdout
instead.Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
Related:
#4384
Right output type is important when using some other tools, eg. Jenkins / Maven. Because process is marked as failed due this error.
The text was updated successfully, but these errors were encountered: