|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const test = require('tape') |
| 4 | +const pino = require('../browser') |
| 5 | + |
| 6 | +test('bindings returns an empty object on the root logger', ({ end, same }) => { |
| 7 | + const instance = pino({ browser: {} }) |
| 8 | + |
| 9 | + same(instance.bindings(), {}) |
| 10 | + |
| 11 | + end() |
| 12 | +}) |
| 13 | + |
| 14 | +test('bindings contains child bindings', ({ end, same }) => { |
| 15 | + const instance = pino({ browser: {} }) |
| 16 | + const child = instance.child({ foo: 'bar' }) |
| 17 | + |
| 18 | + same(child.bindings(), { foo: 'bar' }) |
| 19 | + |
| 20 | + end() |
| 21 | +}) |
| 22 | + |
| 23 | +test('bindings contains bindings from nested children', ({ end, same }) => { |
| 24 | + const instance = pino({ browser: {} }) |
| 25 | + const child = instance |
| 26 | + .child({ foo: 'bar' }) |
| 27 | + .child({ a: 2 }) |
| 28 | + |
| 29 | + same(child.bindings(), { foo: 'bar', a: 2 }) |
| 30 | + |
| 31 | + end() |
| 32 | +}) |
| 33 | + |
| 34 | +test('child bindings overwrite parent bindings with the same key', ({ end, same }) => { |
| 35 | + const instance = pino({ browser: {} }) |
| 36 | + const child = instance |
| 37 | + .child({ foo: 'bar' }) |
| 38 | + .child({ foo: 'baz' }) |
| 39 | + |
| 40 | + same(child.bindings(), { foo: 'baz' }) |
| 41 | + |
| 42 | + end() |
| 43 | +}) |
| 44 | + |
| 45 | +test('bindings contains bindings added with setBindings', ({ end, same }) => { |
| 46 | + const instance = pino({ browser: {} }) |
| 47 | + |
| 48 | + instance.setBindings({ foo: 'bar' }) |
| 49 | + |
| 50 | + same(instance.bindings(), { foo: 'bar' }) |
| 51 | + |
| 52 | + end() |
| 53 | +}) |
| 54 | + |
| 55 | +test('newly set bindings overwrite old bindings', ({ end, same }) => { |
| 56 | + const instance = pino({ browser: {} }) |
| 57 | + |
| 58 | + instance.setBindings({ foo: 'bar' }) |
| 59 | + instance.setBindings({ foo: 'baz' }) |
| 60 | + |
| 61 | + same(instance.bindings(), { foo: 'baz' }) |
| 62 | + |
| 63 | + end() |
| 64 | +}) |
| 65 | + |
| 66 | +test('setBindings on child merges with child bindings', ({ end, same }) => { |
| 67 | + const instance = pino({ browser: {} }) |
| 68 | + const child = instance.child({ child: true }) |
| 69 | + |
| 70 | + child.setBindings({ later: 'yes' }) |
| 71 | + |
| 72 | + same(child.bindings(), { |
| 73 | + child: true, |
| 74 | + later: 'yes' |
| 75 | + }) |
| 76 | + |
| 77 | + end() |
| 78 | +}) |
| 79 | + |
| 80 | +test('child inherits bindings set on parent before child creation', ({ end, same }) => { |
| 81 | + const instance = pino({ browser: {} }) |
| 82 | + |
| 83 | + instance.setBindings({ foo: 'bar' }) |
| 84 | + |
| 85 | + const child = instance.child({}) |
| 86 | + |
| 87 | + same(child.bindings(), { foo: 'bar' }) |
| 88 | + |
| 89 | + end() |
| 90 | +}) |
| 91 | + |
| 92 | +test('child does not inherit bindings set on parent after child creation', ({ end, same }) => { |
| 93 | + const instance = pino({ browser: {} }) |
| 94 | + const child = instance.child({}) |
| 95 | + |
| 96 | + instance.setBindings({ foo: 'bar' }) |
| 97 | + |
| 98 | + same(instance.bindings(), { foo: 'bar' }) |
| 99 | + same(child.bindings(), {}) |
| 100 | + |
| 101 | + end() |
| 102 | +}) |
| 103 | + |
| 104 | +test('bindings returns a copy of the bindings', ({ end, same }) => { |
| 105 | + const instance = pino({ browser: {} }) |
| 106 | + instance.setBindings({ foo: 'bar' }) |
| 107 | + |
| 108 | + const bindings = instance.bindings() |
| 109 | + bindings.foo = 'baz' |
| 110 | + |
| 111 | + same(instance.bindings(), { foo: 'bar' }) |
| 112 | + |
| 113 | + end() |
| 114 | +}) |
0 commit comments