Skip to content

Commit

Permalink
test: refactoring test with common.mustCall
Browse files Browse the repository at this point in the history
  • Loading branch information
weewey committed Apr 28, 2017
1 parent 892ce06 commit 4ca46bb
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions test/parallel/test-https-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ const options = {
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};

const tests = 2;
let successful = 0;

const testSucceeded = function() {
successful = successful + 1;
if (successful === tests) {
server.close();
}
};

const body = 'hello world\n';

const serverCallback = common.mustCall(function(req, res) {
Expand All @@ -55,7 +45,7 @@ const serverCallback = common.mustCall(function(req, res) {

const server = https.createServer(options, serverCallback);

server.listen(0, function() {
server.listen(0, function(){
// Do a request ignoring the unauthorized server certs
const noCertCheckOptions = {
hostname: '127.0.0.1',
Expand All @@ -66,16 +56,15 @@ server.listen(0, function() {
};
noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions);

const req = https.request(noCertCheckOptions, function(res) {
const req = https.request(noCertCheckOptions, function(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();

Expand Down Expand Up @@ -108,6 +97,6 @@ server.listen(0, function() {
});
});

process.on('exit', function() {
assert.strictEqual(successful, tests);
});
function testSucceeded (){
server.close();
};

0 comments on commit 4ca46bb

Please sign in to comment.