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

test: replaces assert.throws() with common.expectsError() #22689

Closed
wants to merge 1 commit into from

Conversation

saudkhanzada
Copy link

@saudkhanzada saudkhanzada commented Sep 4, 2018

replaces assert.throws() with common.expectsError() to check error code
and error type in parallel/test-buffer-alloc.js

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

replaces assert.throws() with common.expectsError() to check error code
and error type in parallel/test-buffer-alloc.js
@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Sep 4, 2018
@Trott
Copy link
Member

Trott commented Sep 4, 2018

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

There is no need to use common.expectsError() to do this. assert.throws() is also able to do that. Therefore the message is a bit off. I suggest to rephrase to:
test: check for error codes in test-buffer-alloc.js

Otherwise LGTM

@Trott
Copy link
Member

Trott commented Sep 5, 2018

There is no need to use common.expectsError() to do this.

@BridgeAR The reason to use common.expectsError() is so that it can be cherry-picked into the 8.x-staging branch rather than requiring a backport.

Once 10.x is the oldest supported version, we can likely get rid of common.expectsError() in favor of assert.throws(). (We'll need to refactor cases where common.expectsError() returns a function, but it should be do-able.)

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 5, 2018
assert.throws(() => b.write('', 2048), RangeError);
common.expectsError(
() => b.write('', 2048),
{
Copy link
Member

Choose a reason for hiding this comment

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

nit: Since this error object is used multiple times in the test, it can be stored in a const.

@Trott
Copy link
Member

Trott commented Sep 8, 2018

@Trott
Copy link
Member

Trott commented Sep 8, 2018

@Trott
Copy link
Member

Trott commented Sep 8, 2018

@refack
Copy link
Contributor

refack commented Sep 8, 2018

The reason to use common.expectsError() is so that it can be cherry-picked into the 8.x-staging branch rather than requiring a backport.

I remember we used to use common.expectsError for checking NodeErrors that have an error code, while assert.throws was the legacy usage. And we used that distinction to track where we still throw "old" errors.
Was that effort completed?

@BridgeAR
Copy link
Member

BridgeAR commented Sep 8, 2018

@refack assert.throws() became significantly more powerful in the meanwhile. It now behaves very similar to common.expectsError(). But @Trott is correct that these changes were not yet backported to 8 and it's easier to backport everything with the current notation until those features landed in 8 as well.

Trott pushed a commit to Trott/io.js that referenced this pull request Sep 8, 2018
replaces assert.throws() with common.expectsError() to check error code
and error type in parallel/test-buffer-alloc.js

PR-URL: nodejs#22689
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@Trott
Copy link
Member

Trott commented Sep 8, 2018

Landed in 9782ce2.

Thanks for the contribution! 🎉

(If you're interested in other possible contributions to Node.js but don't have a good idea of where to start looking, some ideas are posted at https://www.nodetodo.org/next-steps/.)

@Trott Trott closed this Sep 8, 2018
targos pushed a commit that referenced this pull request Sep 9, 2018
replaces assert.throws() with common.expectsError() to check error code
and error type in parallel/test-buffer-alloc.js

PR-URL: #22689
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants