Choices/config/jsdom.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-param-reassign */
2017-07-24 16:18:43 +02:00
const { JSDOM } = require('jsdom');
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;
global.Option = window.Option;
2017-12-20 13:38:16 +01:00
global.HTMLOptionElement = window.HTMLOptionElement;
global.HTMLOptGroupElement = window.HTMLOptGroupElement;
global.HTMLSelectElement = window.HTMLSelectElement;
global.HTMLInputElement = window.HTMLInputElement;
global.DocumentFragment = window.DocumentFragment;
global.requestAnimationFrame = window.requestAnimationFrame;
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'], '');