Skip to content

Commit d0b89a1

Browse files
BamiehMylesBorins
authored andcommitted
doc: add countdown module to writing tests guide
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]>
1 parent cc03470 commit d0b89a1

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

doc/guides/writing-tests.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ 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
137+
to the [common file documentation](https://github.com/nodejs/node/tree/master/test/common)
138+
for the full details of the helpers.
137139

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

142146
```javascript
143147
'use strict';
@@ -189,6 +193,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
189193
});
190194

191195
```
196+
#### Countdown Module
197+
198+
The common [Countdown module](https://github.com/nodejs/node/tree/master/test/common#countdown-module) provides a simple countdown mechanism for tests that
199+
require a particular action to be taken after a given number of completed tasks
200+
(for instance, shutting down an HTTP server after a specific number of requests).
201+
202+
```javascript
203+
const Countdown = require('../common/countdown');
204+
205+
const countdown = new Countdown(2, function() {
206+
console.log('.');
207+
});
208+
209+
countdown.dec();
210+
countdown.dec(); // The countdown callback will be invoked now.
211+
```
212+
192213

193214
### Flags
194215

0 commit comments

Comments
 (0)