(command: string, args: readonly string[])
| 132 | const calls: SpawnCall[] = []; |
| 133 | let invocation = 0; |
| 134 | const spawn = (command: string, args: readonly string[]): FakeProc => { |
| 135 | calls.push({ command, args }); |
| 136 | const outcome = outcomes[invocation] ?? outcomes[outcomes.length - 1]; |
| 137 | invocation += 1; |
| 138 | |
| 139 | const proc = new EventEmitter() as FakeProc; |
| 140 | proc.stdout = new EventEmitter(); |
| 141 | proc.stderr = new EventEmitter(); |
| 142 | |
| 143 | process.nextTick(() => { |
| 144 | if (!outcome) return; |
| 145 | if (outcome.kind === "missing") { |
| 146 | const err = new Error("spawn ffprobe ENOENT") as NodeJS.ErrnoException; |
| 147 | err.code = "ENOENT"; |
| 148 | proc.emit("error", err); |
| 149 | return; |
| 150 | } |
| 151 | if (outcome.kind === "error") { |
| 152 | const err = new Error(outcome.message) as NodeJS.ErrnoException; |
| 153 | if (outcome.code) err.code = outcome.code; |
| 154 | proc.emit("error", err); |
| 155 | return; |
| 156 | } |
| 157 | if (outcome.stdout) proc.stdout.emit("data", Buffer.from(outcome.stdout)); |
| 158 | if (outcome.stderr) proc.stderr.emit("data", Buffer.from(outcome.stderr)); |
| 159 | proc.emit("close", outcome.code); |
| 160 | }); |
| 161 | |
| 162 | return proc; |
| 163 | }; |
| 164 | return { spawn, calls }; |
| 165 | } |
| 166 |
no test coverage detected