Skip to content
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

assert: validate the block return type #19886

Closed
wants to merge 2 commits into from

Conversation

BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Apr 9, 2018

This makes sure the returned value when calling block is actually
of type promise in case assert.rejects or assert.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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@BridgeAR BridgeAR added the blocked PRs that are blocked by other issues or PRs. label Apr 9, 2018
@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. tools Issues and PRs related to the tools directory. labels Apr 9, 2018
.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()',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an object

Copy link
Member Author

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.

@BridgeAR BridgeAR mentioned this pull request Apr 12, 2018
4 tasks
This makes sure the returned value when calling `block` is actually
of type promise in case `assert.rejects` or `assert.doesNotReject`
is called.
@BridgeAR BridgeAR removed the blocked PRs that are blocked by other issues or PRs. label Apr 16, 2018
@BridgeAR
Copy link
Member Author

@BridgeAR
Copy link
Member Author

Rebased. This is unblocked and should now be looked at.

@BridgeAR
Copy link
Member Author

@targos PTAL

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
Copy link
Member

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?

<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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: an expected value

`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.
Copy link
Contributor

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?

`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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@BridgeAR
Copy link
Member Author

Comments addressed.

CI https://ci.nodejs.org/job/node-test-pull-request/14385/

@BridgeAR
Copy link
Member Author

@vsemozhetbyt @targos PTAL. This should be ready to land otherwise.

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 19, 2018
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs LGTM)

BridgeAR added a commit to BridgeAR/node that referenced this pull request Apr 19, 2018
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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
@BridgeAR
Copy link
Member Author

Landed in 7007eee

@BridgeAR BridgeAR closed this Apr 19, 2018
jasnell pushed a commit that referenced this pull request Apr 20, 2018
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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
@BridgeAR BridgeAR deleted the stricter-assert-rejects branch January 20, 2020 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. errors Issues and PRs related to JavaScript errors originated in Node.js core. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants