-
Notifications
You must be signed in to change notification settings - Fork 667
Use jsdom env. for testing and plugin-stats #1871
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
Conversation
| }, | ||
| getItem(key) { | ||
| return _localStorage[key]; | ||
| return _localStorage[key] || null; |
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.
Note: these changes are made so that mock localStorage is as close to production as possible in terms of its API.
For example, in case of getItem method:
If the key does not exist,
nullis returned.
https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem
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.
You should only return null if the key doesn't exist. If the value is an empty string, this will incorrectly return null.
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.
You should only return null if the key doesn't exist. If the value is an empty string, this will incorrectly return
null.
Right, I've missed that. Will fix that in a separate PR.
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.
Will fix that in a separate PR.
| .first() | ||
| .props().filter, | ||
| ).toBe('url(blank#BaseNodeDropShadowFilterId)'); | ||
| ).toBe('url(/#BaseNodeDropShadowFilterId)'); |
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.
These changes are due to setting testURL value above.
| } | ||
| } | ||
| return activePerspective; | ||
| return activePerspective || undefined; |
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.
This is to coerce the expectation (undefined means no perspective) vs. underlying storage implementation (null means no such item in storage).
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.
Is something breaking without this?
I'd rather not distinguish between null and undefined here.
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.
Is something breaking without this?
I'd rather not distinguish between null and undefined here.
Without this, __tests__/reducers/ui.spec.ts fails on
expect(getDefaultPerspective()).toBeUndefined();(expected undefined but received null)
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.
A bad test. null and undefined should be equivalent for this assertion.
To reproduce, just put following code in import { Icon } from 'patternfly-react';
const c = <Icon type="fa" name="address-book" />; |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: rawagner, vojtechszocs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This PR ensures that
plugin-statsscripthave access to relevant web APIs (notably DOM and HTML) provided via jsdom implementation.
This also fixes problems like Console plugin entry module directly or indirectly referencing such web APIs and
plugin-stats(ts-node) failing on errors likeReferenceError: Element is not defined.Notable changes:
__mocks__/localStorage.tssince it's not easy to mock jsdom's web storage__mocks__/matchMedia.jssince it's not provided by jsdom__mocks__/requestAnimationFrame.jssince it's already provided by jsdom/cc @spadgett @alecmerdler @rawagner @christianvogt