| 14 | * This class allows for simulating a file system in memory. |
| 15 | */ |
| 16 | export class MockHost implements Host { |
| 17 | readonly requiresQuoting = false; |
| 18 | private readonly fs = new Map<string, string[] | true>(); |
| 19 | |
| 20 | constructor(files: Record<string, string[] | true> = {}) { |
| 21 | // Normalize paths to use forward slashes for consistency in tests. |
| 22 | for (const [path, content] of Object.entries(files)) { |
| 23 | const normalizedPath = path.replace(/\\/g, '/'); |
| 24 | this.fs.set(normalizedPath, content); |
| 25 | |
| 26 | // If the content is an array (directory listing), create entries for the files in it. |
| 27 | if (Array.isArray(content)) { |
| 28 | for (const file of content) { |
| 29 | const filePath = normalizedPath === '/' ? `/${file}` : `${normalizedPath}/${file}`; |
| 30 | this.fs.set(filePath, []); // Use empty array to represent a file (not `true` which is a dir) |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | mkdir(path: string, options?: { recursive?: boolean }): Promise<string | undefined> { |
| 37 | throw new Error('Method not implemented.'); |
| 38 | } |
| 39 | |
| 40 | stat(path: string): Promise<Stats> { |
| 41 | const content = this.fs.get(path.replace(/\\/g, '/')); |
| 42 | if (content === undefined) { |
| 43 | return Promise.reject(new Error(`File not found: ${path}`)); |
| 44 | } |
| 45 | |
| 46 | // A `true` value signifies a directory in our mock file system. |
| 47 | // Anything else is considered a file for the purpose of this mock. |
| 48 | return Promise.resolve({ |
| 49 | isDirectory: () => content === true, |
| 50 | isFile: () => content !== true, |
| 51 | } as Stats); |
| 52 | } |
| 53 | |
| 54 | runCommand( |
| 55 | command: string, |
| 56 | args: readonly string[], |
| 57 | options?: { |
| 58 | timeout?: number; |
| 59 | stdio?: 'pipe' | 'ignore'; |
| 60 | cwd?: string; |
| 61 | env?: Record<string, string>; |
| 62 | }, |
| 63 | ): Promise<{ stdout: string; stderr: string }> { |
| 64 | throw new Error('Method not implemented.'); |
| 65 | } |
| 66 | |
| 67 | createTempDirectory(baseDir?: string): Promise<string> { |
| 68 | throw new Error('Method not implemented.'); |
| 69 | } |
| 70 | |
| 71 | deleteDirectory(path: string): Promise<void> { |
| 72 | throw new Error('Method not implemented.'); |
| 73 | } |
nothing calls this directly
no outgoing calls
no test coverage detected