update
This commit is contained in:
parent
d9becc67b6
commit
9308795b8b
964 changed files with 104265 additions and 16 deletions
55
node_modules/pino/test/helper.js
generated
vendored
Normal file
55
node_modules/pino/test/helper.js
generated
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
'use strict'
|
||||
|
||||
const os = require('os')
|
||||
const writer = require('flush-write-stream')
|
||||
const split = require('split2')
|
||||
const pid = process.pid
|
||||
const hostname = os.hostname()
|
||||
const v = 1
|
||||
|
||||
const isWin = process.platform === 'win32'
|
||||
|
||||
function getPathToNull () {
|
||||
return isWin ? '\\\\.\\NUL' : '/dev/null'
|
||||
}
|
||||
|
||||
function once (emitter, name) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (name !== 'error') emitter.once('error', reject)
|
||||
emitter.once(name, (...args) => {
|
||||
emitter.removeListener('error', reject)
|
||||
resolve(...args)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function sink (func) {
|
||||
const result = split((data) => {
|
||||
try {
|
||||
return JSON.parse(data)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
console.log(data)
|
||||
}
|
||||
})
|
||||
if (func) result.pipe(writer.obj(func))
|
||||
return result
|
||||
}
|
||||
|
||||
function check (is, chunk, level, msg) {
|
||||
is(new Date(chunk.time) <= new Date(), true, 'time is greater than Date.now()')
|
||||
delete chunk.time
|
||||
is(chunk.pid, pid)
|
||||
is(chunk.hostname, hostname)
|
||||
is(chunk.level, level)
|
||||
is(chunk.msg, msg)
|
||||
is(chunk.v, v)
|
||||
}
|
||||
|
||||
function sleep (ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { getPathToNull, sink, check, once, sleep }
|
||||
Loading…
Add table
Add a link
Reference in a new issue