-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple rAF polyfill in jsdom environment #4568
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3c6b120
Add simple rAF polyfill in jsdom environment
SimenB 617562d
Fix flow error
SimenB 484c26d
Tweak test
SimenB 08d58c5
Try to log out stderr on CI
SimenB 23dd2bc
Use snake case naming for test file
SimenB 7c91e67
Update to newest yarn on ci
SimenB 78b5ebf
Revert "Try to log out stderr on CI"
SimenB b3f85a2
Remove extra -- from appveyor to avoid warning on newer yarn
SimenB 4968028
Include time since window initialised in rAF implementation
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
integration_tests/__tests__/request_animation_frame.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
const runJest = require('../runJest'); | ||
|
||
test('requestAnimationFrame', () => { | ||
const result = runJest('request_animation_frame', ['--verbose']); | ||
const stderr = result.stderr.toString(); | ||
|
||
expect(stderr).toMatch('requestAnimationFrame test'); | ||
expect(result.status).toBe(0); | ||
}); |
21 changes: 21 additions & 0 deletions
21
integration_tests/request_animation_frame/__tests__/request_animation_frame.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/* eslint-env browser */ | ||
|
||
'use strict'; | ||
|
||
test('requestAnimationFrame test', done => { | ||
expect.hasAssertions(); | ||
|
||
requestAnimationFrame(timestamp => { | ||
expect(true).toBe(true); | ||
expect(timestamp).toBeGreaterThan(0); | ||
|
||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "jsdom" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -32,6 +33,16 @@ class JSDOMEnvironment { | |
this.global.Error.stackTraceLimit = 100; | ||
installCommonGlobals(global, config.globals); | ||
|
||
if (!global.requestAnimationFrame) { | ||
global.requestAnimationFrame = callback => { | ||
const hr = process.hrtime(jsdomInitialized); | ||
const hrInNano = hr[0] * 1e9 + hr[1]; | ||
const hrInMicro = hrInNano / 1e6; | ||
|
||
return global.setTimeout(callback, 0, hrInMicro); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm currently working on getting it upstreamed into JSDOM, so I read some of the spec. I don't know if people use this argument, or expect it to be in any way accurate, but this is a best effort 🙂 |
||
}; | ||
} | ||
|
||
this.moduleMocker = new mock.ModuleMocker(global); | ||
this.fakeTimers = new FakeTimers(global, this.moduleMocker, config); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to have it beneath the
JSDom.jsdom
call, but that makes stuff fail with an odd flow error...