If 1 test fails npm return an error
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 1.197s
Ran all test suites matching /.\/assets/i.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] unit: `jest --verbose ./assets`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
This is not a bug. Jest exits with code 1 because a test failed.
This is not a bug. Jest exits with code 1 because a test failed.
Any setting to prevent that ? i read mostly of the documentations and didn't find information about that.
I don't think so (and I cannot imagine why you would want that).
But jest --verbose ./assets || true
would always exit with 0, no guarantees on Windows compatibility though 😅
I’m new at Jest, so correct me if I’m misinformed, but I’d think that any normal operation should exit with code 0. The purpose of Jest is to test your code; if Jest successfully does that — even if your code fails — shouldn’t it exit with code 0? A code 1 implies something went wrong with _Jest itself,_ not necessarily the code it’s testing.
This reminds me of something I read about parsers:
Syntax errors are a fact of life and language tools have to be robust in the face of them. Segfaulting or getting stuck in an infinite loop isn’t allowed. While the source may not be valid _code_, it’s still a valid _input to the parser_ because users use the parser to learn what syntax is allowed.
I disagree with this as a general statement - and I think there are other programs where the sensible thing is to forward an error caused by something that is not under the control of the program. For example, you wouldn't want yarn run somescript
to swallow the exit code of somescript
and just return 0 because it successfully executed somescript
.
I think this choice needs to be made on a case-by-case basis, and for Jest clearly the implications of exiting with 0 despite failing tests would be immense - think of all the CI pipelines that would stop detecting failing tests.
@jeysal So what do you suggest in order to get rid of those 10 lines and the continuous creation of useless debug log files?
It's immensely annoying to get that every single time your test fails, merely because you were not done programming yet.
You made a good point though. And this issue is probably more befitting to be aimed towards NPM itself.
@pedzed As suggested in this Stack Overflow post, you can use the --silent
or -s
flag to avoid npm error messages if tests fail.
@pedzed As suggested in this Stack Overflow post, you can use the
--silent
or-s
flag to avoid npm error messages if tests fail.
Ah, thanks!
npm -s run test
npm -s run test
it work for me, thank you so much
Most helpful comment
I’m new at Jest, so correct me if I’m misinformed, but I’d think that any normal operation should exit with code 0. The purpose of Jest is to test your code; if Jest successfully does that — even if your code fails — shouldn’t it exit with code 0? A code 1 implies something went wrong with _Jest itself,_ not necessarily the code it’s testing.
This reminds me of something I read about parsers: