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.

console.log is weirdly-formatted and too verbose after upgrading jest from 24.8.0 to 26.1.0

See original GitHub issue

💥 Regression Report

I’m running end-to-end tests using jest and the tests are doing a lot of console.log for debugging purposes. Today I’ve upgraded jest from 24.8.0 to 26.1.0 and noticed the console.log output now looks different - it seems to include the stack trace of the logged line along with blank lines - which makes the output extremely long and barely readable.

Output with v26.1.0:

17:54:33 PASS src/tests/archiveProgram.test.ts (16.865 s)
17:54:33   ● Console
17:54:33 
17:54:33     console.log
17:54:33       Launching Puppeteer...
17:54:33 
17:54:33       at Object.initSession (src/TestRunner.ts:38:17)
17:54:33 
17:54:33     console.log
17:54:33       Puppeteer is running on local environment
17:54:33 
17:54:33       at getBrowser (src/TestRunner.ts:68:17)
17:54:33 
17:54:33     console.log
17:54:33       Puppeteer launched successfully
17:54:33 
17:54:33       at Object.initSession (src/TestRunner.ts:40:17)
17:54:33 
17:54:33     console.log
17:54:33       Opening browser...
17:54:33 
17:54:33       at Object.initSession (src/TestRunner.ts:42:17)
17:54:33 
17:54:33     console.log
17:54:33       Browser opened successfully
17:54:33 
17:54:33       at Object.initSession (src/TestRunner.ts:44:17)
17:54:33 
17:54:33     console.log
17:54:33       Logging in to Studio...
17:54:33 
17:54:33       at Object.exports.loginAndNavigateToAccountPage (src/common/actions/hubUIActions.ts:244:13)
17:54:33 
17:54:33     console.log
17:54:33       Looking for introduction dialog
17:54:33 
17:54:33       at handleIntroductionNewStudioNavigationDialog (src/common/actions/hubUIActions.ts:139:13)
17:54:33 
17:54:33     console.log
17:54:33       Logged in successfully
17:54:33 
17:54:33       at Object.exports.loginAndNavigateToAccountPage (src/common/actions/hubUIActions.ts:246:13)
17:54:33 
17:54:33     console.log
17:54:33       Navigating to account ID 0010b00002R0wc3AAB...
17:54:33 
17:54:33       at Object.exports.loginAndNavigateToAccountPage (src/common/actions/hubUIActions.ts:248:13)
17:54:33 
17:54:33     console.log
17:54:33       Navigation completed
17:54:33 
17:54:33       at Object.exports.loginAndNavigateToAccountPage (src/common/actions/hubUIActions.ts:251:13)
17:54:33 
17:54:33     console.log
17:54:33       Creating new program "Archive program E2E Test 27-7-2020-14-54-28-774"...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:30:21)
17:54:33 
17:54:33     console.log
17:54:33       Navigating to "All Programs"...
17:54:33 
17:54:33       at Object.exports.createNewProgram (src/common/actions/hubUIActions.ts:151:13)
17:54:33 
17:54:33     console.log
17:54:33       Opening New Program dialog...
17:54:33 
17:54:33       at Object.exports.createNewProgram (src/common/actions/hubUIActions.ts:160:13)
17:54:33 
17:54:33     console.log
17:54:33       Setting program name...
17:54:33 
17:54:33       at Object.exports.createNewProgram (src/common/actions/hubUIActions.ts:165:13)
17:54:33 
17:54:33     console.log
17:54:33       Setting program type...
17:54:33 
17:54:33       at Object.exports.createNewProgram (src/common/actions/hubUIActions.ts:169:13)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       Saving program...
17:54:33 
17:54:33       at Object.exports.createNewProgram (src/common/actions/hubUIActions.ts:173:13)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       Program created successfully
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:32:21)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       Verifying that we are under All but Archived filter...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:53:27)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       clicking program's context menu and selecting Archive...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:56:27)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       clicking confirmation to Archive program...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:62:27)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       expecting the program that have been archive to disappear from view...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:66:27)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       setting drawer filter to archived
17:54:33 
17:54:33       at Object.exports.selectMainProgramsDrawerFilter (src/common/actions/hubUIActions.ts:194:19)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       Verifying that we are under archived filter...
17:54:33 
17:54:33       at Object.exports.selectMainProgramsDrawerFilter (src/common/actions/hubUIActions.ts:198:19)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       expecting the program that have been archive to appear in drawer...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:70:27)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       clicking program's context menu and selecting Unarchive...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:73:27)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       expecting the program that have been archive to disappear from view...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:77:27)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       setting drawer filter to notArchived
17:54:33 
17:54:33       at Object.exports.selectMainProgramsDrawerFilter (src/common/actions/hubUIActions.ts:194:19)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       Verifying that we are under notArchived filter...
17:54:33 
17:54:33       at Object.exports.selectMainProgramsDrawerFilter (src/common/actions/hubUIActions.ts:198:19)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       expecting the program that have been unarchive to appear in drawer...
17:54:33 
17:54:33       at Object.<anonymous> (src/tests/archiveProgram.test.ts:81:27)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       Test took 4.413138531 seconds
17:54:33 
17:54:33       at Object.stopTestTiming (src/TestRunner.ts:101:17)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       Closing browser...
17:54:33 
17:54:33       at Object.terminateSession (src/TestRunner.ts:135:17)
17:54:33           at runMicrotasks (<anonymous>)
17:54:33 
17:54:33     console.log
17:54:33       Browser closed successfully
17:54:33 
17:54:33       at Object.terminateSession (src/TestRunner.ts:137:17)
17:54:33 

