Skip to content

Commit

Permalink
Merge branch 'jedrus2000-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
felixheck committed Oct 22, 2020
2 parents 39b8d0e + fa873e1 commit a049e66
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const errorStackParser = require('error-stack-parser')
const util = require('util')

/**
* @function
Expand Down Expand Up @@ -56,7 +57,7 @@ function noop (data) {
* @param {Array} data The data to be logged
*/
function wrapper (server, level, ...data) {
server.log(level, data.length === 1 ? data[0] : data)
server.log(level, util.format(data))
}

/**
Expand Down
19 changes: 17 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ test.serial.cb('get log message by overriden `console.warn` – single', (t) =>
const logs = ['foobar']

helpers.spawn('console', options, logs, (log) => {
t.is(log.message, 'foobar')
t.is(log.message, '[ \'foobar\' ]')
t.end()
})
})
Expand All @@ -486,7 +486,22 @@ test.serial.cb('get log message by overriden `console.warn` – multiple', (t)
const logs = ['foo', 'bar']

helpers.spawn('console', options, logs, (log) => {
t.deepEqual(log.message, ['foo', 'bar'])
t.deepEqual(log.message, '[ \'foo\', \'bar\' ]')
t.end()
})
})

test.serial.cb('get log message by overriden `console.warn` – null', (t) => {
const options = {
indent: 0,
override: true,
hapiPino: { logEvents: false }
}

const logs = [null]

helpers.spawn('console', options, logs, (log) => {
t.is(log.message, '[ null ]')
t.end()
})
})
Expand Down
4 changes: 4 additions & 0 deletions test/tokens.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,15 @@ test('return requested req/res attributes', (t) => {
}
}

const mockDataWithNullReq = Object.assign({}, mockData)
mockDataWithNullReq.req = null

t.is(tokens.requestId(mockData), mockData.req.id)
t.is(tokens.method(mockData, mockColors), mockData.req.method.toUpperCase())
t.is(tokens.status(mockData, mockColors), mockData.res.statusCode)
t.is(tokens.payload(mockData), JSON.stringify({}))
t.is(tokens.remoteAddress(mockData), mockData.req.remoteAddress)
t.is(tokens.remoteAddress(mockDataWithNullReq), undefined)
t.is(tokens.remotePort(mockData), mockData.req.remotePort)
t.is(tokens.url(mockData), mockData.req.url.href)
t.is(tokens.req(mockData, mockColors, 'x-header'), mockData.req.headers['x-header'])
Expand Down

0 comments on commit a049e66

Please sign in to comment.