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

id defaults to undefined #7

Merged
merged 1 commit into from
Mar 28, 2018
Merged
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 Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The default `request` serializer. Returns and object:

```js
{
id: 'string', // Default is an empty string, unless there is an `id` property
id: 'string', // Defaults to `undefined`, unless there is an `id` property
// already attached to the `request` object or to the `request.info`
// object. Attach a synchronous function
// to the `request.id` that returns an identifier to have
Expand Down
2 changes: 1 addition & 1 deletion lib/req.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function reqSerializer (req) {
var connection = req.connection
const _req = Object.create(pinoReqProto)
// req.info is for hapi compat.
_req.id = (typeof req.id === 'function' ? req.id() : (req.id || (req.info && req.info.id))) || ''
_req.id = (typeof req.id === 'function' ? req.id() : (req.id || (req.info ? req.info.id : undefined)))
_req.method = req.method
// req.url.path is for hapi compat.
_req.url = req.url ? (req.url.path || req.url) : undefined
Expand Down
18 changes: 18 additions & 0 deletions test/req.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ test('req.raw will be obtained in from input request raw property if input reque
}
})

test('req.id defaults to undefined', function (t) {
t.plan(1)

var server = http.createServer(handler)
server.unref()
server.listen(0, () => {
http.get(server.address(), () => {})
})

t.tearDown(() => server.close())

function handler (req, res) {
var serialized = serializers.reqSerializer(req)
t.is(serialized.id, undefined)
res.end()
}
})

test('req.id has a non-function value', function (t) {
t.plan(1)

Expand Down