You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pino's deprecated prettyPrint and its problem with Jest #3
But starting on this tutorial for testing I found a head-scratching error faced me when using --detectOpenHandles:
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● WORKER
4 | const testMode = process.env.NODE_ENV === "test";
5 |
> 6 | const log = logger({
| ^
After a short amount of Googling I found that the transport option was to blame. To check, I restored prettyPrint: true, removed transport: {...} and the error disappeared.
I don't know if this is perhaps the best method to fix it, but noticing that the env variable NODE_ENV was set when running jest (which is then utilized by config to switch to a different config file, test.js) I decided to take advantage of it and wrote this adjustment:
// NODE_ENV is set to "test" when jest is running.
const inTest = process.env.NODE_ENV === "test";
const log = logger({
enabled: !inTest,
transport: !inTest ? {
target: "pino-pretty",
options: {
colorize: true,
},
} : undefined,
base: {
pid: false,
},
timestamp: () => `,"time":"${dayjs().format()}"`,
});
Activity