This repository has been archived on 2026-05-02. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
obsidian-plugin-auto-task-s.../test/mock_obsidian.ts
Felipe Martin 6c464483f5
Some checks are pending
CI / build (push) Waiting to run
Migrate dev environment to Bun with modern tooling
- 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)
2026-04-13 15:09:11 +02:00

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;
}