Currently, jest --watch output won't include console.error/warn/log, which can lead to things silently failing.
One simple use case is a Promise making an HTTP request, handling exceptions but also logging to console.error to alert the developer. If an HTTP request is failing is because I probably forgot to mock something, but instead it will just silently output nothing.
It does include console calls. Just scroll up a little bit ;) For a single test, they are printed immediately when they happen and we don't wait until test results are coming in.
@cpojer actually, my original message is wrong, it does include console.log but it definitely doesn't include console.error.
By the way, running just jest also does not print console.error. If I run jest <specific_test_file> then it outputs.
If you are using Jest 15 it should definitely be printed unless you also add --silent or something else is happening.
Can you please provide more information? The issue template is there for a reason ;) Which OS are you on, which version of node, which version of Jest, etc.?
For example, running just jest:
> jest
PASS src/app/resource_db/__tests__/clean-json_test.js
PASS src/auth/__tests__/actions_test.js
PASS src/auth/__tests__/LoginPage_test.jsx
PASS src/auth/__tests__/LoginPageContainer_test.jsx
Test Summary
› Ran all tests.
› 6 tests passed (6 total in 4 test suites, run time 2.136s)
vs running specific test:
> jest "actions_test.js"
PASS src/auth/__tests__/actions_test.js
fetchAuthorization
✓ fetches authorization with valid token (6ms)
Test Summary
› Ran all tests matching "actions_test.js".
› 1 test passed (1 total in 1 test suite, run time 1.318s)
console.error node_modules/core-js/modules/es6.promise.js:87
FetchError {
name: 'FetchError',
message: 'request to http://auth.test/authorization failed, reason: Nock: Not allow net connect for "auth.test:80/authorization"',
type: 'system',
errno: undefined,
code: undefined }
The only option I'm passing to jest is --color.
More info
$ npm --version # => 3.10.3
$ node --version # => v6.4.0
$ ./node_modules/.bin/jest -v # => v15.1.0
And I'm on OSX
oh, ok, the problem here seems that we don't print console errors that happen _after_ a test has been finished because the worker thread will always be torn down. When you run jest -i, will that print the console.error calls?
@cpojer jest -i gives the same result. You're somewhat right though.
I see the output if I call console.error from within the test, the problem seems to happen when it's logging on an async operation.
yeah, I suspect what happens is this async operation is called after the test finishes and we ignore those messages at this point. We could potentially bring them back but that might be risky.
Can you also try:
afterAll(done => {
setTimeout(() => done(), 3000);
});
that will make the test wait for a few seconds before sending results back to Jest and would help me confirm my suspicion.
Yep, that causes the output to come through.
I've also tested using async/await on the promise and that worked too. Not sure what's a good solution here but it did cause me a couple of hours today to understand that the HTTP request was failing due lack of a mock for example. Might be an isolated case, but seems like a good idea to have a way to capture that.
I'm seeing this issue on Node 7. Downgrading to Node 6 fixes it.
@davidaurelio upgrade to Jest v18.1, this should be fixed there for Node 7
Thanks for the recommendation
Add 'silent' value in your package.json scripts config. This solves the issue on my side. Using Jest version 19.0.0. Like:
_Before:_
"test": "jest --colors",
_After:_
"test": "jest --silent=false --colors",
I cannot see the console messages. I have Jest 20, Node 7, OSX. any ideas? Even with silent false. Here is my Jest config
"collectCoverage": true,
"coverageReporters": [
"lcov"
],
"collectCoverageFrom": [
"src/**/*.{js}"
],
"modulePathIgnorePatterns": [
"<rootDir>/dist/",
"<rootDir>/templates/"
],
"testPathIgnorePatterns": [
"<rootDir>[/\\\\](dist|templates|node_modules)[/\\\\]"
],
"verbose": true
Moving back to Node 6 seems to fix the issue.
Had issues with v7.3.0, but upgraded to v8.5.0 and console outputs are visible again.