virtual-time
v0.1.0
Published
Fast forward the event loop when it runs out of work
Downloads
3
Maintainers
Readme
virtual-time
Fast forward the event loop when it runs out of work
When installed, this library overwrites setTimeout
, clearTimeout
, setInterval
, clearInterval
and Date
functionality.
It will fast forward the timers on the event loop whenever it is idle.
Example
const virtualTime = require('virtual-time');
let realNow = Date.now;
virtualTime.install();
let startTimeReal = realNow();
let startTimeVirtual = Date.now();
setTimeout(() => {
let durationReal = realNow() - startTimeReal;
let durationVirtual = Date.now() - startTimeVirtual;
console.log(`Real duration: ${durationReal}ms; Virtual duration: ${durationVirtual}ms`);
}, 100000);
API
.install( [Object options] )
This will install the library.
options
number time
Default 0
. The time in milliseconds of when the clock starts.
boolean addExecutionTime
Default true
. This option makes it so execution time is calculated in the Date.now()
call.
Disable this option if you need deterministic Date.now()
behavior.
.uninstall()
This will restore the timer functions to their normal state.