Title: Pino's deprecated prettyPrint and its problem with Jest · Issue #3 · TomDoesTech/Testing-Express-REST-API · GitHub
Open Graph Title: Pino's deprecated prettyPrint and its problem with Jest · Issue #3 · TomDoesTech/Testing-Express-REST-API
X Title: Pino's deprecated prettyPrint and its problem with Jest · Issue #3 · TomDoesTech/Testing-Express-REST-API
Description: I have the solution to this issue, I just wanted to share it. I noticed when working on the previous chapter of this tutorial that pino complains saying that prettyPrint is deprecated for the logger(). (node:54078) [PINODEP008] PinoWarni...
Open Graph Description: I have the solution to this issue, I just wanted to share it. I noticed when working on the previous chapter of this tutorial that pino complains saying that prettyPrint is deprecated for the logge...
X Description: I have the solution to this issue, I just wanted to share it. I noticed when working on the previous chapter of this tutorial that pino complains saying that prettyPrint is deprecated for the logge...
Opengraph URL: https://github.com/TomDoesTech/Testing-Express-REST-API/issues/3
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pino's deprecated prettyPrint and its problem with Jest","articleBody":"I have the solution to this issue, I just wanted to share it.\r\n\r\nI noticed when working on the previous chapter of this tutorial that pino complains saying that prettyPrint is deprecated for the logger().\r\n\r\n```\r\n(node:54078) [PINODEP008] PinoWarning: prettyPrint is deprecated, look at https://github.com/pinojs/pino-pretty for alternatives.\r\n```\r\n\r\nSo, I found that the preferred method is using a transport option, like so:\r\n\r\nBefore\r\n```\r\nconst log = logger({\r\n prettyPrint: true,\r\n base: {\r\n pid: false,\r\n },\r\n timestamp: () =\u003e `,\"time\":\"${dayjs().format()}\"`,\r\n});\r\n```\r\nAfter\r\n```\r\nconst log = logger({\r\n transport: {\r\n target: \"pino-pretty\",\r\n options: {\r\n colorize: true,\r\n },\r\n },\r\n base: {\r\n pid: false,\r\n },\r\n timestamp: () =\u003e `,\"time\":\"${dayjs().format()}\"`,\r\n});\r\n```\r\n\r\nBut starting on this tutorial for testing I found a head-scratching error faced me when using `--detectOpenHandles`:\r\n```\r\nJest has detected the following 1 open handle potentially keeping Jest from exiting:\r\n\r\n ● WORKER\r\n\r\n 4 | const testMode = process.env.NODE_ENV === \"test\";\r\n 5 |\r\n \u003e 6 | const log = logger({\r\n | ^\r\n```\r\n\r\nAfter 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.\r\n\r\nI 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:\r\n\r\n```\r\n// NODE_ENV is set to \"test\" when jest is running.\r\nconst inTest = process.env.NODE_ENV === \"test\";\r\n\r\nconst log = logger({\r\n enabled: !inTest,\r\n transport: !inTest ? {\r\n target: \"pino-pretty\",\r\n options: {\r\n colorize: true,\r\n },\r\n } : undefined,\r\n base: {\r\n pid: false,\r\n },\r\n timestamp: () =\u003e `,\"time\":\"${dayjs().format()}\"`,\r\n});\r\n```\r\nThat solved it and I hope this is helpful.","author":{"url":"https://github.com/TiE23","@type":"Person","name":"TiE23"},"datePublished":"2022-04-14T18:57:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/3/Testing-Express-REST-API/issues/3"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:79295a68-8967-2337-7dc0-d8105b4b3cff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC6C:F4A23:4617A3:5F556A:698E2178 |
| html-safe-nonce | 7d45f5f46938da3c27479b813a440695269fe7b86d5aa3b6ee95289e03db98fa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzZDOkY0QTIzOjQ2MTdBMzo1RjU1NkE6Njk4RTIxNzgiLCJ2aXNpdG9yX2lkIjoiMTkxNTQzNDk1Nzg5MjU3MDgxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b9cfc165ca3eae4390696339f06c05c229c9da2fb3215b30ae876d4c9c9efb8f |
| hovercard-subject-tag | issue:1204875984 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TomDoesTech/Testing-Express-REST-API/3/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f2b62a01c934eb6f180e73d0cc35d197f7ae86626ddcee86837e9af9351920c3/TomDoesTech/Testing-Express-REST-API/issues/3 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f2b62a01c934eb6f180e73d0cc35d197f7ae86626ddcee86837e9af9351920c3/TomDoesTech/Testing-Express-REST-API/issues/3 |
| og:image:alt | I have the solution to this issue, I just wanted to share it. I noticed when working on the previous chapter of this tutorial that pino complains saying that prettyPrint is deprecated for the logge... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TiE23 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d71262819a4a68a7786924c05495bfd40a7561e4258dd129ba36f53d667639a |
| turbo-cache-control | no-preview |
| go-import | github.com/TomDoesTech/Testing-Express-REST-API git https://github.com/TomDoesTech/Testing-Express-REST-API.git |
| octolytics-dimension-user_id | 82136854 |
| octolytics-dimension-user_login | TomDoesTech |
| octolytics-dimension-repository_id | 415179365 |
| octolytics-dimension-repository_nwo | TomDoesTech/Testing-Express-REST-API |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 415179365 |
| octolytics-dimension-repository_network_root_nwo | TomDoesTech/Testing-Express-REST-API |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1d904ac995eb43f93014fbdbcc9ae5878653c932 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width