Skip to content

Commit

Permalink
test: improve test-https-agent.js
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
Williams-Dan authored and Fishrock123 committed Oct 11, 2016
1 parent 8684cea commit b10467c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions test/parallel/test-https-agent.js
Original file line number Diff line number Diff line change
@@ -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++) {
Expand All @@ -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);
Expand All @@ -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 b10467c

Please sign in to comment.