Skip to content

Commit d1af106

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 373d5df commit d1af106

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
@@ -138,11 +138,15 @@ platforms.
138138

139139
### The *common* API
140140

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

143-
One interesting case is `common.mustCall`. The use of `common.mustCall` may
144-
avoid the use of extra variables and the corresponding assertions. Let's explain
145-
this with a real test from the test suite.
145+
#### common.mustCall
146+
147+
One interesting case is `common.mustCall`. The use of `common.mustCall` may avoid
148+
the use of extra variables and the corresponding assertions. Let's explain this
149+
with a real test from the test suite.
146150

147151
```javascript
148152
'use strict';
@@ -194,6 +198,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
194198
});
195199

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

198219
### Flags
199220

0 commit comments

Comments
 (0)