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

Logs missing in Jest tests #480

Open
OliverJAsh opened this issue Nov 24, 2023 · 4 comments
Open

Logs missing in Jest tests #480

OliverJAsh opened this issue Nov 24, 2023 · 4 comments
Labels
bug Something isn't working documentation

Comments

@OliverJAsh
Copy link
Contributor

I am following the recommendation here: https://github.com/pinojs/pino-pretty/tree/db278755318e2f1c565df736bbedd7eb7a2fd73f#usage-with-jest

Reduced test case:

package.json:

{
  "dependencies": {
    "jest": "^29.7.0",
    "pino": "^8.16.2",
    "pino-pretty": "^10.2.3"
  }
}

test.js:

const pino = require('pino')
const pretty = require('pino-pretty')

test('test pino-pretty', () => {
  const logger = pino(pretty({ sync: true }));
  logger.info('Info');
  logger.error('Error');
});

When I run jest test.js I get this output:

 RUNS  ./test.js
 PASS  ./test.jsNFO (81668): Info
  ✓ test pino-pretty (6 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.129 s, estimated 1 s
Ran all test suites matching /test.js/i.
✨  Done in 0.37s.
  • The info message is partially truncated.
  • The error message is missing.
@jsumners
Copy link
Member

All I can suggest is that if you need to verify the final NDJSON of individual logs, you should supply a stream that collects the logs and then inspect that collection. See pinojs/pino#1274 (comment).

@mcollina mcollina added bug Something isn't working documentation labels Nov 25, 2023
@mcollina
Copy link
Member

I think we have a bug in our docs, I don't think Jest would ever render things correctly.

@FiveOFive
Copy link

FiveOFive commented Jan 30, 2024

I think we have a bug in our docs, I don't think Jest would ever render things correctly.

Is that confirmed that Jest won't ever render correctly? I'm also trying to follow those docs but it seems like even with sync: true the log entries are still showing up after tests

@Ugikie
Copy link

Ugikie commented Apr 17, 2024

Confirming this because I'm also using sync: true and jest is still complaining about open handles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation
Projects
None yet
Development

No branches or pull requests

5 participants