diff --git a/browser.js b/browser.js index a6384c63d..22ed05a7a 100644 --- a/browser.js +++ b/browser.js @@ -6,6 +6,10 @@ module.exports = pino var _console = global.console || {} var stdSerializers = { + mapHttpRequest: mock, + mapHttpResponse: mock, + wrapRequestSerializer: passthrough, + wrapResponseSerializer: passthrough, req: mock, res: mock, err: asErrValue @@ -157,6 +161,7 @@ pino.levels = { } pino.stdSerializers = stdSerializers +pino.symbols = require('./lib/symbols') function set (opts, logger, level, fallback) { var proto = Object.getPrototypeOf(logger) @@ -296,4 +301,5 @@ function asErrValue (err) { } function mock () { return {} } +function passthrough (a) { return a } function noop () {} diff --git a/test/browser.test.js b/test/browser.test.js index 02184486e..cdbfff94c 100644 --- a/test/browser.test.js +++ b/test/browser.test.js @@ -1,6 +1,8 @@ 'use strict' const test = require('tape') const fresh = require('fresh-require') +const pinoStdSerializers = require('pino-std-serializers') +const pinoSymbols = require('../lib/symbols') const pino = require('../browser') levelTest('fatal') @@ -101,22 +103,36 @@ test('exposes LOG_VERSION', ({ end, is }) => { test('exposes faux stdSerializers', ({ end, ok, same }) => { ok(pino.stdSerializers) - ok(pino.stdSerializers.req) - ok(pino.stdSerializers.res) - ok(pino.stdSerializers.err) + // make sure faux stdSerializers match pino-std-serializers + for (let serializer in pinoStdSerializers) { + ok(pino.stdSerializers[serializer], `pino.stdSerializers.${serializer}`) + } + // confirm faux methods return empty objects same(pino.stdSerializers.req(), {}) + same(pino.stdSerializers.mapHttpRequest(), {}) + same(pino.stdSerializers.mapHttpResponse(), {}) same(pino.stdSerializers.res(), {}) - + // confirm wrapping function is a passthrough + const noChange = { foo: 'bar', fuz: 42 } + same(pino.stdSerializers.wrapRequestSerializer(noChange), noChange) + same(pino.stdSerializers.wrapResponseSerializer(noChange), noChange) end() }) test('exposes err stdSerializer', ({ end, ok }) => { - ok(pino.stdSerializers) - ok(pino.stdSerializers.req) - ok(pino.stdSerializers.res) ok(pino.stdSerializers.err) ok(pino.stdSerializers.err(Error())) + end() +}) +test('exposes real symbols', ({ end, ok, same }) => { + ok(pino.symbols) + // confirm every symbol is present + for (let symbol in pinoSymbols) { + ok(pino.symbols[symbol], `pino.symbols.${symbol}`) + } + // confirm real symbols are used + same(pino.symbols, pinoSymbols) end() })