From d2bb4862d20d581f6f5511e1ebc3f9a1c821fbf6 Mon Sep 17 00:00:00 2001 From: garygsc Date: Fri, 25 Oct 2019 17:04:26 -0600 Subject: [PATCH 1/3] doc: use arrow functions in writing-tests.md --- doc/guides/writing-tests.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/guides/writing-tests.md b/doc/guides/writing-tests.md index 584b1d2373ce1b..460a0cd221191b 100644 --- a/doc/guides/writing-tests.md +++ b/doc/guides/writing-tests.md @@ -163,7 +163,7 @@ const http = require('http'); let request = 0; let response = 0; -process.on('exit', function() { +process.on('exit', () => { assert.equal(request, 1, 'http server "request" callback was not called'); assert.equal(response, 1, 'http request "response" callback was not called'); }); @@ -171,10 +171,10 @@ process.on('exit', function() { const server = http.createServer((req, res) => { request++; res.end(); -}).listen(0, function() { +}).listen(0, () => { const options = { agent: null, - port: this.address().port + port: server.address().port }; http.get(options, (res) => { response++; @@ -193,10 +193,10 @@ const http = require('http'); const server = http.createServer(common.mustCall((req, res) => { res.end(); -})).listen(0, function() { +})).listen(0, () => { const options = { agent: null, - port: this.address().port + port: server.address().port }; http.get(options, common.mustCall((res) => { res.resume(); @@ -216,7 +216,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('.'); }); From f57926fc6d9a4cc0a854652c615d2d55dd997d40 Mon Sep 17 00:00:00 2001 From: garygsc Date: Fri, 25 Oct 2019 17:19:01 -0600 Subject: [PATCH 2/3] doc: sync example in writing-tests.md Match test/parallel/test-http-agent-null.js --- doc/guides/writing-tests.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/guides/writing-tests.md b/doc/guides/writing-tests.md index 460a0cd221191b..9e65821db34599 100644 --- a/doc/guides/writing-tests.md +++ b/doc/guides/writing-tests.md @@ -193,7 +193,7 @@ const http = require('http'); const server = http.createServer(common.mustCall((req, res) => { res.end(); -})).listen(0, () => { +})).listen(0, common.mustCall(() => { const options = { agent: null, port: server.address().port @@ -202,7 +202,7 @@ const server = http.createServer(common.mustCall((req, res) => { res.resume(); server.close(); })); -}); +})); ``` From e2e095af68268527d2e2bccf5809aeb86c9d2e21 Mon Sep 17 00:00:00 2001 From: garygsc Date: Fri, 25 Oct 2019 17:45:09 -0600 Subject: [PATCH 3/3] doc: match functionality in writing-tests.md example --- doc/guides/writing-tests.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/guides/writing-tests.md b/doc/guides/writing-tests.md index 9e65821db34599..7022bf8f938f78 100644 --- a/doc/guides/writing-tests.md +++ b/doc/guides/writing-tests.md @@ -162,9 +162,11 @@ const assert = require('assert'); const http = require('http'); let request = 0; +let listening = 0; let response = 0; 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'); }); @@ -172,6 +174,7 @@ const server = http.createServer((req, res) => { request++; res.end(); }).listen(0, () => { + listening++; const options = { agent: null, port: server.address().port