Skip to content

Commit

Permalink
Document countdown module in the 'writing tests' guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Dec 12, 2017
1 parent 446c1ec commit d9fc0e2
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions doc/guides/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ platforms.

### The *common* API

Make use of the helpers from the `common` module as much as possible.
Make use of the helpers from the `common` module as much as possible. Please refer to the [common file documentation](https://github.com/nodejs/node/tree/master/test/common) for the full details of the helpers.

One interesting case is `common.mustCall`. The use of `common.mustCall` may
avoid the use of extra variables and the corresponding assertions. Let's explain
#### common.mustCall

One interesting case is `common.mustCall`. The use of `common.mustCall` may avoid the use of extra variables and the corresponding assertions. Let's explain
this with a real test from the test suite.

```javascript
Expand Down Expand Up @@ -189,6 +190,21 @@ const server = http.createServer(common.mustCall(function(req, res) {
});

```
#### Countdown Module

The common [Countdown module](https://github.com/nodejs/node/tree/master/test/common#countdown-module) provides a simple countdown mechanism for tests that require a particular action to be taken after a given number of completed tasks (for instance, shutting down an HTTP server after a specific number of requests).

```
const Countdown = require('../common/countdown');
const countdown = new Countdown(2, function() {
console.log('.');
});
countdown.dec();
countdown.dec(); // The countdown callback will be invoked now.
```


### Flags

Expand Down

0 comments on commit d9fc0e2

Please sign in to comment.