From 71edd0d58190bcc5ab19ac41ec227f64340cf1ce Mon Sep 17 00:00:00 2001 From: Jonathan Lomas Date: Wed, 30 May 2018 14:49:26 -0700 Subject: [PATCH] console.warn on unknown options --- lib/utils.js | 3 ++- test/utils.spec.js | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 0d62440a1e..8175a2e8ea 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -207,7 +207,8 @@ var utils = module.exports = { function emitStripeWarning(warning) { if (typeof process.emitWarning !== 'function') { - return console.warn('Stripe: ' + warning); + /* eslint-disable no-console */ + return console.warn('Stripe: ' + warning); } return process.emitWarning(warning, 'Stripe'); diff --git a/test/utils.spec.js b/test/utils.spec.js index 5707dbd24d..0a5e395cb7 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -228,8 +228,6 @@ describe('utils', function() { handleWarnings(function() { utils.getOptionsFromArgs(args); }, function(message) { - console.log('potato'); - expect(message).to.equal( 'Stripe: Invalid options found (fishsticks, custard); ignoring.' ); @@ -288,6 +286,7 @@ describe('utils', function() { /* eslint-disable no-console */ function handleWarnings(doWithShimmedConsoleWarn, onWarn) { + /* eslint-disable no-console */ if (typeof process.emitWarning !== 'function') { // Shim `console.warn` var _warn = console.warn; @@ -295,14 +294,21 @@ function handleWarnings(doWithShimmedConsoleWarn, onWarn) { doWithShimmedConsoleWarn(); - // Un-shim `console.warn` + // Un-shim `console.warn`, console.warn = _warn; } else { - process.on('warning', onWarn); + /* eslint-disable no-inner-declarations */ + function onProcessWarn(warning) { + onWarn(warning.name + ': ' + warning.message); + } + + process.on('warning', onProcessWarn); doWithShimmedConsoleWarn(); - process.off('warning', onWarn); + process.nextTick(function() { + process.removeListener('warning', onProcessWarn); + }) } } /* eslint-enable no-console */