MCPcopy Create free account
hub / github.com/chhoumann/quickadd / createFakeApp

Function createFakeApp

src/services/packageImportService.test.ts:61–106  ·  view source on GitHub ↗
(initialExisting: string[] = [])

Source from the content-addressed store, hash-verified

59}
60
61function createFakeApp(initialExisting: string[] = []): {
62 app: App;
63 state: FakeVaultState;
64 adapter: { exists: ReturnType<typeof vi.fn> };
65} {
66 const state: FakeVaultState = {
67 existingPaths: new Set(initialExisting),
68 writes: new Map(),
69 createdFolders: [],
70 };
71
72 const adapter = {
73 exists: vi.fn(async (path: string) => {
74 if (state.existThrowsFor?.has(path)) {
75 throw new Error(`boom: ${path}`);
76 }
77 return state.existingPaths.has(path);
78 }),
79 read: vi.fn(async (path: string) => {
80 const content = state.writes.get(path);
81 if (content === undefined) {
82 throw new Error(`no file at ${path}`);
83 }
84 return content;
85 }),
86 write: vi.fn(async (path: string, content: string) => {
87 state.writes.set(path, content);
88 state.existingPaths.add(path);
89 }),
90 };
91
92 const app = {
93 vault: {
94 adapter,
95 // isVaultCaseInsensitive probes a case-swapped variant of configDir;
96 // seed ".OBSIDIAN" into existing paths to simulate a case-insensitive vault.
97 configDir: ".obsidian",
98 createFolder: vi.fn(async (path: string) => {
99 state.createdFolders.push(path);
100 state.existingPaths.add(path);
101 }),
102 },
103 } as unknown as App;
104
105 return { app, state, adapter };
106}
107
108// --- Fixture builders -------------------------------------------------------
109

Callers 1

Calls 5

fnMethod · 0.80
addMethod · 0.80
pushMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected