Skip to content
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

React-scripts test is swallowing console logs, warnings, and errors #1368

Closed
zachfedor opened this issue Jan 10, 2017 · 16 comments
Closed

React-scripts test is swallowing console logs, warnings, and errors #1368

zachfedor opened this issue Jan 10, 2017 · 16 comments

Comments

@zachfedor
Copy link

Can you reproduce the problem with latest npm?

Yes, I'm already on npm@4.0.5.

Description

Create a new app:

create-react-app test-app
cd test-app

Add the following tests to src/App.test.js:

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

  1. npm ls react-scripts (if you haven’t ejected): 0.8.5

  2. node -v: v7.4.0

  3. npm -v: 4.0.5

  4. Operating system: OSX 10.11.6

  5. Browser and version: n/a

Reproducible Demo

See description

@zachfedor
Copy link
Author

I know this might end up being an issue with jest, but I figured I'd start here because I'm unsure how react-scripts is wrapping the test runner.

@gaearon
Copy link
Contributor

gaearon commented 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.0 fixes the issue?

@gaearon
Copy link
Contributor

gaearon commented 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.js and verify npm test at the top level swallows them.

Then you could bump Jest package versions in packages/react-scripts/package.json and run npm install there.

Then run npm test at the top level again and verify it works this time.

@zachfedor
Copy link
Author

zachfedor commented 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-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?

@gaearon
Copy link
Contributor

gaearon commented 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
Copy link
Author

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
Copy link
Contributor

gaearon commented 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
Copy link
Author

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
Copy link

ezhlobo commented Jan 15, 2017

@gaearon I think 0.8.6 will be better for Jest updating and bug fixes

@gaearon
Copy link
Contributor

gaearon commented Jan 15, 2017

We can't cut 0.8.6 for this because Jest 17 => 18 contained breaking changes.

@gaearon
Copy link
Contributor

gaearon commented Feb 11, 2017

Appears fixed with react-scripts@0.9.0 which contains Jest 18.

screen shot 2017-02-11 at 21 44 42

@gaearon gaearon closed this as completed Feb 11, 2017
@zachfedor
Copy link
Author

thanks for the fix!

@gaearon
Copy link
Contributor

gaearon commented Feb 14, 2017

Thank you for reporting!

@nvh95
Copy link
Contributor

nvh95 commented Jun 11, 2018

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.

@jb-1980
Copy link

jb-1980 commented 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=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"

jestjs/jest#2441 (comment)

@PontusNyberg
Copy link

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"

@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants