Skip to content

Commit

Permalink
Include time since window initialised in rAF implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 30, 2017
1 parent b3f85a2 commit 9abbe75
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/jest-environment-jsdom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JSDOMEnvironment {
moduleMocker: ?ModuleMocker;

constructor(config: ProjectConfig): void {
const jsdomInitialized = process.hrtime();
// lazy require
this.document = JSDom.jsdom('<!DOCTYPE html>', {
url: config.testURL,
Expand All @@ -34,7 +35,11 @@ class JSDOMEnvironment {

if (!global.requestAnimationFrame) {
global.requestAnimationFrame = callback => {
global.setTimeout(callback, 0);
const hr = process.hrtime(jsdomInitialized);
const hrInNano = hr[0] * 1e9 + hr[1];
const hrInMicro = hrInNano / 1e6;

return global.setTimeout(callback, 0, hrInMicro);
};
}

Expand Down

0 comments on commit 9abbe75

Please sign in to comment.