Skip to content

Commit d9fc0e2

Browse files
committed
Document countdown module in the 'writing tests' guide
1 parent 446c1ec commit d9fc0e2

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

doc/guides/writing-tests.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ platforms.
133133

134134
### The *common* API
135135

136-
Make use of the helpers from the `common` module as much as possible.
136+
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.
137137

138-
One interesting case is `common.mustCall`. The use of `common.mustCall` may
139-
avoid the use of extra variables and the corresponding assertions. Let's explain
138+
#### common.mustCall
139+
140+
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
140141
this with a real test from the test suite.
141142

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

191192
```
193+
#### Countdown Module
194+
195+
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).
196+
197+
```
198+
const Countdown = require('../common/countdown');
199+
200+
const countdown = new Countdown(2, function() {
201+
console.log('.');
202+
});
203+
204+
countdown.dec();
205+
countdown.dec(); // The countdown callback will be invoked now.
206+
```
207+
192208

193209
### Flags
194210

0 commit comments

Comments
 (0)