laabr
Version:
well-formatted, extendable pino logger for hapi.js
60 lines (54 loc) • 2.55 kB
JavaScript
const test = require('ava')
const laabr = require('../src')
const formats = require('../src/formats')
test('throw error if format arguments are invalid – key', (t) => {
t.throws(() => laabr.format(null, ':foobar'))
t.throws(() => laabr.format(false, ':foobar'))
t.throws(() => laabr.format(NaN, ':foobar'))
t.throws(() => laabr.format(42, ':foobar'))
t.throws(() => laabr.format('', ':foobar'))
t.throws(() => laabr.format('foobar', ':foobar'))
t.throws(() => laabr.format({}, ':foobar'))
t.throws(() => laabr.format([], ':foobar'))
t.throws(() => laabr.format(new RegExp(), ':foobar'))
})
test('throw error if format arguments are invalid – format', (t) => {
t.throws(() => laabr.format('log', null))
t.throws(() => laabr.format('log', true))
t.throws(() => laabr.format('log', NaN))
t.throws(() => laabr.format('log', 42))
t.throws(() => laabr.format('log', ''))
t.throws(() => laabr.format('log', {}))
t.throws(() => laabr.format('log', []))
t.throws(() => laabr.format('log', new RegExp()))
})
test('throw error if format preset already exists', (t) => {
t.throws(() => laabr.preset('log.tiny', false))
})
test('throw no error if format arguments are valid', (t) => {
t.notThrows(() => { laabr.format('log', ':foobar') })
t.notThrows(() => laabr.format('response', ':foobar'))
t.notThrows(() => laabr.format('request-error', ':foobar'))
t.notThrows(() => laabr.format('onPostStart', ':foobar'))
t.notThrows(() => laabr.format('onPostStop', ':foobar'))
t.notThrows(() => laabr.format('uncaught', ':foobar'))
t.is(formats.get('foobar'), ':foobar')
t.is(formats.get({ msg: 'request completed' }), ':foobar')
t.is(formats.get({ msg: 'request error' }), ':foobar')
t.is(formats.get({ msg: 'server started' }), ':foobar')
t.is(formats.get({ msg: 'server stopped' }), ':foobar')
t.is(formats.get({ tags: ['uncaught'] }), ':foobar')
t.notThrows(() => laabr.format('log', false))
t.notThrows(() => laabr.format('response', false))
t.notThrows(() => laabr.format('request-error', false))
t.notThrows(() => laabr.format('onPostStart', false))
t.notThrows(() => laabr.format('onPostStop', false))
t.is(formats.get('foobar'), false)
t.is(formats.get({ msg: 'request completed' }), false)
t.is(formats.get({ msg: 'request error' }), false)
t.is(formats.get({ msg: 'server started' }), false)
t.is(formats.get({ msg: 'server stopped' }), false)
})
test('throw no error if format preset does not already exist', (t) => {
t.notThrows(() => laabr.preset('log.dev', false))
})