Repository: pinojs/pino
Pull request #377 (2018-03-27 11:16:07)

std serializers api typo + deprecation unit tests
this is a no brainer to fix, 

however: I'm assuming this is a patch release not a major, because even though we're technically changing the API - we should consider the current API broken

I doubt anyone is relying on the typo, we would have had a PR by now... surely


Patch:
diff --git a/package.json b/package.json
index ba6cc8a..ed8f787 100644
--- a/package.json
+++ b/package.json
@@ -20,8 +20,8 @@
   ],
   "scripts": {
     "browser-test": "zuul tape test/browser*test.js --local",
-    "test": "standard | snazzy && tap --no-cov test/*test.js",
-    "ci": "standard | snazzy && tap --cov test/*test.js",
+    "test": "standard | snazzy && NODE_OPTIONS='--no-warnings' tap --no-cov test/*test.js",
+    "ci": "standard | snazzy &&  NODE_OPTIONS='--no-warnings' tap --cov test/*test.js",
     "bench-all": "node benchmarks/runbench all",
     "bench-basic": "node benchmarks/runbench basic",
     "bench-object": "node benchmarks/runbench object",
diff --git a/pino.js b/pino.js
index ec3af49..55f8bfb 100644
--- a/pino.js
+++ b/pino.js
@@ -5,6 +5,7 @@ var EventEmitter = require('events').EventEmitter
 var stringifySafe = require('fast-safe-stringify')
 var serializers = require('pino-std-serializers')
 var fs = require('fs')
+var util = require('util')
 var pump = require('pump')
 var flatstr = require('flatstr')
 var pretty = require('./pretty')
@@ -326,7 +327,7 @@ function pino (opts, stream) {
 
   if (iopts.slowtime) {
     instance.time = time.slowTime
-    process.emitWarning('use `timestamp: pino.stdTimeFunctions.slowTime`', '(pino) `slowtime` is deprecated')
+    util.deprecate(tools.noop, '(pino) `slowtime` is deprecated: use `timestamp: pino.stdTimeFunctions.slowTime`')()
   } else if (iopts.timestamp && Function.prototype.isPrototypeOf(iopts.timestamp)) {
     instance.time = iopts.timestamp
   } else if (iopts.timestamp) {
@@ -383,8 +384,19 @@ module.exports.stdSerializers = {
   res: serializers.res,
   err: serializers.err,
   wrapRequestSerializer: serializers.wrapRequestSerializer,
-  wrapRespnonseSerializer: serializers.wrapResponseSerializer
+  wrapResponseSerializer: serializers.wrapResponseSerializer
 }
+
+Object.defineProperty(module.exports.stdSerializers, 'wrapRespnonseSerializer', {
+  enumerable: true,
+  get: util.deprecate(
+    function () {
+      return serializers.wrapResponseSerializer
+    },
+    '`pino.stdSerializers.wrapRespnonseSerializer` is deprecated: use `pino.stdSerializers.wrapResponseSerializer`'
+  )
+})
+
 module.exports.stdTimeFunctions = Object.assign({}, time)
 module.exports.pretty = pretty
 Object.defineProperty(


Test patch:
diff --git a/test/deprecated.test.js b/test/deprecated.test.js
new file mode 100644
index 0000000..8baa441
--- /dev/null
+++ b/test/deprecated.test.js
@@ -0,0 +1,45 @@
+'use strict'
+
+var test = require('tap').test
+var pino = require('../')
+var sink = require('./helper').sink
+
+test('opts.slowtime', function (t) {
+  if (typeof process.emitWarning === 'function') {
+    process.once('warning', (msg) => {
+      t.is(/`slowtime` is deprecated/.test(msg), true)
+      t.end()
+    })
+  } else {
+    const write = process.stderr.write
+    process.stderr.write = (msg) => {
+      t.is(/`slowtime` is deprecated/.test(msg), true)
+      process.nextTick(t.end)
+      process.stderr.write = write
+    }
+  }
+
+  var instance = pino({slowtime: true},
+    sink(function (chunk, enc, cb) {
+      t.ok(Date.parse(chunk.time) <= new Date(), 'time is greater than Date.now()')
+    }))
+
+  instance.info('hello world')
+})
+
+test('pino.stdSerializers.wrapRespnonseSerializer', function (t) {
+  if (typeof process.emitWarning === 'function') {
+    process.once('warning', (msg) => {
+      t.is(/`pino.stdSerializers.wrapRespnonseSerializer` is deprecated/.test(msg), true)
+      t.end()
+    })
+  } else {
+    const write = process.stderr.write
+    process.stderr.write = (msg) => {
+      t.is(/`pino.stdSerializers.wrapRespnonseSerializer` is deprecated/.test(msg), true)
+      process.nextTick(t.end)
+      process.stderr.write = write
+    }
+  }
+  t.is(pino.stdSerializers.wrapRespnonseSerializer, pino.stdSerializers.wrapResponseSerializer)
+})