Skip to content

Commit

Permalink
tests: test param lambdas, destructure t, switch to end always, tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmarkclements committed Jun 15, 2018
1 parent 41734bf commit 3c21d18
Show file tree
Hide file tree
Showing 23 changed files with 928 additions and 975 deletions.
Empty file modified bin.js
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { onTerminatedSym, streamSym } = require('./symbols')
function events (instance) {
const stream = instance[streamSym]

if (stream instanceof SonicBoom === true) {
if (stream instanceof SonicBoom) {
if (stream.fd === -1) {
stream.on('ready', register)
} else {
Expand Down
1 change: 1 addition & 0 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function getPrettyStream (opts, prettifier, dest) {
}
try {
var prettyFactory = require('pino-pretty')
prettyFactory.asMetaWrapper = asMetaWrapper
return asMetaWrapper(prettyFactory(opts), dest)
} catch (e) {
throw Error('Missing `pino-pretty` module: `pino-pretty` must be installed separately')
Expand Down
115 changes: 50 additions & 65 deletions test/add-level.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,58 @@ var test = require('tap').test
var sink = require('./helper').sink
var pino = require('../')

test('can add a custom level via constructor', function (t) {
t.plan(2)

test('can add a custom level via constructor', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino({level: 'foo', levelVal: 35}, sink(function (chunk, enc, cb) {
t.is(chunk.msg, 'bar')
cb()
is(chunk.msg, 'bar')
end()
}))

t.is(typeof log.foo, 'function')
is(typeof log.foo, 'function')
log.foo('bar')
})

test('can add a custom level to a prior instance', function (t) {
t.plan(2)

test('can add a custom level to a prior instance', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino(sink(function (chunk, enc, cb) {
t.is(chunk.msg, 'bar')
is(chunk.msg, 'bar')
end()
}))

log.addLevel('foo2', 35)
t.is(typeof log.foo2, 'function')
is(typeof log.foo2, 'function')
log.foo2('bar')
})

test('custom level via constructor does not affect other instances', function (t) {
t.plan(2)

test('custom level via constructor does not affect other instances', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino({level: 'foo3', levelVal: 36})
var other = pino()
t.is(typeof log.foo3, 'function')
t.is(typeof other.foo3, 'undefined')
is(typeof log.foo3, 'function')
is(typeof other.foo3, 'undefined')
end()
})

test('custom level on one instance does not affect other instances', function (t) {
t.plan(2)

test('custom level on one instance does not affect other instances', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino()
log.addLevel('foo4', 37)
var other = pino()
log.addLevel('foo5', 38)
t.is(typeof other.foo4, 'undefined')
t.is(typeof other.foo5, 'undefined')
is(typeof other.foo4, 'undefined')
is(typeof other.foo5, 'undefined')
end()
})

test('custom levels encompass higher levels', function (t) {
t.plan(1)

test('custom levels encompass higher levels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino({level: 'foo', levelVal: 35}, sink(function (chunk, enc, cb) {
t.is(chunk.msg, 'bar')
cb()
is(chunk.msg, 'bar')
end()
}))

log.warn('bar')
})

test('after the fact add level does not include lower levels', function (t) {
t.plan(1)

test('after the fact add level does not include lower levels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino(sink(function (chunk, enc, cb) {
t.is(chunk.msg, 'bar')
cb()
is(chunk.msg, 'bar')
end()
}))

log.addLevel('foo', 35)
Expand All @@ -73,12 +64,10 @@ test('after the fact add level does not include lower levels', function (t) {
log.foo('bar')
})

test('after the fact add of a lower level does not include it', function (t) {
t.plan(1)

test('after the fact add of a lower level does not include it', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino(sink(function (chunk, enc, cb) {
t.is(chunk.msg, 'bar')
cb()
is(chunk.msg, 'bar')
end()
}))

log.level = 'info'
Expand All @@ -87,68 +76,64 @@ test('after the fact add of a lower level does not include it', function (t) {
log.foo('nope')
})

test('children can be set to custom level', function (t) {
t.plan(2)

test('children can be set to custom level', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var parent = pino({level: 'foo', levelVal: 35}, sink(function (chunk, enc, cb) {
t.is(chunk.msg, 'bar')
t.is(chunk.child, 'yes')
cb()
is(chunk.msg, 'bar')
is(chunk.child, 'yes')
end()
}))
var child = parent.child({child: 'yes'})
child.foo('bar')
})

test('custom levels exists on children', function (t) {
t.plan(2)

test('custom levels exists on children', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var parent = pino({}, sink(function (chunk, enc, cb) {
t.is(chunk.msg, 'bar')
t.is(chunk.child, 'yes')
cb()
is(chunk.msg, 'bar')
is(chunk.child, 'yes')
end()
}))
parent.addLevel('foo', 35)
var child = parent.child({child: 'yes'})
child.foo('bar')
})

test('rejects already known labels', function (t) {
t.plan(1)
test('rejects already known labels', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino({level: 'info', levelVal: 900})
t.is(log.levelVal, 30)
is(log.levelVal, 30)
end()
})

test('reject already known values', function (t) {
t.plan(1)
test('reject already known values', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
try {
pino({level: 'foo', levelVal: 30})
} catch (e) {
t.is(e.message.indexOf('level value') > -1, true)
is(e.message.indexOf('level value') > -1, true)
} finally {
end()
}
})

test('reject values of Infinity', function (t) {
t.plan(1)
t.throws(function () {
test('reject values of Infinity', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
throws(function () {
pino({level: 'foo', levelVal: Infinity})
}, /.*level value is already used.*/)
end()
})

test('level numbers are logged correctly after level change', function (t) {
t.plan(1)
test('level numbers are logged correctly after level change', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var log = pino({level: 'foo', levelVal: 25}, sink(function (chunk, enc, cb) {
t.is(chunk.level, 25)
is(chunk.level, 25)
end()
}))
log.level = 'debug'
log.foo('bar')
})

test('levels state is not shared between instances', function (t) {
t.plan(2)

test('levels state is not shared between instances', ({plan, end, ok, same, is, isNot, throws, doesNotThrow, fail, pass, error, notError}) => {
var instance1 = pino({level: 'foo', levelVal: 35})
t.is(typeof instance1.foo, 'function')
is(typeof instance1.foo, 'function')

var instance2 = pino()
t.is(instance2.hasOwnProperty('foo'), false)
is(instance2.hasOwnProperty('foo'), false)
end()
})
Loading

0 comments on commit 3c21d18

Please sign in to comment.