Skip to content

Commit 8414659

Browse files
weeweyMylesBorins
authored andcommitted
test: refactoring test with common.mustCall
PR-URL: #12702 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 608c309 commit 8414659

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

‎test/parallel/test-https-simple.js‎

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

3535
constserver=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+
constport=server.address().port;
40+
3941
constnoCertCheckOptions={
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=newhttps.Agent(noCertCheckOptions);
4750

48-
constreq=https.request(noCertCheckOptions,function(res){
51+
constreq=https.request(noCertCheckOptions,common.mustCall((res)=>{
4952
letresponseBody='';
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
constcheckCertOptions={
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)