Some checks are pending
CI / build (push) Waiting to run
- Switch package manager from npm to Bun (bun.lock replaces package-lock.json) - Move source to src/main.ts, tests to test/ (flattened structure) - Build output now goes to dist/ with git-based version stamping in manifest - Replace ESLint legacy config with ESLint v9 flat config (typescript-eslint v8) - Add Prettier for formatting (.prettierrc) - Add Husky pre-commit hook running bun run lint - Add vault management scripts (install, uninstall, symlink, unlink) - Add GitHub Actions CI and release workflows - Update tsconfig for TypeScript v5, add isolatedModules/esModuleInterop - Upgrade Jest config to jsdom environment, coverage from src/** - Remove Makefile, version-bump.mjs, versions.json (replaced by bun scripts and git-tag versioning)
103 lines
2.4 KiB
TypeScript
103 lines
2.4 KiB
TypeScript
// Mock implementations for Obsidian API
|
|
export class MockedFunction extends Function {
|
|
mockResolvedValue = jest.fn().mockReturnThis();
|
|
mockRejectedValue = jest.fn().mockReturnThis();
|
|
mockReturnValue = jest.fn().mockReturnThis();
|
|
mockImplementation = jest.fn().mockReturnThis();
|
|
}
|
|
|
|
export class App {
|
|
vault = {
|
|
read: jest.fn().mockResolvedValue(''),
|
|
getMarkdownFiles: jest.fn().mockReturnValue([]),
|
|
on: jest.fn(),
|
|
};
|
|
|
|
workspace = {
|
|
on: jest.fn(),
|
|
getActiveFile: jest.fn(),
|
|
};
|
|
|
|
fileManager = {
|
|
processFrontMatter: jest.fn().mockResolvedValue(undefined),
|
|
};
|
|
|
|
keymap: any = {};
|
|
scope: any = {};
|
|
metadataCache: any = {};
|
|
lastEvent: any = null;
|
|
loadLocalStorage = jest.fn().mockReturnValue('{}');
|
|
saveLocalStorage = jest.fn();
|
|
}
|
|
|
|
export class Plugin {
|
|
app: App;
|
|
settings: any;
|
|
|
|
constructor(app: App, manifest: any) {
|
|
this.app = app;
|
|
}
|
|
|
|
loadData = jest.fn().mockResolvedValue({});
|
|
saveData = jest.fn().mockResolvedValue(undefined);
|
|
addCommand = jest.fn();
|
|
addSettingTab = jest.fn();
|
|
registerEvent = jest.fn();
|
|
}
|
|
|
|
export class PluginSettingTab {
|
|
app: App;
|
|
plugin: Plugin;
|
|
containerEl = {
|
|
empty: jest.fn(),
|
|
createEl: jest.fn().mockReturnValue({
|
|
createEl: jest.fn(),
|
|
}),
|
|
};
|
|
|
|
constructor(app: App, plugin: Plugin) {
|
|
this.app = app;
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
display = jest.fn();
|
|
}
|
|
|
|
export class Setting {
|
|
constructor(containerEl: any) {}
|
|
|
|
setName = jest.fn().mockReturnThis();
|
|
setDesc = jest.fn().mockReturnThis();
|
|
addText = jest.fn().mockReturnThis();
|
|
addToggle = jest.fn().mockReturnThis();
|
|
addTextArea = jest.fn().mockReturnThis();
|
|
addButton = jest.fn().mockReturnThis();
|
|
}
|
|
|
|
export class TFile {
|
|
path: string;
|
|
parent: any;
|
|
stat: any = { ctime: 0, mtime: 0, size: 0 };
|
|
basename: string;
|
|
extension: string;
|
|
vault: any = {};
|
|
name: string;
|
|
|
|
constructor(path: string = '', parent: any = null) {
|
|
this.path = path;
|
|
this.parent = parent;
|
|
this.name = path.split('/').pop() || '';
|
|
this.basename = this.name.replace(/\.[^/.]+$/, '');
|
|
this.extension = path.includes('.') ? path.split('.').pop() || '' : '';
|
|
}
|
|
}
|
|
|
|
export class Notice {
|
|
constructor(message: string) {}
|
|
hide = jest.fn();
|
|
}
|
|
|
|
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number, immediate?: boolean): T {
|
|
const mockFn = jest.fn(func) as any;
|
|
return mockFn;
|
|
}
|