2019-10-29 22:19:56 +01:00
|
|
|
/* eslint-disable no-param-reassign */
|
|
|
|
|
2017-07-24 16:18:43 +02:00
|
|
|
const { JSDOM } = require('jsdom');
|
|
|
|
|
2019-10-27 21:18:59 +01:00
|
|
|
const jsdom = new JSDOM(
|
|
|
|
'<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>',
|
|
|
|
{
|
|
|
|
pretendToBeVisual: true,
|
|
|
|
},
|
|
|
|
);
|
2017-07-24 16:18:43 +02:00
|
|
|
const { window } = jsdom;
|
|
|
|
|
|
|
|
function copyProps(src, target) {
|
|
|
|
const props = Object.getOwnPropertyNames(src)
|
|
|
|
.filter(prop => typeof target[prop] === 'undefined')
|
|
|
|
.map(prop => Object.getOwnPropertyDescriptor(src, prop));
|
|
|
|
Object.defineProperties(target, props);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ignoreExtensions(extensions = [], returnValue = {}) {
|
|
|
|
function noop() {
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
2018-05-28 18:56:36 +02:00
|
|
|
extensions.forEach(ext => {
|
2017-07-24 16:18:43 +02:00
|
|
|
require.extensions[ext] = noop;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
global.window = window;
|
|
|
|
global.document = window.document;
|
|
|
|
global.navigator = {
|
2017-09-29 14:26:47 +02:00
|
|
|
userAgent: 'node.js',
|
2017-07-24 16:18:43 +02:00
|
|
|
};
|
2017-12-20 13:38:16 +01:00
|
|
|
global.CustomEvent = window.CustomEvent;
|
2018-05-28 18:56:36 +02:00
|
|
|
global.Element = window.Element;
|
2017-07-24 16:18:43 +02:00
|
|
|
global.HTMLElement = window.HTMLElement;
|
2019-10-25 16:43:28 +02:00
|
|
|
global.Option = window.Option;
|
2017-12-20 13:38:16 +01:00
|
|
|
global.HTMLOptionElement = window.HTMLOptionElement;
|
2017-12-20 16:10:01 +01:00
|
|
|
global.HTMLOptGroupElement = window.HTMLOptGroupElement;
|
2019-10-29 22:19:56 +01:00
|
|
|
global.HTMLSelectElement = window.HTMLSelectElement;
|
|
|
|
global.HTMLInputElement = window.HTMLInputElement;
|
2017-12-20 16:10:01 +01:00
|
|
|
global.DocumentFragment = window.DocumentFragment;
|
2019-10-27 21:18:59 +01:00
|
|
|
global.requestAnimationFrame = window.requestAnimationFrame;
|
2019-10-30 18:28:15 +01:00
|
|
|
window.matchMedia = () => true;
|
2017-07-24 16:18:43 +02:00
|
|
|
|
|
|
|
copyProps(window, global);
|
2017-09-29 14:26:47 +02:00
|
|
|
|
2017-07-24 16:18:43 +02:00
|
|
|
ignoreExtensions(['.scss', '.css']);
|
|
|
|
ignoreExtensions(['.jpg', '.png', '.svg'], '');
|