-
Notifications
You must be signed in to change notification settings - Fork 31.3k
assert: validate the block return type #19886
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
Conversation
.eslintrc.js
Outdated
{ | ||
selector: `CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])`, | ||
message: 'use a regular expression for second argument of assert.throws()', | ||
message: 'Use a object as second argument of assert.throws()', |
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.
an object
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.
This is a change from #19885 that I plan on removing in here as soon as that lands. I already fixed that in there though.
This makes sure the returned value when calling `block` is actually of type promise in case `assert.rejects` or `assert.doesNotReject` is called.
8fdc532
to
386f664
Compare
Rebased. This is unblocked and should now be looked at. |
@targos PTAL |
doc/api/assert.md
Outdated
rejected Promise with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases | ||
without checking the error handler. | ||
|
||
If `block` is a function and it does not return a promise, an |
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.
Isn't this redundant with the previous paragraph?
doc/api/errors.md
Outdated
<a id="ERR_INVALID_RETURN_VALUE"></a> | ||
### ERR_INVALID_RETURN_VALUE | ||
|
||
Thrown in case a function option does not return a expected value on execution. |
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.
Nit: an expected value
doc/api/assert.md
Outdated
`assert.doesNotReject()` will return a rejected Promise with that error. If the | ||
function does not return a promise, `assert.doesNotReject()` will return a | ||
rejected Promise with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases | ||
without checking the error handler. |
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.
This sentence fragment seems a bit unexpected. Should we add a verb to it?
doc/api/assert.md
Outdated
`assert.rejects()` will return a rejected Promise with that error without | ||
`assert.rejects()` will return a rejected Promise with that error. If the | ||
function does not return a promise, `assert.rejects()` will return a rejected | ||
Promise with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases without |
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.
Ditto.
Comments addressed. |
@vsemozhetbyt @targos PTAL. This should be ready to land otherwise. |
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.
Docs LGTM)
This makes sure the returned value when calling `block` is actually of type promise in case `assert.rejects` or `assert.doesNotReject` is called. PR-URL: nodejs#19886 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Landed in 7007eee |
This makes sure the returned value when calling `block` is actually of type promise in case `assert.rejects` or `assert.doesNotReject` is called. PR-URL: #19886 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
This makes sure the returned value when calling
block
is actuallyof type promise in case
assert.rejects
orassert.doesNotReject
is called.
This currently relies on #19885 and I am going to rebase as soon as that lands / changes. Marking as blocked in the meanwhile.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes