test('sync false logs everything when calling flushSync', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'syncfalse-flush-exit.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(actual.match(/hello/), null) isNot(actual.match(/world/), null) })
function capture () { const ws = writer((chunk, enc, cb) => { ws.data += chunk.toString() cb() }) ws.data = '' return ws }
test('do not use SonicBoom is someone tampered with process.stdout.write', async ({ isNot }) => { var actual = '' const child = fork(join(__dirname, 'fixtures', 'stdout-hack-protection.js'), { silent: true }) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(actual.match(/^hack/), null) })
test('errors with props', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'error-props.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): kaboom/), null) isNot(strip(actual).match(/code: ENOENT/), null) isNot(strip(actual).match(/errno: 1/), null) isNot(strip(actual).match(/.*error-props\.js.*/), null) })
test('with custom timestamp', async ({ is }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'custom-time.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') is(strip(actual).slice(0, 6), '[test]') })
test('sync false does not log everything when calling process.exit(0)', async ({ is }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'syncfalse-exit.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') is(actual.match(/hello/), null) is(actual.match(/world/), null) })
test('applies redaction rules', async ({ is, isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'redact.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h/), null) isNot(strip(actual).match(/\[Redacted\]/), null) is(strip(actual).match(/object/), null) })
test('without timestamp', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'no-time.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).slice(2), '[]') })
test('final works without prior logging', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'final-no-log-before.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/WARN\s+: pino.final with prettyPrint does not support flushing/), null) isNot(strip(actual).match(/INFO\s+\(123456 on abcdefghijklmnopqr\): beforeExit/), null) })
test('suppress flush sync warning when corresponding option is specified', async ({ isNot, is }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'suppress-flush-sync-warning.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') is(strip(actual).match(/WARN\s+\(123456 on abcdefghijklmnopqr\): pino.final with prettyPrint does not support flushing/), null) })
test('can be enabled via exported pino function with pretty configuration', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'level-first.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/^INFO.*h/), null) })
// https://github.com/pinojs/pino/issues/542 test('pino.destination log everything when calling process.exit(0)', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'destination-exit.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(actual.match(/hello/), null) isNot(actual.match(/world/), null) })
test('applies serializers', async ({ is, isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'serializers.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h/), null) isNot(strip(actual).match(/foo: "bar"/), null) })
test('can be enabled via exported pino function', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'basic.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h/), null) })
test('dateformat', async ({ isNot }) => { var actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'dateformat.js')]) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(strip(actual).match(/\(123456 on abcdefghijklmnopqr\): h/), null) })