-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn on unknown options
#465
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,26 +106,30 @@ describe('utils', function() { | |
expect(utils.getDataFromArgs(args)).to.deep.equal({}); | ||
expect(args.length).to.equal(2); | ||
}); | ||
it('ignores a hash with only options', function() { | ||
it('ignores a hash with only options', function(done) { | ||
var args = [{api_key: 'foo'}]; | ||
|
||
handleConsoleWarns(function() { | ||
handleWarnings(function() { | ||
expect(utils.getDataFromArgs(args)).to.deep.equal({}); | ||
expect(args.length).to.equal(1); | ||
|
||
done(); | ||
}, function(message) { | ||
throw new Error('Should not have warned, but did: ' + message); | ||
}); | ||
}); | ||
it('warns if the hash contains both data and options', function() { | ||
it('warns if the hash contains both data and options', function(done) { | ||
var args = [{foo: 'bar', api_key: 'foo', idempotency_key: 'baz'}]; | ||
|
||
handleConsoleWarns(function() { | ||
handleWarnings(function() { | ||
utils.getDataFromArgs(args); | ||
}, function(message) { | ||
expect(message).to.equal( | ||
'Stripe: Options found in arguments (api_key, idempotency_key).' + | ||
' Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.' | ||
); | ||
|
||
done(); | ||
}); | ||
}); | ||
it('finds the data', function() { | ||
|
@@ -212,6 +216,25 @@ describe('utils', function() { | |
}); | ||
expect(args.length).to.equal(0); | ||
}); | ||
it('warns if the hash contains something that does not belong', function(done) { | ||
var args = [{foo: 'bar'}, { | ||
api_key: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii', | ||
idempotency_key: 'foo', | ||
stripe_version: '2010-01-10', | ||
fishsticks: true, | ||
custard: true, | ||
},]; | ||
|
||
handleWarnings(function() { | ||
utils.getOptionsFromArgs(args); | ||
}, function(message) { | ||
expect(message).to.equal( | ||
'Stripe: Invalid options found (fishsticks, custard); ignoring.' | ||
); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('arrayToObject', function() { | ||
|
@@ -262,15 +285,31 @@ describe('utils', function() { | |
}); | ||
|
||
/* eslint-disable no-console */ | ||
function handleConsoleWarns(doWithShimmedConsoleWarn, onWarn) { | ||
// Shim `console.warn` | ||
var _warn = console.warn; | ||
function handleWarnings(doWithShimmedConsoleWarn, onWarn) { | ||
/* eslint-disable no-console */ | ||
if (typeof process.emitWarning !== 'function') { | ||
// Shim `console.warn` | ||
var _warn = console.warn; | ||
console.warn = onWarn; | ||
|
||
console.warn = onWarn; | ||
doWithShimmedConsoleWarn(); | ||
|
||
doWithShimmedConsoleWarn(); | ||
// Un-shim `console.warn`, | ||
console.warn = _warn; | ||
|
||
// Un-shim `console.warn` | ||
console.warn = _warn; | ||
/* eslint-enable no-console */ | ||
} else { | ||
/* eslint-disable no-inner-declarations */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here, can we either re-enable this lint after the inner declaration or use |
||
function onProcessWarn(warning) { | ||
onWarn(warning.name + ': ' + warning.message); | ||
} | ||
|
||
process.on('warning', onProcessWarn); | ||
|
||
doWithShimmedConsoleWarn(); | ||
|
||
process.nextTick(function() { | ||
process.removeListener('warning', onProcessWarn); | ||
}) | ||
} | ||
} | ||
/* eslint-enable no-console */ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another small one, but I think this
eslint-disable
might have been duplicated. Can we just have one of these? (Between the ones on lines 287 and 289.)