mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-28 10:20:08 +02:00
034191c78a
* use matchMedia * use last-of-type * better type check * simplify distanceFromTopWindow * use visibility * update JSDoc
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
/* eslint-disable no-param-reassign */
|
|
|
|
const { JSDOM } = require('jsdom');
|
|
|
|
const jsdom = new JSDOM(
|
|
'<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>',
|
|
{
|
|
pretendToBeVisual: true,
|
|
},
|
|
);
|
|
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;
|
|
}
|
|
|
|
extensions.forEach(ext => {
|
|
require.extensions[ext] = noop;
|
|
});
|
|
}
|
|
|
|
global.window = window;
|
|
global.document = window.document;
|
|
global.navigator = {
|
|
userAgent: 'node.js',
|
|
};
|
|
global.CustomEvent = window.CustomEvent;
|
|
global.Element = window.Element;
|
|
global.HTMLElement = window.HTMLElement;
|
|
global.Option = window.Option;
|
|
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;
|
|
|
|
copyProps(window, global);
|
|
|
|
ignoreExtensions(['.scss', '.css']);
|
|
ignoreExtensions(['.jpg', '.png', '.svg'], '');
|