From a89c23f8ebb8d47e2f577d3594bfb465c1861d25 Mon Sep 17 00:00:00 2001 From: "Dan.Williams" Date: Tue, 13 Sep 2016 19:27:34 +0100 Subject: [PATCH] test: improve test-https-agent.js On line 40: replace '==' with '===' On line 52: replace 'assert.equal' with 'assert.strictEqual' Added some comments. Changed 'var' to 'const' where possible. Replaced console.log(res.statusCode); with and assertion. Rather than logging the https request status on every loop it will now assert the https status is correct on every loop. Changed the error listener to throw the error rather than log it. PR-URL: https://github.com/nodejs/node/pull/8517 Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- test/parallel/test-https-agent.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-https-agent.js b/test/parallel/test-https-agent.js index 2ad3bd8d01..221ed2bbd2 100644 --- a/test/parallel/test-https-agent.js +++ b/test/parallel/test-https-agent.js @@ -1,30 +1,31 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var https = require('https'); +const https = require('https'); -var fs = require('fs'); +const fs = require('fs'); -var options = { +const options = { key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') }; -var server = https.Server(options, function(req, res) { +const server = https.Server(options, function(req, res) { res.writeHead(200); res.end('hello world\n'); }); var responses = 0; -var N = 4; -var M = 4; +const N = 4; +const M = 4; + server.listen(0, function() { for (var i = 0; i < N; i++) { @@ -36,11 +37,10 @@ server.listen(0, function() { rejectUnauthorized: false }, function(res) { res.resume(); - console.log(res.statusCode); - if (++responses == N * M) server.close(); + assert.strictEqual(res.statusCode, 200); + if (++responses === N * M) server.close(); }).on('error', function(e) { - console.log(e.message); - process.exit(1); + throw e; }); } }, i); @@ -49,5 +49,5 @@ server.listen(0, function() { process.on('exit', function() { - assert.equal(N * M, responses); + assert.strictEqual(N * M, responses); });