-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
detect improper use of t.throws #742
Changes from 1 commit
1f431c4
dbed3d4
53b38a8
56c59ce
3f6a01f
4a0bbd0
b12b4d7
df79d3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,24 @@ Test.prototype._assert = function (promise) { | |
}; | ||
|
||
Test.prototype._setAssertError = function (err) { | ||
var data = err._avaThrowsHelperData; | ||
if (data) { | ||
console.error( | ||
[ | ||
'Improper usage of t.throws detected at %s (%d:%d).', | ||
'You should wrap the following expression in a function:', | ||
' %s', | ||
'Like this:', | ||
' function() {\n %s\n }', | ||
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. Promote arrow functions? 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. I considered that. But if the user is green enough that that they don't fully understand how 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. Yea fair enough. |
||
'See https://github.com/sindresorhus/ava#throwsfunctionpromise-error-message for more details.' | ||
].join('\n\n'), | ||
data.filename, | ||
data.line, | ||
data.column, | ||
data.source, | ||
data.source | ||
); | ||
} | ||
if (this.assertError !== undefined) { | ||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ var uniqueTempDir = require('unique-temp-dir'); | |
var sinon = require('sinon'); | ||
var babel = require('babel-core'); | ||
var transformRuntime = require('babel-plugin-transform-runtime'); | ||
var throwsHelper = require('babel-plugin-ava-throws-helper'); | ||
var fromMapFileSource = require('convert-source-map').fromMapFileSource; | ||
|
||
var CachingPrecompiler = require('../lib/caching-precompiler'); | ||
|
@@ -145,7 +146,7 @@ test('uses babelConfig for babel options when babelConfig is an object', functio | |
t.true('inputSourceMap' in options); | ||
t.false(options.babelrc); | ||
t.same(options.presets, ['stage-2', 'es2015']); | ||
t.same(options.plugins, [customPlugin, powerAssert, rewrite, transformRuntime]); | ||
t.same(options.plugins, [customPlugin, powerAssert, throwsHelper, rewrite, transformRuntime]); | ||
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. Without checking the 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. Shouldn't be. The 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. Sure, but 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. Oh - Understood. Still not a problem though. t.true(_rec._expr(_rec._capt(_rec._capt(a, 'arguments/0/left') === 'bar', 'arguments/0'), {
content: 't.true(a === \'bar\')',
filepath: 'test/fixture/power-assert.js',
line: 6
})); Also, we don't enhance 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.
Right. |
||
t.end(); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import test from '../../'; | ||
|
||
test(t => { | ||
t.throws(throwSync()); | ||
}); | ||
|
||
function throwSync() { | ||
throw new Error('should be detected'); | ||
} |
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.
Probably need to guard against
err
beingnull
orundefined
here?