Skip to content
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

Conditionally require hammer.js #658

Merged
merged 2 commits into from
May 24, 2017
Merged

Conditionally require hammer.js #658

merged 2 commits into from
May 24, 2017

Conversation

ericsoco
Copy link
Contributor

Conditionally require hammer.js to avoid failure on server, on window and document references.

I'm not happy with this solution, but hammerjs/hammer.js#930 suggests there isn't much of a better option for now :/

@howtimeflies0
Copy link

We have a isBrowser test in src/controllers/globals.js, should we use that?


import {
const Manager = (typeof window === 'undefined' || typeof document === 'undefined') ?
ManagerMock : require('hammerjs').Manager;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't need that as well. We could just Manager set to null and have a if check when Manager object is created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock should be there so that future consumers of EventManager can call its public API without fear of failure in some environments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the isBrowser test, and src/controllers generally, that folder should be cleaned up to bring it more in-line with react-map-gl...and the globals.js file there seems to be a near-duplicate of src/utils/globals.js...thoughts on this @ibgreen @shaojingli?

For now, I can use that isBrowser.

@@ -149,3 +151,13 @@ export default class EventManager {
return event => this.manager.emit(eventAlias, event);
}
}

function ManagerMock(m) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScripts "hoisting" of function names (allowing them to be used before declaration) is a mixed blessing.

I'd move this up top, so that we can see how the mocking is done in one place.


import {
const Manager = (typeof window === 'undefined' || typeof document === 'undefined') ?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a function in utils that is intended to do a safe check for whether we are running under node.js (a check that is not fooled e.g. by jsdom inclusion). Consider using that?

Also, add a short comment?

@howtimeflies0 howtimeflies0 force-pushed the event-manager-hotfix branch from 7d575a3 to ba70cd9 Compare May 24, 2017 17:24
Manually hoist ManagerMock ;)
@ericsoco ericsoco merged commit 398f04c into master May 24, 2017
Firenze11 pushed a commit to Firenze11/deck.gl that referenced this pull request May 31, 2017
* Conditionally require hammer.js to avoid failure on server, on `window` and `document` references.

* Use `isBrowser` for conditional requires
Manually hoist ManagerMock ;)
@balthazar balthazar deleted the event-manager-hotfix branch June 15, 2017 19:29
wimrijnders added a commit to wimrijnders/vis that referenced this pull request Jul 29, 2017
Adds mocks for certain components, in order to let module `Network` be run in unit tests.

Changes:

