diff options
Diffstat (limited to 'test/fixtures')
-rw-r--r-- | test/fixtures/dom-test.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/fixtures/dom-test.js b/test/fixtures/dom-test.js index 8cfe80a9..e0e7d647 100644 --- a/test/fixtures/dom-test.js +++ b/test/fixtures/dom-test.js @@ -36,6 +36,20 @@ function prepareWindow(window) { } /** + * + * @param {string} [htmlFilePath] + * @returns {Promise<{window: import('jsdom').DOMWindow; teardown: (global: unknown) => import('vitest').Awaitable<void>}>} + */ +export async function setupDomTest(htmlFilePath) { + const html = typeof htmlFilePath === 'string' ? fs.readFileSync(htmlFilePath, {encoding: 'utf8'}) : '<!DOCTYPE html>'; + const env = builtinEnvironments.jsdom; + const {teardown} = await env.setup(global, {jsdom: {html}}); + const window = /** @type {import('jsdom').DOMWindow} */ (/** @type {unknown} */ (global.window)); + prepareWindow(window); + return {window, teardown}; +} + +/** * @param {string} [htmlFilePath] * @returns {import('vitest').TestAPI<{window: import('jsdom').DOMWindow}>} */ |