Skip to content

Commit 9e46af6

Browse files
radelmannMylesBorins
authored andcommitted
test: refactor test-beforeexit-event
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener. PR-URL: #10121 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent aecb2ca commit 9e46af6

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed
Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
'use strict';
2-
require('../common');
3-
varassert=require('assert');
4-
varnet=require('net');
5-
varrevivals=0;
6-
vardeaths=0;
2+
constcommon=require('../common');
3+
constnet=require('net');
74

8-
process.on('beforeExit',function(){deaths++;});
9-
10-
process.once('beforeExit',tryImmediate);
5+
process.once('beforeExit',common.mustCall(tryImmediate));
116

127
functiontryImmediate(){
13-
console.log('set immediate');
14-
setImmediate(function(){
15-
revivals++;
16-
process.once('beforeExit',tryTimer);
17-
});
8+
setImmediate(common.mustCall(()=>{
9+
process.once('beforeExit',common.mustCall(tryTimer));
10+
}));
1811
}
1912

2013
functiontryTimer(){
21-
console.log('set a timeout');
22-
setTimeout(function(){
23-
console.log('timeout cb, do another once beforeExit');
24-
revivals++;
25-
process.once('beforeExit',tryListen);
26-
},1);
14+
setTimeout(common.mustCall(()=>{
15+
process.once('beforeExit',common.mustCall(tryListen));
16+
}),1);
2717
}
2818

2919
functiontryListen(){
30-
console.log('create a server');
3120
net.createServer()
3221
.listen(0)
33-
.on('listening',function(){
34-
revivals++;
22+
.on('listening',common.mustCall(function(){
3523
this.close();
36-
});
24+
process.on('beforeExit',common.mustCall(()=>{}));
25+
}));
3726
}
38-
39-
process.on('exit',function(){
40-
assert.strictEqual(4,deaths);
41-
assert.strictEqual(3,revivals);
42-
});

0 commit comments

Comments
(0)