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
@@ -133,11 +133,15 @@ platforms.
133
133
134
134
### The *common* API
135
135
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.
137
139
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.
141
145
142
146
```javascript
143
147
'use strict';
@@ -189,6 +193,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
189
193
});
190
194
191
195
```
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
+
constCountdown=require('../common/countdown');
204
+
205
+
constcountdown=newCountdown(2, function() {
206
+
console.log('.');
207
+
});
208
+
209
+
countdown.dec();
210
+
countdown.dec(); // The countdown callback will be invoked now.
0 commit comments