MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / MockVaultFileSystem

Class MockVaultFileSystem

tests/__mocks__/obsidian.ts:40–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39// Global mock file system state
40class MockVaultFileSystem {
41 private files = new Map<string, MockFile>();
42 private folders = new Map<string, MockFolder>();
43 private emitter = new EventEmitter();
44
45 constructor() {
46 // Initialize with root folder
47 this.folders.set('', {
48 path: '',
49 name: '',
50 children: new Map(),
51 });
52 }
53
54 // File operations
55 create(path: string, content: string): MockFile {
56 const normalizedPath = this.normalizePath(path);
57
58 if (this.files.has(normalizedPath)) {
59 throw new Error(`File already exists: ${normalizedPath}`);
60 }
61
62 this.ensureFolderExists(this.getParentPath(normalizedPath));
63
64 const file: MockFile = {
65 path: normalizedPath,
66 name: this.getFileName(normalizedPath),
67 basename: this.getBaseName(normalizedPath),
68 extension: this.getExtension(normalizedPath),
69 content,
70 stat: {
71 ctime: Date.now(),
72 mtime: Date.now(),
73 size: content.length,
74 },
75 };
76
77 this.files.set(normalizedPath, file);
78 this.emitter.emit('create', file);
79 return file;
80 }
81
82 modify(file: MockFile, content: string): void {
83 file.content = content;
84 file.stat.mtime = Date.now();
85 file.stat.size = content.length;
86 this.emitter.emit('modify', file);
87 }
88
89 delete(path: string): void {
90 const normalizedPath = this.normalizePath(path);
91 const file = this.files.get(normalizedPath);
92 if (file) {
93 this.files.delete(normalizedPath);
94 this.emitter.emit('delete', file);
95 }
96 }
97

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected