jsdom-context-require
Version:
Allows you to require files in a jsdom window context.
25 lines (24 loc) • 1.13 kB
TypeScript
/// <reference types="node" />
import { type ConstructorOptions, type DOMWindow, JSDOM } from "jsdom";
import { type Types as ContextRequire } from "context-require";
export interface Browser extends JSDOM {
require: ContextRequire.RequireFunction;
window: DOMWindow & Global;
yield(): Promise<void>;
act<T = unknown>(fn?: () => T): Promise<Awaited<T>>;
}
export interface Options extends Omit<ConstructorOptions, "dir" | "html" | "extensions" | "beforeParse"> {
/** The directory from which to resolve requires for this module. */
dir: string;
/** The initial html to parse with jsdom. */
html?: string;
/** An object containing any browser specific require hooks to be used in this module. */
extensions?: ContextRequire.Hooks;
/** A function called with the window, and the module, before parsing html. */
beforeParse?(window: DOMWindow, browser: Browser): void;
}
/**
* Creates a custom Module object which runs all required scripts
* in a new jsdom instance.
*/
export declare function createBrowser({ dir, html, extensions, beforeParse, ...jsdomOptions }: Options): Browser;