From 40667c5a2a1e6fd697f1f81b4eb6d108f3e47e64 Mon Sep 17 00:00:00 2001 From: aqemi <2773683+aqemi@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:17:24 +0300 Subject: [PATCH] fix: pass error-like objects (#505) --- test/basic.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/basic.test.js b/test/basic.test.js index 0201e69..150f1e2 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -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' })