Permalink
Browse files

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: #8517
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information...
Williams-Dan authored and Trott committed Sep 13, 2016
1 parent 7926886 commit a89c23f8ebb8d47e2f577d3594bfb465c1861d25
Showing with 13 additions and 13 deletions.
  1. +13 −13 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);
});

0 comments on commit a89c23f

Please sign in to comment.