Open OliverJAsh opened 9 months ago
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 https://github.com/pinojs/pino/issues/1274#issuecomment-997971329.
I think we have a bug in our docs, I don't think Jest would ever render things correctly.
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
Confirming this because I'm also using sync: true
and jest is still complaining about open handles
I was able to workaround this by using prettyFactory
directly in tests. I've tried configuring { sync: true }
, using as transport
, destination
and other things and wasn't able to get all log messages to show up. It seems like there's still something stuck in the buffer even when using { sync: true }
, and i'm not sure if it has something to do with the event-based nature of sonic-boom not playing well with jest or what, but this is working (well enough) for me.
// foo.ts
import pino from 'pino';
import PinoPretty, { prettyFactory } from 'pino-pretty';
const getPino = () => {
const isJest = !!process.env.JEST_WORKER_ID;
if (isJest) {
const prettify = prettyFactory({ sync: true });
// configure custom stream that forwards pretty message to console
return pino({}, {
write(data: unknown) {
console.log(prettify(data));
},
});
}
return pino({}, PinoPretty());
};
export const foo = () => {
const logger = getPino();
console.log('console test');
logger.info('pino test');
};
I am following the recommendation here: https://github.com/pinojs/pino-pretty/tree/db278755318e2f1c565df736bbedd7eb7a2fd73f#usage-with-jest
Reduced test case:
package.json
:test.js
:When I run
jest test.js
I get this output: