|
1 | 1 | 'use strict';
|
2 |
| -require('../common'); |
| 2 | +const common = require('../common'); |
3 | 3 | const assert = require('assert');
|
4 |
| - |
5 |
| -var exceptions = 0; |
6 |
| -var timer1 = 0; |
7 |
| -var timer2 = 0; |
| 4 | +const errorMsg = 'BAM!'; |
8 | 5 |
|
9 | 6 | // the first timer throws...
|
10 |
| -console.error('set first timer'); |
11 |
| -setTimeout(function() { |
12 |
| - console.error('first timer'); |
13 |
| - timer1++; |
14 |
| - throw new Error('BAM!'); |
15 |
| -}, 100); |
| 7 | +setTimeout(common.mustCall(function() { |
| 8 | + throw new Error(errorMsg); |
| 9 | +}), 1); |
16 | 10 |
|
17 | 11 | // ...but the second one should still run
|
18 |
| -console.error('set second timer'); |
19 |
| -setTimeout(function() { |
20 |
| - console.error('second timer'); |
21 |
| - assert.equal(timer1, 1); |
22 |
| - timer2++; |
23 |
| -}, 100); |
| 12 | +setTimeout(common.mustCall(function() {}), 1); |
24 | 13 |
|
25 | 14 | function uncaughtException(err) {
|
26 |
| - console.error('uncaught handler'); |
27 |
| - assert.equal(err.message, 'BAM!'); |
28 |
| - exceptions++; |
| 15 | + assert.strictEqual(err.message, errorMsg); |
29 | 16 | }
|
30 |
| -process.on('uncaughtException', uncaughtException); |
31 | 17 |
|
32 |
| -var exited = false; |
33 |
| -process.on('exit', function() { |
34 |
| - assert(!exited); |
35 |
| - exited = true; |
36 |
| - process.removeListener('uncaughtException', uncaughtException); |
37 |
| - assert.equal(exceptions, 1); |
38 |
| - assert.equal(timer1, 1); |
39 |
| - assert.equal(timer2, 1); |
40 |
| -}); |
| 18 | +process.on('uncaughtException', common.mustCall(uncaughtException)); |
0 commit comments