Skip to content

Commit

Permalink
console.warn on unknown options
Browse files Browse the repository at this point in the history
  • Loading branch information
jlomas-stripe committed May 30, 2018
1 parent 94b4b6f commit 71edd0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
16 changes: 11 additions & 5 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
Expand Down Expand Up @@ -288,21 +286,29 @@ 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;
console.warn = 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 */

0 comments on commit 71edd0d

Please sign in to comment.