Skip to content

Commit 152966d

Browse files
weeweyaddaleax
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 6058c43 commit 152966d

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
@@ -55,28 +55,31 @@ const serverCallback = common.mustCall(function(req, res) {
5555

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

58-
server.listen(0, function() {
58+
server.listen(0, common.mustCall(() => {
5959
// Do a request ignoring the unauthorized server certs
60+
const port = server.address().port;
61+
6062
const noCertCheckOptions = {
6163
hostname: '127.0.0.1',
62-
port: this.address().port,
64+
port: port,
6365
path: '/',
6466
method: 'GET',
6567
rejectUnauthorized: false
6668
};
69+
6770
noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions);
6871

69-
const req = https.request(noCertCheckOptions, function(res) {
72+
const req = https.request(noCertCheckOptions, common.mustCall((res) => {
7073
let responseBody = '';
7174
res.on('data', function(d) {
7275
responseBody = responseBody + d;
7376
});
7477

75-
res.on('end', function() {
78+
res.on('end', common.mustCall(() => {
7679
assert.strictEqual(responseBody, body);
7780
testSucceeded();
78-
});
79-
});
81+
}));
82+
}));
8083
req.end();
8184

8285
req.on('error', function(e) {
@@ -86,7 +89,7 @@ server.listen(0, function() {
8689
// Do a request that throws error due to the invalid server certs
8790
const checkCertOptions = {
8891
hostname: '127.0.0.1',
89-
port: this.address().port,
92+
port: port,
9093
path: '/',
9194
method: 'GET'
9295
};
@@ -102,11 +105,11 @@ server.listen(0, function() {
102105
});
103106
checkCertReq.end();
104107

105-
checkCertReq.on('error', function(e) {
108+
checkCertReq.on('error', common.mustCall((e) => {
106109
assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
107110
testSucceeded();
108-
});
109-
});
111+
}));
112+
}));
110113

111114
process.on('exit', function() {
112115
assert.strictEqual(successful, tests);

0 commit comments

Comments
 (0)