question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
gaearoncommented, 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?

2reactions
jb-1980commented, 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"

https://github.com/facebook/jest/issues/2441#issuecomment-424310466

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-scripts test is swallowing console logs, warnings, and errors
React -scripts test is swallowing console logs, warnings, and errors. ... React-scripts test is swallowing console logs, warnings, and errors.
Read more >
Console.log statements output nothing at all in Jest
Run console.debug('Message here', yourValueHere) inside test function and it should show in the console output when running test script. You can ...
Read more >
jest console log after tests are done - You.com | The AI Search ...
I was using the react-native default test case (see below) when Cannot log after ... Attempted to log "Warning: NOT valid form element"....
Read more >
Changelog - Cypress Documentation
Compile errors are now surfaced in the command log during tests for Angular ... Add a warning for users on the old React...
Read more >
How does MDN Intercept `console.log`? | DevLog 003
MDN's interactive examples override the browser's console.log, formats the arguments for ... I created a component in React that accomplishes the same thing....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found