-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
chore: make tests compatible with Jest 24 #15779
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,13 +37,7 @@ describe('ChangeEventPlugin', () => { | |
ReactFeatureFlags = require('shared/ReactFeatureFlags'); | ||
// TODO pull this into helper method, reduce repetition. | ||
// mock the browser APIs which are used in schedule: | ||
// - requestAnimationFrame should pass the DOMHighResTimeStamp argument | ||
// - calling 'window.postMessage' should actually fire postmessage handlers | ||
global.requestAnimationFrame = function(cb) { | ||
return setTimeout(() => { | ||
cb(Date.now()); | ||
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. the raf from jsdom passes in the timestamp. is this safe to remove? |
||
}); | ||
}; | ||
const originalAddEventListener = global.addEventListener; | ||
let postMessageCallback; | ||
global.addEventListener = function(eventName, callback, useCapture) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,3 +543,4 @@ describe 'ReactCoffeeScriptClass', -> | |
node = ReactDOM.findDOMNode(instance) | ||
expect(node).toBe container.firstChild | ||
undefined | ||
undefined | ||
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. same as the |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,11 @@ module.exports = { | |
collectCoverageFrom: ['packages/**/*.js'], | ||
timers: 'fake', | ||
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')], | ||
// Jest changed from `about:blank` to `http://localhost` default in 24.5 (https://github.com/facebook/jest/pull/6792) | ||
// in order to address https://github.com/facebook/jest/issues/6766. If one uses `about:blank` in JSDOM@11.12 or | ||
// newer, it fails with `SecurityError: localStorage is not available for opaque origins`. However, some of React's | ||
// tests depend on `about:blank` being the domain (for e.g. `url` in `img` tags). So we set `about:blank` here to | ||
// keep the current behavior and make sure to keep the version of JSDOM to version lower than 11.12. This will have | ||
// to be addressed properly when Jest 25 is released, as it will come with a newer version of JSDOM. | ||
testURL: 'about:blank', | ||
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. Note that doing this breaks in JSDOM@>=11.12 with For now, I've manually made sure the entry in the lockfile is ~11.11.0, which does not have this issue 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. Could you add a short TODO here? 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. Done! 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. ergh, expect it wasn't particularly short 😅 |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ module.exports = { | |
} | ||
: {} | ||
) | ||
).code; | ||
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. removing this ensures you return source maps to Jest, for better errors and debugging. |
||
); | ||
} | ||
return src; | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,6 @@ global.__PROFILE__ = NODE_ENV === 'development'; | |
global.__UMD__ = false; | ||
|
||
if (typeof window !== 'undefined') { | ||
global.requestAnimationFrame = function(callback) { | ||
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. jsdom comes with raf |
||
setTimeout(callback); | ||
}; | ||
|
||
global.requestIdleCallback = function(callback) { | ||
return setTimeout(() => { | ||
callback({ | ||
|
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.
describe
must bevoid
(in reality it must be synchronous) in Jest.async
here was always an error, but it throws with jest 24.https://jestjs.io/docs/en/troubleshooting#defining-tests