Browse Source

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 <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>
v7.x
Dan.Williams 8 years ago
committed by Rich Trott
parent
commit
a89c23f8eb
  1. 26
      test/parallel/test-https-agent.js

26
test/parallel/test-https-agent.js

@ -1,30 +1,31 @@
'use strict'; 'use strict';
var common = require('../common'); const common = require('../common');
var assert = require('assert'); const assert = require('assert');
if (!common.hasCrypto) { if (!common.hasCrypto) {
common.skip('missing crypto'); common.skip('missing crypto');
return; 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'), key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.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.writeHead(200);
res.end('hello world\n'); res.end('hello world\n');
}); });
var responses = 0; var responses = 0;
var N = 4; const N = 4;
var M = 4; const M = 4;
server.listen(0, function() { server.listen(0, function() {
for (var i = 0; i < N; i++) { for (var i = 0; i < N; i++) {
@ -36,11 +37,10 @@ server.listen(0, function() {
rejectUnauthorized: false rejectUnauthorized: false
}, function(res) { }, function(res) {
res.resume(); res.resume();
console.log(res.statusCode); assert.strictEqual(res.statusCode, 200);
if (++responses == N * M) server.close(); if (++responses === N * M) server.close();
}).on('error', function(e) { }).on('error', function(e) {
console.log(e.message); throw e;
process.exit(1);
}); });
} }
}, i); }, i);
@ -49,5 +49,5 @@ server.listen(0, function() {
process.on('exit', function() { process.on('exit', function() {
assert.equal(N * M, responses); assert.strictEqual(N * M, responses);
}); });

Loading…
Cancel
Save