pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.27k stars 150 forks source link

pino-pretty not working when running jest test #330

Closed jenrrycordero2022 closed 2 years ago

jenrrycordero2022 commented 2 years ago

Short Description:

I'm trying to build a logger module using Pino. Everything is good until I run our tests cases.

My code:

import pino from 'pino';

const logger = pino({
    transport: {
        level: 'info',
        target: 'pino-pretty',
        options: {
            colorize: true,
            levelFirst: true,
            translateTime: 'SYS:yyyy-mm-dd HH:MM:ss',
            ignore: 'pid,hostname',
        },
    },
});

try {
    // Some functionalities here...
} catch (e) {
        logger.error(`mvpd auth - getPopularMvpds: ${e}`);
}

This is the error when running: > yarn test

ReferenceError: setImmediate is not defined

  at ThreadStream.write (node_modules/thread-stream/index.js:245:7)
  at Pino.write (node_modules/pino/lib/proto.js:208:10)
  at Pino.error (node_modules/pino/lib/tools.js:60:21)

Screen Shot 2022-04-14 at 3 09 54 PM

mcollina commented 2 years ago

setImmediate is a global defined by Node.js. The fact that's not in your environment is the result of jest configuration.

jenrrycordero2022 commented 2 years ago

Thanks Matteo!