From ee1dc4042faab3599737f26cf7e5a36a2947f2a4 Mon Sep 17 00:00:00 2001 From: rjmohammad Date: Sat, 1 Jul 2023 01:14:26 -0400 Subject: [PATCH] fix: checks for undefined specifically instead of falsey values --- index.js | 2 +- test/basic.test.js | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 000a873c..41eb7602 100644 --- a/index.js +++ b/index.js @@ -162,7 +162,7 @@ function prettyFactory (options) { line += ':' } - if (prettifiedMessage) { + if (prettifiedMessage !== undefined) { if (line.length > 0) { line = `${line} ${prettifiedMessage}` } else { diff --git a/test/basic.test.js b/test/basic.test.js index 8514c416..9986811c 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -133,7 +133,7 @@ test('basic prettifier tests', (t) => { })) log.info('baz') }) - + t.test('can print message key value when its a number', (t) => { t.plan(1) const pretty = prettyFactory() @@ -149,7 +149,23 @@ test('basic prettifier tests', (t) => { })) log.info(42) }) - + + t.test('can print message key value when its a Number(0)', (t) => { + t.plan(1) + const pretty = prettyFactory() + const log = pino({}, new Writable({ + write (chunk, enc, cb) { + const formatted = pretty(chunk.toString()) + t.equal( + formatted, + `[${formattedEpoch}] INFO (${pid}): 0\n` + ) + cb() + } + })) + log.info(0) + }) + t.test('can print message key value when its a boolean', (t) => { t.plan(1) const pretty = prettyFactory() @@ -165,7 +181,7 @@ test('basic prettifier tests', (t) => { })) log.info(true) }) - + t.test('can use different message keys', (t) => { t.plan(1) const pretty = prettyFactory({ messageKey: 'bar' })