-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #66: Now children can get serializers injected. Improved test a…
…round serializers rules
- Loading branch information
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict' | ||
var test = require('tap').test | ||
var pino = require('../') | ||
var sink = require('./helper').sink | ||
|
||
var parentSerializers = { | ||
test: function () { return 'parent' } | ||
} | ||
|
||
var childSerializers = { | ||
test: function () { return 'child' } | ||
} | ||
|
||
test('child does not override parent serializers', function (t) { | ||
t.plan(2) | ||
|
||
var parent = pino({ serializers: parentSerializers }) | ||
var child = parent.child({ serializers: childSerializers }) | ||
|
||
t.deepEqual(parent.serializers, parentSerializers) | ||
t.deepEqual(child.serializers, childSerializers) | ||
}) | ||
|
||
test('children inherit parent serializers', function (t) { | ||
t.plan(1) | ||
|
||
var parent = pino({ serializers: parentSerializers }) | ||
var child = parent.child({a: 'property'}) | ||
|
||
t.deepEqual(child.serializers, parentSerializers) | ||
}) | ||
|
||
test('children serializers get called', function (t) { | ||
t.plan(1) | ||
|
||
var parent = pino({ | ||
test: 'this' | ||
}, sink(function (chunk, enc, cb) { | ||
cb() | ||
})) | ||
|
||
var child = parent.child({ 'a': 'property', serializers: childSerializers }) | ||
|
||
child.serializers.test = function () { | ||
t.ok('serializer called') | ||
return 'called' | ||
} | ||
|
||
child.fatal({test: 'test'}) | ||
}) | ||
|
||
test('children serializers get called when inherited from parent', function (t) { | ||
t.plan(1) | ||
|
||
var parent = pino({ | ||
test: 'this', | ||
serializers: childSerializers | ||
}, sink(function (chunk, enc, cb) { | ||
cb() | ||
})) | ||
|
||
var child = parent.child({ 'a': 'property' }) | ||
|
||
child.serializers.test = function () { | ||
t.ok('serializer called') | ||
return 'called' | ||
} | ||
|
||
child.fatal({test: 'test'}) | ||
}) |