Browse Source

Fix linting warnings.

pull/73/head
Guillaume Martigny 6 years ago
parent
commit
1f5c9cf901
  1. 23
      src/index.js

23
src/index.js

@ -13,28 +13,27 @@ const defaultJsdomConfig = {
// IIFE executed on import to return an array of global Node.js properties that // IIFE executed on import to return an array of global Node.js properties that
// conflict with global browser properties. // conflict with global browser properties.
const protectedproperties = (() => Object const protectedproperties = (() => Object
.getOwnPropertyNames(new Window(defaultJsdomConfig)) .getOwnPropertyNames(new Window(defaultJsdomConfig))
.filter(prop => typeof global[prop] !== 'undefined') .filter(prop => typeof global[prop] !== 'undefined')
)(); )();
// Sets up global browser environment // Sets up global browser environment
const browserEnv = function () { const browserEnv = function (...args) {
// Extract options from args // Extract options from args
const args = Array.from(arguments);
const properties = args.filter(arg => Array.isArray(arg))[0]; const properties = args.filter(arg => Array.isArray(arg))[0];
const userJsdomConfig = args.filter(arg => !Array.isArray(arg))[0]; const userJsdomConfig = args.filter(arg => !Array.isArray(arg))[0];
// Create window object // Create window object
const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig)); const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));
// Get all global browser properties // Get all global browser properties
Object.getOwnPropertyNames(window) Object.getOwnPropertyNames(window)
// Remove protected properties // Remove protected properties
.filter(prop => protectedproperties.indexOf(prop) === -1) .filter(prop => !protectedproperties.includes(prop))
// If we're only applying specific required properties remove everything else // If we're only applying specific required properties remove everything else
.filter(prop => !(properties && properties.indexOf(prop) === -1)) .filter(prop => !properties || properties.includes(prop))
// Copy what's left to the Node.js global scope // Copy what's left to the Node.js global scope
.forEach(prop => { .forEach(prop => {
@ -44,7 +43,7 @@ const browserEnv = function () {
}); });
}); });
// Return reference to original window object // Return reference to original window object
return window; return window;
}; };

Loading…
Cancel
Save