MCPcopy
hub / github.com/freshframework/fresh / createFakeFs

Function createFakeFs

packages/fresh/src/test_utils.ts:103–136  ·  view source on GitHub ↗
(files: Record<string, unknown>)

Source from the content-addressed store, hash-verified

101}
102
103export function createFakeFs(files: Record<string, unknown>): FsAdapter {
104 return {
105 cwd: () => ".",
106 async *walk(_root, options) {
107 const skip = options?.skip ?? [];
108 for (const file of Object.keys(files)) {
109 // Check if file matches any skip pattern
110 if (skip.some((pattern) => pattern.test(file))) {
111 continue;
112 }
113
114 const entry: WalkEntry = {
115 isDirectory: false,
116 isFile: true,
117 isSymlink: false,
118 name: file,
119 path: file,
120 };
121 yield entry;
122 }
123 },
124 // deno-lint-ignore require-await
125 async isDirectory(dir) {
126 return Object.keys(files).some((file) => file.startsWith(dir + "/"));
127 },
128 async mkdirp(_dir: string) {
129 },
130 readFile: Deno.readFile,
131 // deno-lint-ignore require-await
132 async readTextFile(path) {
133 return String(files[String(path)]);
134 },
135 };
136}
137
138export const delay = (ms: number) => new Promise((r) => setTimeout(r, ms));
139

Callers 4

createServerFunction · 0.90
fs_routes_test.tsxFile · 0.90
fs_crawl_test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected