(stream: 'stdout' | 'stderr')
| 13 | } |
| 14 | |
| 15 | export function captureProcessWrite(stream: 'stdout' | 'stderr'): { |
| 16 | readonly chunks: string[]; |
| 17 | readonly text: () => string; |
| 18 | readonly restore: () => void; |
| 19 | } { |
| 20 | const chunks: string[] = []; |
| 21 | const target = process[stream]; |
| 22 | const spy = vi.spyOn(target, 'write').mockImplementation(((chunk: string | Uint8Array) => { |
| 23 | chunks.push(typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString('utf8')); |
| 24 | return true; |
| 25 | }) as never); |
| 26 | |
| 27 | return { |
| 28 | chunks, |
| 29 | text: () => chunks.join(''), |
| 30 | restore: () =>{ spy.mockRestore(); }, |
| 31 | }; |
| 32 | } |
no test coverage detected