Skip to content

Commit

Permalink
fix: checks for undefined specifically instead of falsey values
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmohammad committed Jul 1, 2023
1 parent 425414b commit ee1dc40
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function prettyFactory (options) {
line += ':'
}

if (prettifiedMessage) {
if (prettifiedMessage !== undefined) {
if (line.length > 0) {
line = `${line} ${prettifiedMessage}`
} else {
Expand Down
22 changes: 19 additions & 3 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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' })
Expand Down

0 comments on commit ee1dc40

Please sign in to comment.