mirror of
https://github.com/viktoruj/obsidian-cloud-kms.git
synced 2026-07-22 06:56:21 +00:00
fix: add window polyfill for tests (window.setTimeout compatibility)
This commit is contained in:
parent
d9ce26a48d
commit
78c4969517
2 changed files with 25 additions and 0 deletions
24
tests/setup.ts
Normal file
24
tests/setup.ts
Normal 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,
|
||||
};
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ export default defineConfig({
|
|||
test: {
|
||||
globals: true,
|
||||
environment: "node",
|
||||
setupFiles: ["tests/setup.ts"],
|
||||
include: [
|
||||
"tests/**/*.test.ts",
|
||||
"tests/**/*.property.test.ts",
|
||||
|
|
|
|||
Loading…
Reference in a new issue