You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
React-scripts test is swallowing console logs, warnings, and errors #1368
it('should log when test passes', () => {
console.log('test');
console.warn('test');
console.error('test');
expect(0).toEqual(0);
});
it('should log when test fails', () => {
console.log('test');
console.warn('test');
console.error('test');
expect(0).toEqual(1);
});
Run the tests with either yarn or npm.
Expected behavior
I would expect any of these console statements to print to stdout somewhere in the test output.
Actual behavior
The test output shows two passing tests and one failing test, as expected, along with the usual general test info and commands. But the logged output is nowhere to be found.
Environment
npm ls react-scripts (if you haven’t ejected): 0.8.5
Alright, I cloned CRA and added tests with logging. Passing and failing tests show all expected console output. I attempted to generate an app with my clone of CRA with npm run create-react-app test-app and went through the same steps as before. This had the expected output as well.
So this must mean it's an environment thing for me, right? What is different between testing the templates within my clone of CRA vs. testing a generated app with my clone of CRA (both of which have the proper output)? And how was my globally installed npm package of CRA any different to cause the initial issue?
We updated Jest in master to 18.0 in #1311 but it’s not in any CRA release yet. So maybe that fixed it for you? Can you try reverting that commit locally?
i know 0.8.5 was only released 5 days ago, so I'm assuming the 0.9 release might be a while. that's totally fine. is there anything I might be able to do in the meantime as a workaround?
Hi @gaearon
How can I make console.log map where they are called if I am using Jest (20). I am not using react-scripts. Or if you have any reference, can you post it here?
Thank you very much.
This issue has been closed for a while, but it popped again for me today. For those who may also be looking for a solution over a year later, some searching suggested that adding the --verbose=false flag may resolve it. Indeed, it did.
Specifically, in package.json I updated the line for the test script to be "test": "react-scripts test --env=jsdom --verbose=false"
I fell over this yesterday as well but it turned out that without 'watch' it worked. run the following on windows for test now "set CI=true && react-scripts test"
Activity
zachfedor commentedon Jan 10, 2017
I know this might end up being an issue with
jest, but I figured I'd start here because I'm unsure howreact-scriptsis wrapping the test runner.gaearon commentedon Jan 10, 2017
This might be an issue with Jest on Node 7:
jestjs/jest#2457
nodejs/node#10492
Can you clone CRA and verify whether upgrading Jest packages to
18.1.0fixes the issue?gaearon commentedon Jan 10, 2017
In particular you'd need to clone the repo and run
npm install.Then you could put some logs in
packages/react-scripts/template/src/App.test.jsand verifynpm testat the top level swallows them.Then you could bump Jest package versions in
packages/react-scripts/package.jsonand runnpm installthere.Then run
npm testat the top level again and verify it works this time.zachfedor commentedon Jan 10, 2017
Alright, I cloned CRA and added tests with logging. Passing and failing tests show all expected console output. I attempted to generate an app with my clone of CRA with
npm run create-react-app test-appand went through the same steps as before. This had the expected output as well.So this must mean it's an environment thing for me, right? What is different between testing the templates within my clone of CRA vs. testing a generated app with my clone of CRA (both of which have the proper output)? And how was my globally installed npm package of CRA any different to cause the initial issue?
gaearon commentedon Jan 10, 2017
We updated Jest in master to 18.0 in #1311 but it’s not in any CRA release yet. So maybe that fixed it for you? Can you try reverting that commit locally?
zachfedor commentedon Jan 10, 2017
Yup, that worked. I reverted to #1274, the commit previous to #1311, and there was no logged output. I then checked out #1311 and the output is there.
gaearon commentedon Jan 10, 2017
Maybe we can cut 0.9 with just the Jest update and a few fixes, and postpone bigger plans for 0.10. @fson What do you think?
zachfedor commentedon Jan 15, 2017
i know 0.8.5 was only released 5 days ago, so I'm assuming the 0.9 release might be a while. that's totally fine. is there anything I might be able to do in the meantime as a workaround?
ezhlobo commentedon Jan 15, 2017
@gaearon I think 0.8.6 will be better for Jest updating and bug fixes
gaearon commentedon Jan 15, 2017
We can't cut 0.8.6 for this because Jest 17 => 18 contained breaking changes.
gaearon commentedon Feb 11, 2017
Appears fixed with
react-scripts@0.9.0which contains Jest 18.zachfedor commentedon Feb 14, 2017
thanks for the fix!
gaearon commentedon Feb 14, 2017
Thank you for reporting!
nvh95 commentedon Jun 11, 2018
Hi @gaearon
How can I make
console.logmap where they are called if I am using Jest (20). I am not usingreact-scripts. Or if you have any reference, can you post it here?Thank you very much.
jb-1980 commentedon Nov 10, 2018
This issue has been closed for a while, but it popped again for me today. For those who may also be looking for a solution over a year later, some searching suggested that adding the
--verbose=falseflag may resolve it. Indeed, it did.Specifically, in package.json I updated the line for the test script to be
"test": "react-scripts test --env=jsdom --verbose=false"jestjs/jest#2441 (comment)
PontusNyberg commentedon Nov 16, 2018
I fell over this yesterday as well but it turned out that without 'watch' it worked. run the following on windows for test now "set CI=true && react-scripts test"