-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
I don't mean in regards to the React example as mentioned here: #773 but rather the way the environment is set up. Only window
, document
and navigator
are exposed globally by the helper which means any other global variables available in a browser environment will only be accessible through window
. This is fine for writing tests but lots of browser libs and their dependencies will expect everything to be global.
For example if one of the browser dependencies was doing something like: if(domNode instanceof HTMLDivElement)
then HTMLDivElement
would be undefined so you'd have to go in to the helper and add:
global.HTMLDivElement = window.HTMLDivElement;
This could quickly get out of hand. I'm using a simple module (lukechilds/node-browser-environment) that by default adds everything in window
to global
so everything just works. If you want to limit to certain properties you can pass an array of required properties.
So the helper would just be:
require('node-browser-environment')();
and you have everything on window available globally.
If you wanted to limit it to certain properties it'd be:
require('node-browser-environment')(['window', 'document', 'navigator']);
Would you accept a PR to use this instead? Seems like it would be more frictionless.