Skip to content
Snippets Groups Projects
Select Git revision
  • 3071be563197835a2aed1f3f7b9655312676d6d4
  • master default protected
  • v1.23.2
  • v1.23.1
  • v1.23.0
  • v1.22.0
  • v1.21.1
  • v1.21.0
  • v1.20.3
  • v1.20.2
  • v1.20.1
  • v1.20.0
  • v1.19.4
  • v1.19.3
  • v1.19.2
  • v1.19.1
  • v1.19.0
  • v1.18.2
  • v1.18.1
  • v1.18.0
  • v1.17.0
  • v1.16.1
22 results

errors.go

Blame
  • jsdom.mjs 2.45 KiB
    'use strict';
    
    import {extend} from "../../../application/source/data/extend.mjs";
    import {getGlobal} from "../../../application/source/types/global.mjs";
    
    export const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
    export const isNode = new Function("try {return this===global;}catch(e){return false;}");
    
    
    /**
     * this helper function creates the dom stack in the node environment
     *
     * @return {Promise<unknown>|Promise<void>}
     */
    function initJSDOM(options) {
        if (typeof window === "object" && window['DOMParser']) return Promise.resolve();
    
        const g = getGlobal();
    
        options = extend({}, {
            pretendToBeVisual: true,
            contentType: "text/html",
            includeNodeLocations: true,
            storageQuota: 10000000,
            runScripts: "dangerously",
            resources: "usable"
        }, options || {})
    
        return import("jsdom").then(({JSDOM}) => {
            const {window} = new JSDOM(`<html>
    <head>
    </head>
    <body>
    <div id="mocks"></div>
    </body>`, options);
    
            g['window'] = window;
    
            return new Promise(resolve =>
                window.addEventListener("load", () => {
    
                    [
                        'self',
                        'HTMLCollection',
                        'NodeList',
                        'ElementInternals',
                        'HTMLDocument',
                        'HTMLFormElement',
                        'HTMLInputElement',
                        'HTMLSelectElement',
                        'HTMLTextAreaElement',
                        'document',
                        'Document',
                        'Node',
                        'ShadowRoot',
                        'EventTarget',
                        'Event',
                        'CustomEvent',
                        'Element',
                        'HTMLElement',
                        'HTMLDivElement',
                        'customElements',
                        'DocumentFragment',
                        'DOMParser',
                        'KeyboardEvent',
                        'CSSStyleSheet',
                        'HTMLScriptElement',
                        'MutationObserver',
                        'HTMLTemplateElement',
                        'XMLSerializer',
                        'NodeFilter',
                        'navigator',
                        'InputEvent',
                        'Blob',
                        'CustomEvent'
                    ].forEach(key => {
                        g[key] = window[key]
                    });
    
                    resolve();
                })
            );
    
    
        });
    }
    
    export {initJSDOM}