Skip to content

Commit 1114080

Browse files
radelmannaddaleax
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 d64e52c commit 1114080

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed
+12-28
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
'use strict';
2-
require('../common');
3-
var assert = require('assert');
4-
var net = require('net');
5-
var revivals = 0;
6-
var deaths = 0;
2+
const common = require('../common');
3+
const net = require('net');
74

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

127
function tryImmediate() {
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
function tryTimer() {
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
function tryListen() {
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)