// This works even after Sinon takes over the time in a Node.js environment
// But it is blocking so only suitable for tests
// Not the exact same signature are the native setTimeout, you can't pass arguments to the callback
var myBlockingSetTimeout = (function (Date) {
return function (cb, delay) {
var beginning = (new myDate()).getTime()
, now = (new myDate()).getTime();
while (now < beginning + delay) {
now = (new myDate()).getTime();
}
cb();
}
})(Date);
If you put this definition before Sinon takes over the Date object, you have a blocking setTimeout function because we have a local reference to a Date object that works (that wasn't the case with setTimeout as changing the global Date object impacted setTimeout). This is only suitable for tests so this will work OK for me, but I think it will be difficult to fix this for you since you can't inject dependencies into Node's core modules, and the timers module doesn't expose its internal Timeout constructor.