|
@ -4,10 +4,10 @@ const Window = require('window'); |
|
|
// These settings must override any custom settings to make sure we can iterate
|
|
|
// These settings must override any custom settings to make sure we can iterate
|
|
|
// over the window object.
|
|
|
// over the window object.
|
|
|
const defaultJsdomConfig = { |
|
|
const defaultJsdomConfig = { |
|
|
features: { |
|
|
features: { |
|
|
FetchExternalResources: false, |
|
|
FetchExternalResources: false, |
|
|
ProcessExternalResources: false |
|
|
ProcessExternalResources: false |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 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
|
|
@ -18,18 +18,17 @@ const protectedproperties = (() => Object |
|
|
)(); |
|
|
)(); |
|
|
|
|
|
|
|
|
// Sets up global browser environment
|
|
|
// Sets up global browser environment
|
|
|
module.exports = function browserEnv() { |
|
|
const browserEnv = function () { |
|
|
|
|
|
|
|
|
// Extract options from args
|
|
|
// Extract options from args
|
|
|
const args = Array.from(arguments); |
|
|
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.indexOf(prop) === -1) |
|
@ -38,8 +37,12 @@ module.exports = function browserEnv() { |
|
|
.filter(prop => !(properties && properties.indexOf(prop) === -1)) |
|
|
.filter(prop => !(properties && properties.indexOf(prop) === -1)) |
|
|
|
|
|
|
|
|
// Copy what's left to the Node.js global scope
|
|
|
// Copy what's left to the Node.js global scope
|
|
|
.forEach(prop => global[prop] = window[prop]); |
|
|
.forEach(prop => { |
|
|
|
|
|
global[prop] = window[prop]; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// Return reference to original window object
|
|
|
// Return reference to original window object
|
|
|
return window; |
|
|
return window; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = browserEnv; |
|
|