From 8414659d0251fe974483561bbf6c86d6214ce960 Mon Sep 17 00:00:00 2001 From: weewey Date: Fri, 28 Apr 2017 11:21:01 +0800 Subject: [PATCH] test: refactoring test with common.mustCall PR-URL: https://github.com/nodejs/node/pull/12702 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen --- test/parallel/test-https-simple.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-https-simple.js b/test/parallel/test-https-simple.js index 56d6f10afb003f..78c13dc0ed7c0b 100644 --- a/test/parallel/test-https-simple.js +++ b/test/parallel/test-https-simple.js @@ -34,28 +34,31 @@ const serverCallback = common.mustCall(function(req, res) { const server = https.createServer(options, serverCallback); -server.listen(0, function() { +server.listen(0, common.mustCall(() => { // Do a request ignoring the unauthorized server certs + const port = server.address().port; + const noCertCheckOptions = { hostname: '127.0.0.1', - port: this.address().port, + port: port, path: '/', method: 'GET', rejectUnauthorized: false }; + noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions); - const req = https.request(noCertCheckOptions, function(res) { + const req = https.request(noCertCheckOptions, common.mustCall((res) => { let responseBody = ''; res.on('data', function(d) { responseBody = responseBody + d; }); - res.on('end', function() { + res.on('end', common.mustCall(() => { assert.strictEqual(responseBody, body); testSucceeded(); - }); - }); + })); + })); req.end(); req.on('error', function(e) { @@ -65,7 +68,7 @@ server.listen(0, function() { // Do a request that throws error due to the invalid server certs const checkCertOptions = { hostname: '127.0.0.1', - port: this.address().port, + port: port, path: '/', method: 'GET' }; @@ -81,11 +84,11 @@ server.listen(0, function() { }); checkCertReq.end(); - checkCertReq.on('error', function(e) { + checkCertReq.on('error', common.mustCall((e) => { assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'); testSucceeded(); - }); -}); + })); +})); process.on('exit', function() { assert.strictEqual(successful, tests);