(exitCode: number | null = null)
| 26 | const trackedChildren = new Map<number, ChildProcess>(); |
| 27 | |
| 28 | function createMockChild(exitCode: number | null = null): ChildProcess { |
| 29 | const emitter = new EventEmitter(); |
| 30 | const child = emitter as unknown as ChildProcess; |
| 31 | let currentExitCode = exitCode; |
| 32 | const pid = nextPid++; |
| 33 | Object.defineProperty(child, 'exitCode', { |
| 34 | get: () => currentExitCode, |
| 35 | set: (value: number | null) => { |
| 36 | currentExitCode = value; |
| 37 | }, |
| 38 | configurable: true, |
| 39 | }); |
| 40 | child.unref = vi.fn(); |
| 41 | trackedChildren.set(pid, child); |
| 42 | child.kill = vi.fn((signal?: NodeJS.Signals | number) => { |
| 43 | currentExitCode = 0; |
| 44 | queueMicrotask(() => { |
| 45 | emitter.emit('exit', 0, signal); |
| 46 | emitter.emit('close', 0, signal); |
| 47 | }); |
| 48 | return true; |
| 49 | }) as ChildProcess['kill']; |
| 50 | Object.defineProperty(child, 'pid', { value: pid, writable: true }); |
| 51 | return child; |
| 52 | } |
| 53 | |
| 54 | function createMockSpawner() { |
| 55 | return (_command: string, _args: string[], _options: SpawnOptions): ChildProcess => { |
no test coverage detected