Skip to content

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

Closed

Description

@zachfedor

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

Activity

  1. zachfedor commented on Jan 10, 2017

    @zachfedor
    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.

  2. gaearon commented on Jan 10, 2017

    @gaearon
    Contributor

    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?

  3. gaearon commented on Jan 10, 2017

    @gaearon
    Contributor

    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.

  4. zachfedor commented on Jan 10, 2017

    @zachfedor
    Author

    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?

  5. gaearon commented on Jan 10, 2017

    @gaearon
    Contributor

    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?

  6. zachfedor commented on Jan 10, 2017

    @zachfedor
    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.

  7. gaearon commented on Jan 10, 2017

    @gaearon
    Contributor

    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?

  8. zachfedor commented on Jan 15, 2017

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

  9. ezhlobo commented on Jan 15, 2017

    @ezhlobo

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

  10. gaearon commented on Jan 15, 2017

    @gaearon
    Contributor

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

  11. gaearon commented on Feb 11, 2017

    @gaearon
    Contributor

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

    screen shot 2017-02-11 at 21 44 42

  12. zachfedor commented on Feb 14, 2017

    @zachfedor
    Author

    thanks for the fix!

  13. gaearon commented on Feb 14, 2017

    @gaearon
    Contributor

    Thank you for reporting!

  14. nvh95 commented on Jun 11, 2018

    @nvh95
    Contributor

    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.

  15. jb-1980 commented on Nov 10, 2018

    @jb-1980

    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)

  16. PontusNyberg commented on Nov 16, 2018

    @PontusNyberg

    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"

  17. locked and limited conversation to collaborators on Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions