browser-env
browser-env copied to clipboard
TypeError: Cannot redefine property: Infinity
Setting the jsdom option of runScripts
with value of 'dangerously'
causes the following exception:
TypeError: Cannot redefine property: Infinity
Object.getOwnPropertyNames.filter.filter.forEach.prop (node_modules/browser-env/src/index.js:41:9)
browserEnv (node_modules/browser-env/src/index.js:40:6)
Object.browserEnv (test/browser-env.js:9:1)
Thanks for taking the time to report this but unfortunately I don't have time to look into this right now due to paid work.
PRs are very welcome.
Hi @lukechilds could you merge my last pull request?
If you don't have time, please assign write permissions to me.
I think this is simply due to a simple bug in the index.js:
// IIFE executed on import to return an array of global Node.js properties that
// conflict with global browser properties.
const protectedproperties = (() => Object
.getOwnPropertyNames(new Window(defaultJsdomConfig))
.filter(prop => typeof global[prop] !== 'undefined')
)();
This works with a window object only based on the default settings, but adding a user JSDOM-config changes the window properties, which is why "Infinity" is not included in the protected properties.
I guess this should rather read:
// IIFE executed on import to return an array of global Node.js properties that
// conflict with global browser properties.
const protectedproperties = (() => Object
.getOwnPropertyNames(new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig)))
.filter(prop => typeof global[prop] !== 'undefined')
)();
And in this case the const needs to be placed inside "browserEnv", below the declaration of "userJsdomConfig".
You could of course also switch to a parametrized function and call that in the filter.