mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Update test mocks to use renamed methods: readFile → readFilePath, writeFile → writeToFilePath, patchFile → patchFileAtPath. Add activeWindow and activeDocument globals to test setup for Obsidian compatibility.
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
/**
|
|
* Test setup file - runs before all tests
|
|
*/
|
|
|
|
import { afterEach, vi } from 'vitest';
|
|
|
|
// Mock global window if needed
|
|
if (typeof global.window === 'undefined') {
|
|
global.window = {} as any;
|
|
}
|
|
|
|
// Obsidian global aliases used in source code
|
|
if (typeof (global as any).activeWindow === 'undefined') {
|
|
(global as any).activeWindow = {
|
|
setTimeout: globalThis.setTimeout.bind(globalThis),
|
|
clearTimeout: globalThis.clearTimeout.bind(globalThis),
|
|
getSelection: () => (typeof document !== 'undefined' ? document.getSelection() : null),
|
|
window: typeof window !== 'undefined' ? window : global.window,
|
|
document: typeof document !== 'undefined' ? document : undefined,
|
|
};
|
|
}
|
|
if (typeof (global as any).activeDocument === 'undefined') {
|
|
(global as any).activeDocument = typeof document !== 'undefined' ? document : undefined;
|
|
}
|
|
|
|
// Note: Component class is now defined in __mocks__/obsidian.ts
|
|
// The vitest alias in vitest.config.ts handles mocking 'obsidian' imports
|
|
|
|
// Add Obsidian's .empty() method to HTMLElement prototype for testing
|
|
if (typeof HTMLElement !== 'undefined') {
|
|
HTMLElement.prototype.empty = function() {
|
|
while (this.firstChild) {
|
|
this.removeChild(this.firstChild);
|
|
}
|
|
};
|
|
}
|
|
|
|
// Clean up after each test
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|