(
files: Record<string, string> = {},
options: { failOnWrite?: string } = {},
)
| 9 | }; |
| 10 | |
| 11 | function createMockFs( |
| 12 | files: Record<string, string> = {}, |
| 13 | options: { failOnWrite?: string } = {}, |
| 14 | ): MockFs { |
| 15 | const store = new Map(Object.entries(files)); |
| 16 | const written = new Map<string, string>(); |
| 17 | const unlinked = new Set<string>(); |
| 18 | const dirs = new Set<string>(); |
| 19 | return { |
| 20 | written, |
| 21 | unlinked, |
| 22 | dirs, |
| 23 | async readFile(path: string) { |
| 24 | const content = store.get(toUnixPath(path)); |
| 25 | if (content == null) { |
| 26 | throw new Error(`ENOENT: no such file or directory, open '${path}'`); |
| 27 | } |
| 28 | return content; |
| 29 | }, |
| 30 | async writeFile(path: string, content: string) { |
| 31 | if (options.failOnWrite === toUnixPath(path)) { |
| 32 | throw new Error(`EACCES: permission denied, open '${path}'`); |
| 33 | } |
| 34 | store.set(toUnixPath(path), content); |
| 35 | written.set(toUnixPath(path), content); |
| 36 | }, |
| 37 | async exists(path: string) { |
| 38 | return store.has(toUnixPath(path)); |
| 39 | }, |
| 40 | async mkdir(path: string): Promise<undefined> { |
| 41 | dirs.add(toUnixPath(path)); |
| 42 | }, |
| 43 | async unlink(path: string) { |
| 44 | store.delete(toUnixPath(path)); |
| 45 | unlinked.add(toUnixPath(path)); |
| 46 | }, |
| 47 | }; |
| 48 | } |
| 49 | |
| 50 | describe('createTree', () => { |
| 51 | it('should report the root directory', () => { |
no outgoing calls
no test coverage detected