|
1 | 1 | 'use strict';
|
2 | 2 | const common = require('../common');
|
3 |
| -const assert = require('assert'); |
| 3 | +const timers = require('timers'); |
4 | 4 |
|
5 |
| -// don't verify the globals for this test |
6 |
| -common.globalCheck = false; |
| 5 | +// delete global APIs to make sure they're not relied on by the internal timers |
| 6 | +// code |
| 7 | +delete global.setTimeout; |
| 8 | +delete global.clearTimeout; |
| 9 | +delete global.setInterval; |
| 10 | +delete global.clearInterval; |
| 11 | +delete global.setImmediate; |
| 12 | +delete global.clearImmediate; |
7 | 13 |
|
8 |
| -// try overriding global APIs to make sure |
9 |
| -// they're not relied on by the timers |
10 |
| -global.clearTimeout = assert.fail; |
| 14 | +const timeoutCallback = () => { timers.clearTimeout(timeout); }; |
| 15 | +const timeout = timers.setTimeout(common.mustCall(timeoutCallback), 1); |
11 | 16 |
|
12 |
| -// run timeouts/intervals through the paces |
13 |
| -const intv = setInterval(function() {}, 1); |
14 |
| - |
15 |
| -setTimeout(function() { |
16 |
| - clearInterval(intv); |
17 |
| -}, 100); |
18 |
| - |
19 |
| -setTimeout(function() {}, 2); |
| 17 | +const intervalCallback = () => { timers.clearInterval(interval); }; |
| 18 | +const interval = timers.setInterval(common.mustCall(intervalCallback), 1); |
20 | 19 |
|
| 20 | +const immediateCallback = () => { timers.clearImmediate(immediate); }; |
| 21 | +const immediate = timers.setImmediate(immediateCallback); |
0 commit comments