MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / createSpawnSpy

Function createSpawnSpy

packages/engine/src/utils/ffprobe.test.ts:128–165  ·  view source on GitHub ↗
(outcomes: SpawnOutcome[])

Source from the content-addressed store, hash-verified

126 | { kind: "exit"; code: number; stdout?: string; stderr?: string };
127
128function createSpawnSpy(outcomes: SpawnOutcome[]): {
129 spawn: (command: string, args: readonly string[]) => FakeProc;
130 calls: SpawnCall[];
131} {
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
167describe("ffprobe missing-binary fallback", () => {
168 const originalFfprobePath = process.env.HYPERFRAMES_FFPROBE_PATH;

Callers 1

ffprobe.test.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected