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: refactor common.expectsError #31092

Conversation

BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Dec 25, 2019

This completely refactors the expectsError behavior: so far it's
almost identical to assert.throws(fn, object) in case it was used
with a function as first argument. It had a magical property check
that allowed to verify a functions type in case the type property
was set. This pattern is now completely removed and assert.throws()
should be used instead.

The main intent for common.expectsError() is to verify error cases
for callback based APIs. This is now more flexible by accepting all
validation possibilities that assert.throws() accepts. No
magical properties exist anymore. This reduces surprising behavior
for developers who are not used to the Node.js core code base.

The custom prefer-common-expectserror eslint rule comes obsolete with
this change and common us used significantly less frequent.

Refs: #30186 (comment)

Most changes are trivial and it should be possible to skim through
most of them.
Files that have been changed more "significantly":

  • test/parallel/test-crypto.js
  • test/common/index.js
  • test/common/README.md
  • test/parallel/test-eslint-prefer-common-expectserror.js (removed)
  • test/parallel/test-http-invalid-path-chars.js
  • test/parallel/test-net-better-error-messages-port-hostname.js
  • test/parallel/test-net-connect-immediate-finish.js
  • test/parallel/test-stream-writable-change-default-encoding.js
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

This completely refactors the `expectsError` behavior: so far it's
almost identical to `assert.throws(fn, object)` in case it was used
with a function as first argument. It had a magical property check
that allowed to verify a functions `type` in case `type` was passed
used in the validation object. This pattern is now completely removed
and `assert.throws()` should be used instead.

The main intent for `common.expectsError()` is to verify error cases
for callback based APIs. This is now more flexible by accepting all
validation possibilites that `assert.throws()` accepts as well. No
magical properties exist anymore. This reduces surprising behavior
for developers who are not used to the Node.js core code base.

This has the side effect that `common` is used significantly less
frequent.
@BridgeAR BridgeAR requested a review from Trott December 25, 2019 19:22
@nodejs-github-bot nodejs-github-bot added addons Issues and PRs related to native addons. async_hooks Issues and PRs related to the async hooks subsystem. test Issues and PRs related to the tests. labels Dec 25, 2019
@BridgeAR BridgeAR removed addons Issues and PRs related to native addons. async_hooks Issues and PRs related to the async hooks subsystem. labels Dec 25, 2019
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 27, 2019
BridgeAR added a commit that referenced this pull request Dec 31, 2019
This completely refactors the `expectsError` behavior: so far it's
almost identical to `assert.throws(fn, object)` in case it was used
with a function as first argument. It had a magical property check
that allowed to verify a functions `type` in case `type` was passed
used in the validation object. This pattern is now completely removed
and `assert.throws()` should be used instead.

The main intent for `common.expectsError()` is to verify error cases
for callback based APIs. This is now more flexible by accepting all
validation possibilites that `assert.throws()` accepts as well. No
magical properties exist anymore. This reduces surprising behavior
for developers who are not used to the Node.js core code base.

This has the side effect that `common` is used significantly less
frequent.

PR-URL: #31092
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
@BridgeAR
Copy link
Member Author

Landed in e038d6a 🎉

@BridgeAR BridgeAR closed this Dec 31, 2019
cjihrig added a commit to cjihrig/node that referenced this pull request Dec 31, 2019
This custom ESLint rule is unused since
nodejs#31092. This commit
removes it.
Trott pushed a commit that referenced this pull request Jan 2, 2020
This custom ESLint rule is unused since
#31092. This commit
removes it.

PR-URL: #31147
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: James M Snell <[email protected]>
BridgeAR added a commit that referenced this pull request Jan 3, 2020
This completely refactors the `expectsError` behavior: so far it's
almost identical to `assert.throws(fn, object)` in case it was used
with a function as first argument. It had a magical property check
that allowed to verify a functions `type` in case `type` was passed
used in the validation object. This pattern is now completely removed
and `assert.throws()` should be used instead.

The main intent for `common.expectsError()` is to verify error cases
for callback based APIs. This is now more flexible by accepting all
validation possibilites that `assert.throws()` accepts as well. No
magical properties exist anymore. This reduces surprising behavior
for developers who are not used to the Node.js core code base.

This has the side effect that `common` is used significantly less
frequent.

PR-URL: #31092
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
BridgeAR pushed a commit that referenced this pull request Jan 3, 2020
This custom ESLint rule is unused since
#31092. This commit
removes it.

PR-URL: #31147
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Jan 7, 2020
@targos
Copy link
Member

targos commented Jan 14, 2020

This needs a backport or other previous PRs to be backported in order to land on v12.x-staging.

@BridgeAR BridgeAR deleted the 2019-12-25-refactor-common-expects-error branch January 20, 2020 12:08
MylesBorins pushed a commit to sxa/node that referenced this pull request Apr 1, 2020
This completely refactors the `expectsError` behavior: so far it's
almost identical to `assert.throws(fn, object)` in case it was used
with a function as first argument. It had a magical property check
that allowed to verify a functions `type` in case `type` was passed
used in the validation object. This pattern is now completely removed
and `assert.throws()` should be used instead.

The main intent for `common.expectsError()` is to verify error cases
for callback based APIs. This is now more flexible by accepting all
validation possibilites that `assert.throws()` accepts as well. No
magical properties exist anymore. This reduces surprising behavior
for developers who are not used to the Node.js core code base.

This has the side effect that `common` is used significantly less
frequent.

Backport-PR-URL: nodejs#31449
PR-URL: nodejs#31092
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
MylesBorins pushed a commit that referenced this pull request Apr 1, 2020
This completely refactors the `expectsError` behavior: so far it's
almost identical to `assert.throws(fn, object)` in case it was used
with a function as first argument. It had a magical property check
that allowed to verify a functions `type` in case `type` was passed
used in the validation object. This pattern is now completely removed
and `assert.throws()` should be used instead.

The main intent for `common.expectsError()` is to verify error cases
for callback based APIs. This is now more flexible by accepting all
validation possibilites that `assert.throws()` accepts as well. No
magical properties exist anymore. This reduces surprising behavior
for developers who are not used to the Node.js core code base.

This has the side effect that `common` is used significantly less
frequent.

Backport-PR-URL: #31449
PR-URL: #31092
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
@codebytere codebytere mentioned this pull request Apr 3, 2020
targos pushed a commit to targos/node that referenced this pull request Apr 25, 2020
This custom ESLint rule is unused since
nodejs#31092. This commit
removes it.

PR-URL: nodejs#31147
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: James M Snell <[email protected]>
targos pushed a commit that referenced this pull request Apr 28, 2020
This custom ESLint rule is unused since
#31092. This commit
removes it.

PR-URL: #31147
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: James M Snell <[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.

7 participants