From d8b5dcea6c25225a3a795898c3678f0f63af0068 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 6 Feb 2019 09:26:55 -0800 Subject: [PATCH] add tests --- lib/common/api/deprecate.js | 6 ++---- spec/api-deprecations-spec.js | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/common/api/deprecate.js b/lib/common/api/deprecate.js index ed8782e6e5bc4..a7869e62e65df 100644 --- a/lib/common/api/deprecate.js +++ b/lib/common/api/deprecate.js @@ -36,12 +36,10 @@ const deprecate = { }, function: (fn, newName) => { - // if newName is left blank, a removal warning will be displayed const warn = warnOnce(fn.name, newName) - return function () { - if (!process.noDeprecation) warn() - return fn.apply(this, arguments) + warn() + fn.apply(this, arguments) } }, diff --git a/spec/api-deprecations-spec.js b/spec/api-deprecations-spec.js index 7236107f262dc..4c70a8db63fbc 100644 --- a/spec/api-deprecations-spec.js +++ b/spec/api-deprecations-spec.js @@ -82,9 +82,35 @@ describe('deprecations', () => { expect(msg).to.include(prop) }) + it('warns exactly once when a function is deprecated with no replacement', () => { + let msg + deprecations.setHandler(m => { msg = m }) + + function oldFn () { return 'hello' } + deprecate.function(oldFn) + oldFn() + + expect(msg).to.be.a('string') + expect(msg).to.include(oldFn) + }) + + it('warns exactly once when a function is deprecated with a replacement', () => { + let msg + deprecations.setHandler(m => { msg = m }) + + function oldFn () { return 'hello' } + function newFn () { return 'goodbye' } + deprecate.function(oldFn) + oldFn() + + expect(msg).to.be.a('string') + expect(msg).to.include(oldFn) + expect(msg).to.include(newFn) + }) + it('warns only once per item', () => { const messages = [] - deprecations.setHandler(message => { messages.push(message) }) + deprecations.setHandler(message => messages.push(message)) const key = 'foo' const val = 'bar' @@ -125,7 +151,7 @@ describe('deprecations', () => { const enableCallbackWarnings = () => { warnings = [] - deprecations.setHandler(warning => { warnings.push(warning) }) + deprecations.setHandler(warning => warnings.push(warning)) process.enablePromiseAPIs = true } @@ -133,7 +159,7 @@ describe('deprecations', () => { deprecations.setHandler(null) process.throwDeprecation = true - promiseFunc = param => new Promise((resolve, reject) => { resolve(param) }) + promiseFunc = param => new Promise((resolve, reject) => resolve(param)) }) it('acts as a pass-through for promise-based invocations', async () => {