You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: doc/guides/writing-tests.md
+25-4
Original file line number
Diff line number
Diff line change
@@ -138,11 +138,15 @@ platforms.
138
138
139
139
### The *common* API
140
140
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.
142
144
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.
146
150
147
151
```javascript
148
152
'use strict';
@@ -194,6 +198,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
194
198
});
195
199
196
200
```
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
+
constCountdown=require('../common/countdown');
209
+
210
+
constcountdown=newCountdown(2, function() {
211
+
console.log('.');
212
+
});
213
+
214
+
countdown.dec();
215
+
countdown.dec(); // The countdown callback will be invoked now.
0 commit comments