-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
…w` and `document` references.
We have a |
src/utils/events/event-manager.js
Outdated
|
||
import { | ||
const Manager = (typeof window === 'undefined' || typeof document === 'undefined') ? | ||
ManagerMock : require('hammerjs').Manager; |
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.
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.
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.
The mock should be there so that future consumers of EventManager can call its public API without fear of failure in some environments.
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.
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
.
src/utils/events/event-manager.js
Outdated
@@ -149,3 +151,13 @@ export default class EventManager { | |||
return event => this.manager.emit(eventAlias, event); | |||
} | |||
} | |||
|
|||
function ManagerMock(m) { |
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.
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.
src/utils/events/event-manager.js
Outdated
|
||
import { | ||
const Manager = (typeof window === 'undefined' || typeof document === '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.
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?
7d575a3
to
ba70cd9
Compare
Manually hoist ManagerMock ;)
* Conditionally require hammer.js to avoid failure on server, on `window` and `document` references. * Use `isBrowser` for conditional requires Manually hoist ManagerMock ;)
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.
* 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
* 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
) * 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
* 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
* 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
* 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
Conditionally require hammer.js to avoid failure on server, on
window
anddocument
references.I'm not happy with this solution, but hammerjs/hammer.js#930 suggests there isn't much of a better option for now :/