Skip to content

Commit

Permalink
fix: pass error-like objects (pinojs#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
aqemi committed Apr 24, 2024
1 parent 6f0ecf0 commit 40667c5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/basic.test.js
Expand Up @@ -918,6 +918,32 @@ test('basic prettifier tests', (t) => {
t.equal(arst, 'INFO: hello world\n')
})

t.test('log error-like object', (t) => {
t.plan(7)
const expectedLines = [
' type: "Error"',
' message: "m"',
' stack: [',
' "line1",',
' "line2"',
' ]'
]
const pretty = prettyFactory()
const log = pino({}, new Writable({
write (chunk, enc, cb) {
const formatted = pretty(chunk.toString())
const lines = formatted.split('\n')
t.equal(lines.length, expectedLines.length + 2)
lines.shift(); lines.pop()
for (let i = 0; i < lines.length; i += 1) {
t.equal(lines[i], expectedLines[i])
}
cb()
}
}))
log.error({ type: 'Error', message: 'm', stack: ['line1', 'line2'] })
})

t.test('include should override ignore', (t) => {
t.plan(1)
const pretty = prettyFactory({ ignore: 'time,level', include: 'time,level' })
Expand Down

0 comments on commit 40667c5

Please sign in to comment.