GeezerVison is showing github.com — doc: add countdown module to writing tests guide · nodejs/node@d0b89a1
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/guides/writing-tests.md +25-4Lines changed: 25 additions & 4 deletions - Display the source diff
- Display the rich diff
| 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 | +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 | + |
192 | 213 |
|
193 | 214 | ### Flags |
194 | 215 |
|
|