summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBamieh <ahmadbamieh@gmail.com>2017-12-12 22:43:00 +0200
committerMyles Borins <mylesborins@google.com>2018-02-12 19:28:17 -0500
commitd0b89a12ec5578188b80b5f13a494b6dc1a94040 (patch)
tree633d1b06f66c53033f6b68678fa67dc2fbaf26d6
parentcc03470b82d8d641cd11a107aec96836f3cea493 (diff)
downloadnode-new-d0b89a12ec5578188b80b5f13a494b6dc1a94040.tar.gz
doc: add countdown module to writing tests guide
PR-URL: https://github.com/nodejs/node/pull/17201 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Jon Moss <me@jonathanmoss.me>
-rw-r--r--doc/guides/writing-tests.md29
1 files changed, 25 insertions, 4 deletions
diff --git a/doc/guides/writing-tests.md b/doc/guides/writing-tests.md
index 64181586b5..519db97e55 100644
--- a/doc/guides/writing-tests.md
+++ b/doc/guides/writing-tests.md
@@ -133,11 +133,15 @@ platforms.
### The *common* API
-Make use of the helpers from the `common` module as much as possible.
+Make use of the helpers from the `common` module as much as possible. Please refer
+to the [common file documentation](https://github.com/nodejs/node/tree/master/test/common)
+for the full details of the helpers.
-One interesting case is `common.mustCall`. The use of `common.mustCall` may
-avoid the use of extra variables and the corresponding assertions. Let's explain
-this with a real test from the test suite.
+#### common.mustCall
+
+One interesting case is `common.mustCall`. The use of `common.mustCall` may avoid
+the use of extra variables and the corresponding assertions. Let's explain this
+with a real test from the test suite.
```javascript
'use strict';
@@ -189,6 +193,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
});
```
+#### Countdown Module
+
+The common [Countdown module](https://github.com/nodejs/node/tree/master/test/common#countdown-module) provides a simple countdown mechanism for tests that
+require a particular action to be taken after a given number of completed tasks
+(for instance, shutting down an HTTP server after a specific number of requests).
+
+```javascript
+const Countdown = require('../common/countdown');
+
+const countdown = new Countdown(2, function() {
+ console.log('.');
+});
+
+countdown.dec();
+countdown.dec(); // The countdown callback will be invoked now.
+```
+
### Flags