GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||
GeezerVison is showing github.com — assert: ensure .rejects() disallows sync throws by not-an-aardvark · Pull Request #19650 · nodejs/node Conversation
Contributor
Checklist
This PR has two commits; the first commit fixes an issue with the First commit: Second commit: Note that the second commit would be semver-major, but it modifies an API (introduced in #18023) that has not been backported to a release branch yet. As a result, the second commit could be backported as long as it's applied at the same time as #18023.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
BridgeAR
approved these changes
Member
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. LGTM
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
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. Suggestion: use
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
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. Nit: this test should now be redundant if I am not mistaken.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
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'm assuming you mean that this test is redundant with the other test here. However, this test is a bit different from the other one because it throws asynchronously, and so the promise returned by
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: use common.crashOnUnhandledRejection() at the top of the file instead of adding then(common.mustCall()) everywhere.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@BridgeAR about It is necessary to make sure the promise eventually fulfills (does not stay forever in a pending state). I think the best would be to combine common.crashOnUnhandledRejection(); (async () => { { // test 1 await assert.rejects(something); } { // test 2 await assert.rejects(somethingElse); } })().then(common.mustCall()); We should maybe add something like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@targos fair point. But should the test not time out in case the promise does not fulfill? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@BridgeAR Here's a case where the // Never fulfills. const prom = new Promise(() => {}); (async () => { await prom; console.log('Never printed'); })(); The process does not stay alive since promise states are not part of the event loop. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
3749412 to
edeb64c
Compare
|
Updated to follow the suggestions in #19650 (comment) and #19650 (comment). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This updates the test in `test/parallel/test-assert-async.js` to add an assertion that the Promises used in the test end up fulfilled. Previously, if an assertion failure occurred, the Promises would have rejected and a warning would have been logged, but the test would still have exit code 0.
This updates `assert.rejects()` to disallow any errors that are thrown synchronously from the given function. Previously, throwing an error would cause the same behavior as returning a rejected Promise. Fixes: nodejs#19646
edeb64c to
75d2d1e
Compare
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@TimothyGu thanks for the heads up! @not-an-aardvark to have feature parity, it might make sense to check in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Just thinking about it now: wouldn't it be better if assert.rejects expected a Promise instead of a function? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@targos I agree. That solves that dilemma. Since we did not yet publish the functionality, we can still change it. [update] Thinking about it again: It might still be better to only handle functions:
I am going to give it another thought when I have some more time later on. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
In favor of changing it: existing assertion libraries that I know (Should.js, Chai as Promised, jest) work directly with promises. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Arguably, this is different from On the other hand, one potential argument for the current |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@BridgeAR @targos What would you recommend doing with this PR? If the behavior of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I am actually considering supporting to accept both: passing in a function that returns a promise or directly passing in a promise. That would ease the user experience. I do not really see a downside accepting both. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm going to land this since we seem to be in agreement that it's an improvement over the current behavior, but I'd be fine with the behavior being changed in a future PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This updates the test in `test/parallel/test-assert-async.js` to add an assertion that the Promises used in the test end up fulfilled. Previously, if an assertion failure occurred, the Promises would have rejected and a warning would have been logged, but the test would still have exit code 0. PR-URL: #19650 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
This updates `assert.rejects()` to disallow any errors that are thrown synchronously from the given function. Previously, throwing an error would cause the same behavior as returning a rejected Promise. Fixes: #19646 PR-URL: #19650 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
This updates the test in `test/parallel/test-assert-async.js` to add an assertion that the Promises used in the test end up fulfilled. Previously, if an assertion failure occurred, the Promises would have rejected and a warning would have been logged, but the test would still have exit code 0. PR-URL: nodejs#19650 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
This updates `assert.rejects()` to disallow any errors that are thrown synchronously from the given function. Previously, throwing an error would cause the same behavior as returning a rejected Promise. Fixes: nodejs#19646 PR-URL: nodejs#19650 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
This updates the test in `test/parallel/test-assert-async.js` to add an assertion that the Promises used in the test end up fulfilled. Previously, if an assertion failure occurred, the Promises would have rejected and a warning would have been logged, but the test would still have exit code 0. PR-URL: nodejs#19650 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
This updates `assert.rejects()` to disallow any errors that are thrown synchronously from the given function. Previously, throwing an error would cause the same behavior as returning a rejected Promise. Fixes: nodejs#19646 PR-URL: nodejs#19650 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
This updates the test in `test/parallel/test-assert-async.js` to add an assertion that the Promises used in the test end up fulfilled. Previously, if an assertion failure occurred, the Promises would have rejected and a warning would have been logged, but the test would still have exit code 0. Backport-PR-URL: #24019 PR-URL: #19650 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
This updates `assert.rejects()` to disallow any errors that are thrown synchronously from the given function. Previously, throwing an error would cause the same behavior as returning a rejected Promise. Fixes: #19646 Backport-PR-URL: #24019 PR-URL: #19650 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
assert.rejects passes if the given function throws synchronously
There was an error while loading. Please reload this page.