feat: add vitest, vite, move to tdd
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { IFileSystem } from "@/ports";
|
||||
|
||||
export class InMemoryFileSystem implements IFileSystem {
|
||||
private files = new Map<string, string>();
|
||||
|
||||
reset(): void {
|
||||
this.files.clear();
|
||||
}
|
||||
|
||||
async readFile(path: string): Promise<string> {
|
||||
const content = this.files.get(path);
|
||||
if (content === undefined) {
|
||||
throw new Error(`ENOENT: no such file: ${path}`);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
async writeFile(path: string, content: string): Promise<void> {
|
||||
this.files.set(path, content);
|
||||
}
|
||||
|
||||
async deleteFile(path: string): Promise<void> {
|
||||
this.files.delete(path);
|
||||
}
|
||||
|
||||
async readdir(path: string): Promise<string[]> {
|
||||
const prefix = path.endsWith("/") || path.endsWith("\\") ? path : path + "/";
|
||||
const seen = new Set<string>();
|
||||
for (const key of this.files.keys()) {
|
||||
if (key.startsWith(prefix)) {
|
||||
const relative = key.slice(prefix.length);
|
||||
const top = relative.split(/[/\\]/)[0];
|
||||
if (top) seen.add(top);
|
||||
}
|
||||
}
|
||||
return [...seen];
|
||||
}
|
||||
|
||||
async mkdir(_path: string): Promise<void> {
|
||||
// no-op for in-memory
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user