Output with v24.8.0:

15:55:31 PASS src/tests/archiveProgram.test.ts (16.69s)
15:55:31   ● Console
15:55:31 
15:55:31     console.log src/TestRunner.ts:38
15:55:31       Launching Puppeteer...
15:55:31     console.log src/TestRunner.ts:68
15:55:31       Puppeteer is running on local environment
15:55:31     console.log src/TestRunner.ts:40
15:55:31       Puppeteer launched successfully
15:55:31     console.log src/TestRunner.ts:42
15:55:31       Opening browser...
15:55:31     console.log src/TestRunner.ts:44
15:55:31       Browser opened successfully
15:55:31     console.log src/common/actions/hubUIActions.ts:239
15:55:31       Logging in to Studio...
15:55:31     console.log src/common/actions/hubUIActions.ts:134
15:55:31       Looking for introduction dialog
15:55:31     console.log src/common/actions/hubUIActions.ts:241
15:55:31       Logged in successfully
15:55:31     console.log src/common/actions/hubUIActions.ts:243
15:55:31       Navigating to account ID 0010b00002R0wc3AAB...
15:55:31     console.log src/common/actions/hubUIActions.ts:246
15:55:31       Navigation completed
15:55:31     console.log src/tests/archiveProgram.test.ts:29
15:55:31       Creating new program "Archive program E2E Test 27-7-2020-12-55-27-46"...
15:55:31     console.log src/common/actions/hubUIActions.ts:146
15:55:31       Navigating to "All Programs"...
15:55:31     console.log src/common/actions/hubUIActions.ts:155
15:55:31       Opening New Program dialog...
15:55:31     console.log src/common/actions/hubUIActions.ts:160
15:55:31       Setting program name...
15:55:31     console.log src/common/actions/hubUIActions.ts:164
15:55:31       Setting program type...
15:55:31     console.log src/common/actions/hubUIActions.ts:168
15:55:31       Saving program...
15:55:31     console.log src/tests/archiveProgram.test.ts:31
15:55:31       Program created successfully
15:55:31     console.log src/tests/archiveProgram.test.ts:52
15:55:31       Verifying that we are under All but Archived filter...
15:55:31     console.log src/tests/archiveProgram.test.ts:55
15:55:31       clicking program's context menu and selecting Archive...
15:55:31     console.log src/tests/archiveProgram.test.ts:61
15:55:31       clicking confirmation to Archive program...
15:55:31     console.log src/tests/archiveProgram.test.ts:65
15:55:31       expecting the program that have been archive to disappear from view...
15:55:31     console.log src/common/actions/hubUIActions.ts:189
15:55:31       setting drawer filter to archived
15:55:31     console.log src/common/actions/hubUIActions.ts:193
15:55:31       Verifying that we are under archived filter...
15:55:31     console.log src/tests/archiveProgram.test.ts:69
15:55:31       expecting the program that have been archive to appear in drawer...
15:55:31     console.log src/tests/archiveProgram.test.ts:72
15:55:31       clicking program's context menu and selecting Unarchive...
15:55:31     console.log src/tests/archiveProgram.test.ts:76
15:55:31       expecting the program that have been archive to disappear from view...
15:55:31     console.log src/common/actions/hubUIActions.ts:189
15:55:31       setting drawer filter to notArchived
15:55:31     console.log src/common/actions/hubUIActions.ts:193
15:55:31       Verifying that we are under notArchived filter...
15:55:31     console.log src/tests/archiveProgram.test.ts:80
15:55:31       expecting the program that have been unarchive to appear in drawer...
15:55:31     console.log src/TestRunner.ts:101
15:55:31       Test took 4.628601666000001 seconds
15:55:31     console.log src/TestRunner.ts:135
15:55:31       Closing browser...
15:55:31     console.log src/TestRunner.ts:137
15:55:31       Browser closed successfully
15:55:31 

