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: github.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:d31f4e7d-a0a8-ecf2-7f13-8e1ed979d4ec |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8410:13D214:5A12CD:776733:698E5BD7 |
| html-safe-nonce | e448ad8a229159954126ffab3848fcf03c712d6fbfe71c076f69c395111ce3b7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDEwOjEzRDIxNDo1QTEyQ0Q6Nzc2NzMzOjY5OEU1QkQ3IiwidmlzaXRvcl9pZCI6Ijc3NzYxMTgyODkyMzk3OTI1OTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | bb8417c3bdb9e8a9a898f5489c5d08a871d42d4891caeea91022b3a99f2a82ce |
| 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 | 666e30cc1de8ebdf458084bf731e95deba4f074a5008f91b50803aa9a71e3725 |
| 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 | f2d67bd549813f8aceb31f205ebdb434e9d46d38 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width