Skip to content

Commit 3238bff

Browse files
Trottevanlucas
authored andcommitted
test: confirm globals not used internally
PR-URL: #5882 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent a41fd93 commit 3238bff

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

test/parallel/test-timers-api-refs.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
3+
const timers = require('timers');
44

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;
713

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);
1116

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);
2019

20+
const immediateCallback = () => { timers.clearImmediate(immediate); };
21+
const immediate = timers.setImmediate(immediateCallback);

0 commit comments

Comments
 (0)