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: add common.mustSucceed #35086

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc,test: document common.mustSucceed
  • Loading branch information
tniessen committed Oct 13, 2020
commit c275bf07a5ccd0ec5c63b09549059f71522d3d79
5 changes: 5 additions & 0 deletions doc/guides/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ const server = http.createServer(common.mustCall((req, res) => {

```

**Note:** Many functions invoke their callback with an `err` value as the first
argument. It is not a good idea to simply pass `common.mustCall()` to those
because `common.mustCall()` will ignore the error. Use `common.mustSucceed()`
instead.

#### Countdown Module

The common [Countdown module](https://github.com/nodejs/node/tree/master/test/common#countdown-module)
Expand Down
9 changes: 9 additions & 0 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ If `fn` is not provided, an empty function will be used.
Returns a function that triggers an `AssertionError` if it is invoked. `msg` is
used as the error message for the `AssertionError`.

### `mustSucceed([fn])`

* `fn` [<Function>][] default = () => {}
* return [<Function>][]

Returns a function that accepts arguments `(err, ...args)`. If `err` is not
`undefined` or `null`, it triggers an `AssertionError`. Otherwise, it calls
`fn(...args)`.

### `nodeProcessAborted(exitCode, signal)`

* `exitCode` [<number>][]
Expand Down