Skip to content

Commit

Permalink
doc: add countdown module to writing tests guide
Browse files Browse the repository at this point in the history
PR-URL: #17201
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
  • Loading branch information
Bamieh authored and MylesBorins committed Jan 9, 2018
1 parent 373d5df commit d1af106
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions doc/guides/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,15 @@ 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
this with a real test from the test suite.
#### 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
'use strict';
Expand Down Expand Up @@ -194,6 +198,23 @@ 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).

```javascript
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 d1af106

Please sign in to comment.