| 28 | }; |
| 29 | |
| 30 | function processWithOutput( |
| 31 | options: { |
| 32 | readonly stdout?: string | Buffer; |
| 33 | readonly stderr?: string | Buffer; |
| 34 | readonly exitCode?: number | null; |
| 35 | readonly wait?: () => Promise<number>; |
| 36 | readonly kill?: (signal?: NodeJS.Signals) => Promise<void>; |
| 37 | } = {}, |
| 38 | ): KaosProcess { |
| 39 | const exitCode = options.exitCode ?? 0; |
| 40 | const stdout = Readable.from(options.stdout === undefined ? [] : [options.stdout]); |
| 41 | const stderr = Readable.from(options.stderr === undefined ? [] : [options.stderr]); |
| 42 | return { |
| 43 | stdin: { end: vi.fn(), write: vi.fn() } as unknown as Writable, |
| 44 | stdout, |
| 45 | stderr, |
| 46 | pid: 123, |
| 47 | exitCode, |
| 48 | wait: vi.fn(options.wait ?? (async () => exitCode)), |
| 49 | kill: vi.fn(options.kill ?? (async () => {})), |
| 50 | dispose: vi.fn(async () => { |
| 51 | stdout.destroy(); |
| 52 | stderr.destroy(); |
| 53 | }), |
| 54 | }; |
| 55 | } |
| 56 | |
| 57 | function processWithInterleavedOutput( |
| 58 | events: ReadonlyArray<{ |