Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update examples in writing-tests.md #30126

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions doc/guides/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,22 @@ const assert = require('assert');
const http = require('http');

let request = 0;
let listening = 0;
let response = 0;
process.on('exit', function() {
process.on('exit', () => {
assert.equal(request, 1, 'http server "request" callback was not called');
assert.equal(listening, 1, 'http server "listening" callback was not called');
assert.equal(response, 1, 'http request "response" callback was not called');
});

const server = http.createServer((req, res) => {
request++;
res.end();
}).listen(0, function() {
}).listen(0, () => {
listening++;
const options = {
agent: null,
port: this.address().port
port: server.address().port
};
http.get(options, (res) => {
response++;
Expand All @@ -193,16 +196,16 @@ const http = require('http');

const server = http.createServer(common.mustCall((req, res) => {
res.end();
})).listen(0, function() {
})).listen(0, common.mustCall(() => {
trivikr marked this conversation as resolved.
Show resolved Hide resolved
const options = {
agent: null,
port: this.address().port
port: server.address().port
};
http.get(options, common.mustCall((res) => {
res.resume();
server.close();
}));
});
}));

```

Expand All @@ -216,7 +219,7 @@ shutting down an HTTP server after a specific number of requests).
```javascript
const Countdown = require('../common/countdown');

const countdown = new Countdown(2, function() {
const countdown = new Countdown(2, () => {
console.log('.');
});

Expand Down