fix: add window polyfill for tests (window.setTimeout compatibility)

This commit is contained in:
Viktar Mikalayeu 2026-05-12 23:57:08 +04:00
parent d9ce26a48d
commit 78c4969517
2 changed files with 25 additions and 0 deletions

24
tests/setup.ts Normal file
View file

@ -0,0 +1,24 @@
/**
* Test setup polyfill window for Obsidian plugin compatibility.
* Obsidian plugins use window.setTimeout/window.clearTimeout,
* but tests run in Node.js where window doesn't exist.
*/
if (typeof globalThis.window === 'undefined') {
// Create a proxy that always delegates to globalThis
// This ensures vi.useFakeTimers() works correctly
(globalThis as any).window = new Proxy(globalThis, {
get(target, prop) {
return (target as any)[prop];
}
});
}
if (typeof globalThis.activeDocument === 'undefined') {
(globalThis as any).activeDocument = {
querySelectorAll: () => [],
createElement: (tag: string) => ({ id: '', textContent: '', style: {} }),
head: { appendChild: () => {} },
getElementById: () => null,
};
}

View file

@ -5,6 +5,7 @@ export default defineConfig({
test: {
globals: true,
environment: "node",
setupFiles: ["tests/setup.ts"],
include: [
"tests/**/*.test.ts",
"tests/**/*.property.test.ts",