Skip to content

Commit

Permalink
Add test coverage ignorePaths
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Williams committed Nov 13, 2017
1 parent 5005ea4 commit 3288083
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function register (server, options) {
server.ext('onRequest', (request, h) => {
if (options.ignorePaths && ignoreTable[request.url.path]) {
request.logger = nullLogger
return h.continue()
return h.continue
}
request.logger = logger.child({ req: request })
return h.continue
Expand Down
38 changes: 37 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ experiment('uses a prior pino instance', () => {
}

await server.register(plugin)
server.logger().info({foo: 'bar'}, 'hello world')
server.logger().info({ foo: 'bar' }, 'hello world')
await finish
})
})
Expand Down Expand Up @@ -789,3 +789,39 @@ experiment('logging with request payload', () => {
await done
})
})

experiment('ignore request logs for paths in ignorePaths', () => {
test('when path matches entry in ignorePaths, nothing should be logged', async () => {
const server = getServer()
let resolver
const done = new Promise((resolve, reject) => {
resolver = resolve
})
const stream = sink((data) => {
expect(data.req.url).to.not.equal('/ignored')
resolver()
})
const logger = require('pino')(stream)
const plugin = {
plugin: Pino,
options: {
instance: logger,
ignorePaths: ['/ignored']
}
}

await server.register(plugin)

await server.inject({
method: 'PUT',
url: '/ignored'
})

await server.inject({
method: 'PUT',
url: '/'

})
await done
})
})

0 comments on commit 3288083

Please sign in to comment.