Last working version

Worked up to version: 24.8.0

Stopped working in version: based on checks I’ve made, the output format changed since version 25.0.0

To Reproduce

  1. Have jest 24.8.0 installed
  2. Have a test with multiple console.log commands
  3. Run the test. console.log format is dense and concise
  4. Upgrade jest to any version >= 25.0.0
  5. Run the test. console.log format is too verbose and off-format

Expected behavior

console.log output format to be dense and concise:

  • No stack trace
  • No many blank lines
  • Line number in the same line as the console.log command

npx envinfo --preset jest

  System:
    OS: Windows 10 10.0.17134
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  Binaries:
    Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: 26.1.0 => 26.1.0

package.json:

{
  "dependencies": {
    "@sundaysky/smartvideo-hub-s3": "^1.4.8",
    "@types/jest": "26.0.7",
    "@types/puppeteer": "^3.0.1",
    "@typescript-eslint/eslint-plugin": "3.7.0",
    "@typescript-eslint/parser": "3.7.0",
    "aws-sdk": "2.720.0",
    "faker": "4.1.0",
    "jest": "26.1.0",
    "jest-image-snapshot": "4.1.0",
    "puppeteer": "5.2.1",
    "tmp": "0.2.1",
    "ts-jest": "26.1.3",
    "typescript": "3.9.7"
  },
  "devDependencies": {
    "eslint": "7.5.0",
    "eslint-plugin-jest": "23.18.2"
  },
  "jest": {
    "preset": "ts-jest"
  }
}

Can I revert to the previous format without having to revert jest version? Or is there a way to custom format the output myself?

Thanks!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:61
  • Comments:20

github_iconTop GitHub Comments

26reactions
ysfarancommented, Jan 19, 2021

Is there any update on this?

I also agree that the current logs are too verbose and not really nice to read. As suggested above, options to remove or adapt custom console.log statements would do great.

It would also be nice to have full control over how console logs are output e.g. with template strings in the jest config that allow to use predefined variables e.g.

logPattern: "{{timestamp}} {{file}}:\n{{log}}"

or simply with a lambda:

jest.logPattern((log, { file, timestamp }) => `${timestamp} ${file}:\n${log})`

This would mitigate issues like this one in the future.

can be fixed by #9127

14reactions
viochacommented, Jun 20, 2022

is there any progress? i have come across the same problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Console.log statements output nothing at all in Jest
Jest suppresses the console log message by default. ... Try setting verbose: false (or removing it) in the jest options in package.json.
Read more >
Jest Platform
print the set of modified files since last commit in the current repo getChangedFilesForRoots(['./'], { ... console.log('Hello World!');
Read more >
builtins.mock JavaScript and Node.js code examples - Tabnine
test('Log.info - Log.space should only be called the first time a Log function is run', () => { console.log = jest.fn(); console.info =...
Read more >
Debugging | Testing Library
Debugging. Automatic Logging​. When any get or find calls you use in your test cases fail, the current state of the container (DOM)...
Read more >
Why so loud, jest? - Xolvio
log (warnings, errors, etc) messages to the console. That's great - it helps you understand what's going on in your code when tests...
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