Skip to content

Conversation

@vojtechszocs
Copy link
Contributor

This PR ensures that

  • tests running through Jest / Enzyme
  • the plugin-stats script

have 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 like ReferenceError: Element is not defined.

Notable changes:

  • keep __mocks__/localStorage.ts since it's not easy to mock jsdom's web storage
  • keep __mocks__/matchMedia.js since it's not provided by jsdom
  • remove __mocks__/requestAnimationFrame.js since it's already provided by jsdom

/cc @spadgett @alecmerdler @rawagner @christianvogt

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 1, 2019
},
getItem(key) {
return _localStorage[key];
return _localStorage[key] || null;
Copy link
Contributor Author

@vojtechszocs vojtechszocs Jul 1, 2019

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, null is returned.

https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

#1925

.first()
.props().filter,
).toBe('url(blank#BaseNodeDropShadowFilterId)');
).toBe('url(/#BaseNodeDropShadowFilterId)');
Copy link
Contributor Author

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;
Copy link
Contributor Author

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).

Copy link
Contributor

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.

Copy link
Contributor Author

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)

Copy link
Contributor

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.

@vojtechszocs
Copy link
Contributor Author

vojtechszocs commented Jul 1, 2019

This also fixes problems like Console plugin entry module directly or indirectly referencing such web APIs and plugin-stats (ts-node) failing on errors like ReferenceError: Element is not defined.

To reproduce, just put following code in packages/dev-console/src/plugin.tsx (DevConsole plugin is enabled by default):

import { Icon } from 'patternfly-react';
const c = <Icon type="fa" name="address-book" />;

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rawagner, vojtechszocs
To complete the pull request process, please assign bparees
You can assign the PR to them by writing /assign @bparees in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@spadgett spadgett added this to the v4.2 milestone Jul 2, 2019
@openshift-merge-robot openshift-merge-robot merged commit 1aa7beb into openshift:master Jul 4, 2019
@logonoff logonoff deleted the use-jsdom branch September 25, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants