aboutsummaryrefslogtreecommitdiff
path: root/test/fixtures/dom-test.js
diff options
context:
space:
mode:
authorCashew <52880648+Scrub1492@users.noreply.github.com>2024-01-14 10:51:00 +0700
committerGitHub <noreply@github.com>2024-01-14 03:51:00 +0000
commitdcb26a8ef5c62bf6acbf8130895c37f56e8a9d3f (patch)
tree6b25d1bebff154f9535f47b69ddc62263c7eeded /test/fixtures/dom-test.js
parent326c5335503d45daafe73daac88ae330c6bace77 (diff)
more test updates (#510)24.01.14.0
* test updates * remove duplicate * fix indentation * fix
Diffstat (limited to 'test/fixtures/dom-test.js')
-rw-r--r--test/fixtures/dom-test.js14
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}>}
*/