Skip to content

Commit 8414659

Browse files
weeweyMylesBorins
authored andcommitted
test: refactoring test with common.mustCall
PR-URL: #12702 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 608c309 commit 8414659

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

test/parallel/test-https-simple.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,31 @@ const serverCallback = common.mustCall(function(req, res) {
3434

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

37-
server.listen(0, function() {
37+
server.listen(0, common.mustCall(() => {
3838
// Do a request ignoring the unauthorized server certs
39+
const port = server.address().port;
40+
3941
const noCertCheckOptions = {
4042
hostname: '127.0.0.1',
41-
port: this.address().port,
43+
port: port,
4244
path: '/',
4345
method: 'GET',
4446
rejectUnauthorized: false
4547
};
48+
4649
noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions);
4750

48-
const req = https.request(noCertCheckOptions, function(res) {
51+
const req = https.request(noCertCheckOptions, common.mustCall((res) => {
4952
let responseBody = '';
5053
res.on('data', function(d) {
5154
responseBody = responseBody + d;
5255
});
5356

54-
res.on('end', function() {
57+
res.on('end', common.mustCall(() => {
5558
assert.strictEqual(responseBody, body);
5659
testSucceeded();
57-
});
58-
});
60+
}));
61+
}));
5962
req.end();
6063

6164
req.on('error', function(e) {
@@ -65,7 +68,7 @@ server.listen(0, function() {
6568
// Do a request that throws error due to the invalid server certs
6669
const checkCertOptions = {
6770
hostname: '127.0.0.1',
68-
port: this.address().port,
71+
port: port,
6972
path: '/',
7073
method: 'GET'
7174
};
@@ -81,11 +84,11 @@ server.listen(0, function() {
8184
});
8285
checkCertReq.end();
8386

84-
checkCertReq.on('error', function(e) {
87+
checkCertReq.on('error', common.mustCall((e) => {
8588
assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
8689
testSucceeded();
87-
});
88-
});
90+
}));
91+
}));
8992

9093
process.on('exit', function() {
9194
assert.strictEqual(successful, tests);

0 commit comments

Comments
 (0)