test('child should have bindings set by parent', async ({ same }) => { const instance = pino({ name: 'basicTest', level: 'info' }) instance.setBindings({ foo: 'bar' }) const child = instance.child({}) same(child.bindings(), { name: 'basicTest', foo: 'bar' }) })
test('exposed levels', async ({ same }) => { same(Object.keys(pino.levels.values), [ 'trace', 'debug', 'info', 'warn', 'error', 'fatal' ]) })
test('set the base to null', async ({ is, same }) => { const stream = sink() const instance = pino({ base: null }, stream) instance.fatal('this is fatal') const result = await once(stream, 'data') is(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()') delete result.time same(result, { level: 60, msg: 'this is fatal' }) })
test('bindings are exposed on every instance', async ({ same }) => { const instance = pino() same(instance.bindings(), {}) })
test('normalize number to string with an object', async ({ same }) => { const stream = sink() const instance = pino(stream) instance.info({ answer: 42 }, 1) const result = await once(stream, 'data') delete result.time same(result, { pid, hostname, level: 30, msg: '1', answer: 42 }) })
test('bindings contain the name and the child bindings', async ({ same }) => { const instance = pino({ name: 'basicTest', level: 'info' }).child({ foo: 'bar' }).child({ a: 2 }) same(instance.bindings(), { name: 'basicTest', foo: 'bar', a: 2 }) })
test('set bindings on instance', async ({ same }) => { const instance = pino({ name: 'basicTest', level: 'info' }) instance.setBindings({ foo: 'bar' }) same(instance.bindings(), { name: 'basicTest', foo: 'bar' }) })
test('exposed labels', async ({ same }) => { same(Object.keys(pino.levels.labels), [ '10', '20', '30', '40', '50', '60' ]) })
test('child should not share bindings of parent set after child creation', async ({ same }) => { const instance = pino({ name: 'basicTest', level: 'info' }) const child = instance.child({}) instance.setBindings({ foo: 'bar' }) same(instance.bindings(), { name: 'basicTest', foo: 'bar' }) same(child.bindings(), { name: 'basicTest' }) })
test('set bindings on child instance', async ({ same }) => { const child = pino({ name: 'basicTest', level: 'info' }).child({}) child.setBindings({ foo: 'bar' }) same(child.bindings(), { name: 'basicTest', foo: 'bar' }) })
test('set undefined properties', async ({ is, same }) => { const stream = sink() const instance = pino(stream) instance.info({ hello: 'world', property: undefined }) const result = await once(stream, 'data') is(new Date(result.time) <= new Date(), true, 'time is greater than Date.now()') delete result.time same(result, { pid, hostname, level: 30, hello: 'world' }) })
test('newly set bindings overwrite old bindings', async ({ same }) => { const instance = pino({ name: 'basicTest', level: 'info', base: { foo: 'bar' } }) instance.setBindings({ foo: 'baz' }) same(instance.bindings(), { name: 'basicTest', foo: 'baz' }) })
test('normalize number to string', async ({ same }) => { const stream = sink() const instance = pino(stream) instance.info(1) const result = await once(stream, 'data') delete result.time same(result, { pid, hostname, level: 30, msg: '1' }) })
// https://github.com/pinojs/pino/issues/139 test('object and format string', async ({ same }) => { const stream = sink() const instance = pino(stream) instance.info({}, 'foo %s', 'bar') const result = await once(stream, 'data') delete result.time same(result, { pid, hostname, level: 30, msg: 'foo bar' }) })
test('object and format string property', async ({ same }) => { const stream = sink() const instance = pino(stream) instance.info({ answer: 42 }, 'foo %s', 'bar') const result = await once(stream, 'data') delete result.time same(result, { pid, hostname, level: 30, msg: 'foo bar', answer: 42 }) })