| 34 | }; |
| 35 | |
| 36 | async function captureStdout(fn: () => Promise<void>): Promise<string> { |
| 37 | const originalWrite = process.stdout.write; |
| 38 | let output = ''; |
| 39 | process.stdout.write = ((chunk: string | Uint8Array) => { |
| 40 | output += typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString('utf-8'); |
| 41 | return true; |
| 42 | }) as typeof process.stdout.write; |
| 43 | |
| 44 | try { |
| 45 | await fn(); |
| 46 | return output; |
| 47 | } finally { |
| 48 | process.stdout.write = originalWrite; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | describe('file delete command', () => { |
| 53 | let server: MockServer; |