histoire
Version:
A fast story book powered by Vite
29 lines (28 loc) • 969 B
JavaScript
import { JSDOM, VirtualConsole, } from 'jsdom';
import { populateGlobal } from './util.js';
export function createDomEnv() {
const dom = new JSDOM('<!DOCTYPE html>', {
pretendToBeVisual: true,
runScripts: 'dangerously',
url: 'http://localhost:3000',
virtualConsole: console && globalThis.console ? new VirtualConsole().sendTo(globalThis.console) : undefined,
includeNodeLocations: false,
contentType: 'text/html',
});
const { keys, originals } = populateGlobal(globalThis, dom.window, { bindFunctions: true });
function destroy() {
keys.forEach(key => delete globalThis[key]);
originals.forEach((v, k) => {
globalThis[k] = v;
});
}
window.ResizeObserver = window.ResizeObserver || class ResizeObserver {
disconnect() { }
observe(_target, _options) { }
unobserve(_target) { }
};
return {
window,
destroy,
};
}