Skip to content

Commit

Permalink
test: confirm globals not used internally
Browse files Browse the repository at this point in the history
PR-URL: #5882
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
  • Loading branch information
Trott committed Mar 28, 2016
1 parent 9fa25c8 commit f0367d0
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions test/parallel/test-timers-api-refs.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const timers = require('timers');

// don't verify the globals for this test
common.globalCheck = false;
// delete global APIs to make sure they're not relied on by the internal timers
// code
delete global.setTimeout;
delete global.clearTimeout;
delete global.setInterval;
delete global.clearInterval;
delete global.setImmediate;
delete global.clearImmediate;

// try overriding global APIs to make sure
// they're not relied on by the timers
global.clearTimeout = assert.fail;
const timeoutCallback = () => { timers.clearTimeout(timeout); };
const timeout = timers.setTimeout(common.mustCall(timeoutCallback), 1);

// run timeouts/intervals through the paces
const intv = setInterval(function() {}, 1);

setTimeout(function() {
clearInterval(intv);
}, 100);

setTimeout(function() {}, 2);
const intervalCallback = () => { timers.clearInterval(interval); };
const interval = timers.setInterval(common.mustCall(intervalCallback), 1);

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

0 comments on commit f0367d0

Please sign in to comment.