- Create a mock object for `hammer.js` when running browserless. The inspiration is taken from [here](visgl/deck.gl#658)
- Create a mock function for `window.requestAnimationFrame()` when running browserless in `network/modules/CanvasRenderer.js`
- Added unit test for `Network` to show that unit testing for it now works
- Fixed naming of container in `test/Graph3d.test.js`

Since `hammer.js` is also used in other modules, this fix is potentially an enabler for full-module unit tests for those as well.
yotamberk pushed a commit to almende/vis that referenced this pull request Aug 8, 2017
* First working version of updating clustered edge

* Added fix for #1315 as well

* Enable unit testing for module Network

Adds mocks for certain components, in order to let module `Network` be run in unit tests.

Changes:

- Create a mock object for `hammer.js` when running browserless. The inspiration is taken from [here](visgl/deck.gl#658)
- Create a mock function for `window.requestAnimationFrame()` when running browserless in `network/modules/CanvasRenderer.js`
- Added unit test for `Network` to show that unit testing for it now works
- Fixed naming of container in `test/Graph3d.test.js`

Since `hammer.js` is also used in other modules, this fix is potentially an enabler for full-module unit tests for those as well.

* Cleanup unit test Network

* Added unit test for fix issue #1218

* Adding test for #1315 - Interim save

* Completed unit test and fixes for #1315

* Added fixes for #1291

* Added unit test for #1219

* Added header comment for Clustering.js, small fixes

* Fix for unit test

* Added example networks to unit test

* Fix error in loading disassemblerExample

* Network unit test final fixes

* Fixes for linting

* Fixed essential typo

* Fixed linting error

* Fixed unit test

* Fixed unit test again
yotamberk pushed a commit to almende/vis that referenced this pull request Aug 16, 2017
* Enable unit testing for module Network

Adds mocks for certain components, in order to let module `Network` be run in unit tests.

Changes:

- Create a mock object for `hammer.js` when running browserless. The inspiration is taken from [here](visgl/deck.gl#658)
- Create a mock function for `window.requestAnimationFrame()` when running browserless in `network/modules/CanvasRenderer.js`
- Added unit test for `Network` to show that unit testing for it now works
- Fixed naming of container in `test/Graph3d.test.js`

Since `hammer.js` is also used in other modules, this fix is potentially an enabler for full-module unit tests for those as well.

* Cleanup unit test Network

* Fix for unit test

* Added example networks to unit test

* Fix error in loading disassemblerExample

* Network unit test final fixes

* Adjusted comments
primozs pushed a commit to primozs/vis that referenced this pull request Jan 3, 2019
)

* First working version of updating clustered edge

* Added fix for almende#1315 as well

* Enable unit testing for module Network

Adds mocks for certain components, in order to let module `Network` be run in unit tests.

Changes:

- Create a mock object for `hammer.js` when running browserless. The inspiration is taken from [here](visgl/deck.gl#658)
- Create a mock function for `window.requestAnimationFrame()` when running browserless in `network/modules/CanvasRenderer.js`
- Added unit test for `Network` to show that unit testing for it now works
- Fixed naming of container in `test/Graph3d.test.js`

Since `hammer.js` is also used in other modules, this fix is potentially an enabler for full-module unit tests for those as well.

* Cleanup unit test Network

* Added unit test for fix issue almende#1218

* Adding test for almende#1315 - Interim save

* Completed unit test and fixes for almende#1315

* Added fixes for almende#1291

* Added unit test for almende#1219

* Added header comment for Clustering.js, small fixes

* Fix for unit test

* Added example networks to unit test

* Fix error in loading disassemblerExample

* Network unit test final fixes

* Fixes for linting

* Fixed essential typo

* Fixed linting error

* Fixed unit test

* Fixed unit test again
primozs pushed a commit to primozs/vis that referenced this pull request Jan 3, 2019
* Enable unit testing for module Network

Adds mocks for certain components, in order to let module `Network` be run in unit tests.

Changes:

- Create a mock object for `hammer.js` when running browserless. The inspiration is taken from [here](visgl/deck.gl#658)
- Create a mock function for `window.requestAnimationFrame()` when running browserless in `network/modules/CanvasRenderer.js`
- Added unit test for `Network` to show that unit testing for it now works
- Fixed naming of container in `test/Graph3d.test.js`

Since `hammer.js` is also used in other modules, this fix is potentially an enabler for full-module unit tests for those as well.

* Cleanup unit test Network

* Fix for unit test

* Added example networks to unit test

* Fix error in loading disassemblerExample

* Network unit test final fixes

* Adjusted comments
mojoaxel pushed a commit to visjs/vis-charts that referenced this pull request Jul 12, 2019
* First working version of updating clustered edge

* Added fix for #1315 as well

* Enable unit testing for module Network

Adds mocks for certain components, in order to let module `Network` be run in unit tests.

Changes:

- Create a mock object for `hammer.js` when running browserless. The inspiration is taken from [here](visgl/deck.gl#658)
- Create a mock function for `window.requestAnimationFrame()` when running browserless in `network/modules/CanvasRenderer.js`
- Added unit test for `Network` to show that unit testing for it now works
- Fixed naming of container in `test/Graph3d.test.js`

Since `hammer.js` is also used in other modules, this fix is potentially an enabler for full-module unit tests for those as well.

* Cleanup unit test Network

* Added unit test for fix issue #1218

* Adding test for #1315 - Interim save

* Completed unit test and fixes for #1315

* Added fixes for #1291

* Added unit test for #1219

* Added header comment for Clustering.js, small fixes

* Fix for unit test

* Added example networks to unit test

* Fix error in loading disassemblerExample

* Network unit test final fixes

* Fixes for linting

* Fixed essential typo

* Fixed linting error

* Fixed unit test

* Fixed unit test again
mojoaxel pushed a commit to visjs/vis-charts that referenced this pull request Jul 12, 2019
* Enable unit testing for module Network

Adds mocks for certain components, in order to let module `Network` be run in unit tests.

Changes:

- Create a mock object for `hammer.js` when running browserless. The inspiration is taken from [here](visgl/deck.gl#658)
- Create a mock function for `window.requestAnimationFrame()` when running browserless in `network/modules/CanvasRenderer.js`
- Added unit test for `Network` to show that unit testing for it now works
- Fixed naming of container in `test/Graph3d.test.js`

Since `hammer.js` is also used in other modules, this fix is potentially an enabler for full-module unit tests for those as well.

* Cleanup unit test Network

* Fix for unit test

* Added example networks to unit test

* Fix error in loading disassemblerExample

* Network unit test final fixes

* Adjusted comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants