Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tap to v15 #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .taprc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
esm: false
ts: false
jsx: false
coverage: true
jsumners marked this conversation as resolved.
Show resolved Hide resolved
check-coverage: false
timeout: 480
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"split2": "^4.0.0",
"standard": "^16.0.0",
"steed": "^1.1.3",
"tap": "^14.0.0",
"tap": "^15.1.5",
"through2": "^4.0.0"
}
}
119 changes: 59 additions & 60 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const commonModules = [
'./'
]

tap.afterEach((done) => {
tap.afterEach(() => {
let err = null
for (const modules of debugModules) {
try {
Expand All @@ -46,12 +46,11 @@ tap.afterEach((done) => {
throw err
}
process.env.DEBUG = ''
done()
})

test('throws if called more than once', (t) => {
var pinoDebug = require('../')
t.throw(() => {
t.throws(() => {
pinoDebug()
pinoDebug()
})
Expand All @@ -61,16 +60,16 @@ test('throws if called more than once', (t) => {
test('throws if debug is called after requiring but before calling pinoDebug', (t) => {
require('../')
var debug = require('debug')
t.throw(() => debug('ns'))
t.throws(() => debug('ns'))
t.end()
})

test('captures any calls to `debug` and passes them through pino logger', (t) => {
var pinoDebug = require('../')
var stream = through((line, _, cb) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns')
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns')
t.end()
})
pinoDebug(require('pino')({level: 'debug'}, stream))
Expand All @@ -83,9 +82,9 @@ test('defaults to calling pinoInstance.debug', (t) => {
var pinoDebug = require('../')
var stream = through((line, _, cb) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns')
t.is(obj.level, 20)
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns')
t.equal(obj.level, 20)
t.end()
})
pinoDebug(require('pino')({level: 'debug'}, stream))
Expand All @@ -105,19 +104,19 @@ test('when passed no args, creates a standard pino logger with log level set to
`
var line = execSync(`${process.argv[0]} -e "${program}"`).toString()
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns')
t.is(obj.level, 20)
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns')
t.equal(obj.level, 20)
t.end()
})

test('passes debug args to pino log method according to opts.map', (t) => {
var pinoDebug = require('../')
var stream = through((line, _, cb) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns')
t.is(obj.level, 30)
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns')
t.equal(obj.level, 30)
t.end()
})
pinoDebug(require('pino')(stream), {map: {ns: 'info'}})
Expand All @@ -129,15 +128,15 @@ test('passes debug args to pino log method according to opts.map when auto is of
var pinoDebug = require('../')
var ns = (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns')
t.is(obj.level, 30)
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns')
t.equal(obj.level, 30)
}
var ns2 = (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test2')
t.is(obj.ns, 'ns2')
t.is(obj.level, 40)
t.equal(obj.msg, 'test2')
t.equal(obj.ns, 'ns2')
t.equal(obj.level, 40)
}
var stream = through((line, _, cb) => {
if (!ns.called) {
Expand All @@ -164,9 +163,9 @@ test('does not pass debug args to pino log method according to opts.map when aut

var stream = through((line, _, cb) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test2')
t.is(obj.ns, 'ns2')
t.is(obj.level, 40)
t.equal(obj.msg, 'test2')
t.equal(obj.ns, 'ns2')
t.equal(obj.level, 40)
t.end()
cb()
})
Expand All @@ -185,9 +184,9 @@ test('when preloaded with -r, automatically logs all debug calls with log level
`
var line = execSync(`${process.argv[0]} -r ${__dirname}/../ -e "${program}"`, {env: {DEBUG: '*'}}).toString()
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns')
t.is(obj.level, 20)
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns')
t.equal(obj.level, 20)
t.end()
})

Expand All @@ -196,9 +195,9 @@ test('opts.skip filters out any matching namespaces', (t) => {

var stream = through((line, _, cb) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns')
t.is(obj.level, 30)
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns')
t.equal(obj.level, 30)
t.end()
cb()
})
Expand All @@ -217,44 +216,44 @@ test('when there is a match conflict, log level is set to most precise match', (

var queue = [(line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns')
t.is(obj.level, 30)
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns')
t.equal(obj.level, 30)
}, (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test2')
t.is(obj.ns, 'ns2')
t.is(obj.level, 40)
t.equal(obj.msg, 'test2')
t.equal(obj.ns, 'ns2')
t.equal(obj.level, 40)
}, (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test3')
t.is(obj.ns, 'meow')
t.is(obj.level, 50)
t.equal(obj.msg, 'test3')
t.equal(obj.ns, 'meow')
t.equal(obj.level, 50)
}, (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test4')
t.is(obj.ns, 'izikilla')
t.is(obj.level, 60)
t.equal(obj.msg, 'test4')
t.equal(obj.ns, 'izikilla')
t.equal(obj.level, 60)
}, (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test5')
t.is(obj.ns, 'testtracetest')
t.is(obj.level, 10)
t.equal(obj.msg, 'test5')
t.equal(obj.ns, 'testtracetest')
t.equal(obj.level, 10)
}, (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test6')
t.is(obj.ns, 'debugtra')
t.is(obj.level, 20)
t.equal(obj.msg, 'test6')
t.equal(obj.ns, 'debugtra')
t.equal(obj.level, 20)
}, (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test7')
t.is(obj.ns, 'ns3')
t.is(obj.level, 20)
t.equal(obj.msg, 'test7')
t.equal(obj.ns, 'ns3')
t.equal(obj.level, 20)
}, (line) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test8')
t.is(obj.ns, 'testbla')
t.is(obj.level, 30)
t.equal(obj.msg, 'test8')
t.equal(obj.ns, 'testbla')
t.equal(obj.level, 30)
}]

var stream = through((line, _, cb) => {
Expand Down Expand Up @@ -295,7 +294,7 @@ test('keeps line numbers consistent', (t) => {
require('../')
var lineNums = require('./fixtures/line-numbers')
var line = lineNums()
t.is(line, 4)
t.equal(line, 4)

t.end()
})
Expand All @@ -310,8 +309,8 @@ test('preserves DEBUG env independently from debug module', (t) => {
var pinoDebug = require('../')
var stream = through((line, _, cb) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, 'ns1')
t.equal(obj.msg, 'test')
t.equal(obj.ns, 'ns1')
t.end()
})
pinoDebug(require('pino')({level: 'debug'}, stream))
Expand All @@ -326,8 +325,8 @@ test('supports extend method', (t) => {
var count = 0
var stream = through((line, _, cb) => {
var obj = JSON.parse(line)
t.is(obj.msg, 'test')
t.is(obj.ns, ns[count++])
t.equal(obj.msg, 'test')
t.equal(obj.ns, ns[count++])
cb()
}, () => t.end())
pinoDebug(require('pino')({level: 'debug'}, stream))
Expand All @@ -339,6 +338,6 @@ test('supports extend method', (t) => {
})

test('does not invalidate strict mode', (t) => {
t.is(require('./fixtures/strict-mode'), true)
t.equal(require('./fixtures/strict-mode'), true)
t.end()
})