@rstest/core
Version:
The Rsbuild-based test tool.
37 lines (36 loc) • 1.5 kB
JavaScript
import 'module';
/*#__PURE__*/ import.meta.url;
import { checkPkgInstalled } from "./1294.js";
import { installGlobal, addDefaultErrorHandler } from "./0~3062.js";
const environment = {
name: 'jsdom',
setup: async (global, options)=>{
checkPkgInstalled('jsdom');
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import("jsdom");
const { html = '<!DOCTYPE html>', userAgent, url = 'http://localhost:3000', contentType = 'text/html', pretendToBeVisual = true, includeNodeLocations = false, runScripts = 'dangerously', resources, console = false, cookieJar = false, ...restOptions } = options;
const dom = new JSDOM(html, {
pretendToBeVisual,
resources: resources ?? (userAgent ? new ResourceLoader({
userAgent
}) : void 0),
runScripts,
url,
virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
cookieJar: cookieJar ? new CookieJar() : void 0,
includeNodeLocations,
contentType,
userAgent,
...restOptions
});
const cleanupGlobal = installGlobal(global, dom.window);
const cleanupHandler = addDefaultErrorHandler(global);
return {
teardown () {
cleanupHandler();
dom.window.close();
cleanupGlobal();
}
};
}
};
export { environment };