MCPcopy Index your code
hub / github.com/getsentry/XcodeBuildMCP / createMockChild

Function createMockChild

src/utils/__tests__/simulator-steps-pid.test.ts:28–52  ·  view source on GitHub ↗
(exitCode: number | null = null)

Source from the content-addressed store, hash-verified

26const trackedChildren = new Map<number, ChildProcess>();
27
28function 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
54function createMockSpawner() {
55 return (_command: string, _args: string[], _options: SpawnOptions): ChildProcess => {

Callers 2

createMockSpawnerFunction · 0.70
spawnerFunction · 0.70

Calls 1

emitMethod · 0.80

Tested by

no test coverage detected