GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • doc/guides
    • writing-tests.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/guides/writing-tests.md‎

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 numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ platforms.
133133

134134
### The *common* API
135135

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.
137139

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.
141145

142146
```javascript
143147
'use strict';
@@ -189,6 +193,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
189193
});
190194

191195
```
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+
192213

193214
### Flags
194215

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.