Skip to content

Commit

Permalink
Merge pull request #650 from pinojs/pino-browser-fixes
Browse files Browse the repository at this point in the history
Pino browser fixes
  • Loading branch information
davidmarkclements authored May 14, 2019
2 parents 248be4e + 8f9ff4f commit 0b62bd8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
18 changes: 16 additions & 2 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var format = require('quick-format-unescaped')

module.exports = pino

var _console = global.console || {}
var _console = polyfillGlobalThis().console || {}
var stdSerializers = {
mapHttpRequest: mock,
mapHttpResponse: mock,
Expand Down Expand Up @@ -162,7 +162,6 @@ pino.levels = {
}

pino.stdSerializers = stdSerializers
pino.symbols = require('./lib/symbols')

function set (opts, logger, level, fallback) {
var proto = Object.getPrototypeOf(logger)
Expand Down Expand Up @@ -304,3 +303,18 @@ function asErrValue (err) {
function mock () { return {} }
function passthrough (a) { return a }
function noop () {}

/* eslint-disable */
/* istanbul ignore next */
function polyfillGlobalThis () {
if (typeof globalThis !== 'undefined') return globalThis
Object.defineProperty(Object.prototype, 'globalThis', {
get: function () {
delete Object.prototype.globalThis
return (this.globalThis = this)
},
configurable: true
})
return globalThis
}
/* eslint-enable */
12 changes: 0 additions & 12 deletions test/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const test = require('tape')
const fresh = require('import-fresh')
const pinoStdSerializers = require('pino-std-serializers')
const pinoSymbols = require('../lib/symbols')
const pino = require('../browser')

levelTest('fatal')
Expand Down Expand Up @@ -125,17 +124,6 @@ test('exposes err stdSerializer', ({ end, ok }) => {
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()
})

consoleMethodTest('error')
consoleMethodTest('fatal', 'error')
consoleMethodTest('warn')
Expand Down

0 comments on commit 0b62bd8

Please sign in to comment.