MCPcopy Create free account
hub / github.com/google-gemini/gemini-cli / createMockChildProcess

Function createMockChildProcess

packages/cli/src/utils/relaunch.test.ts:354–387  ·  view source on GitHub ↗

* Creates a mock child process that emits events asynchronously

(
  exitCode: number = 0,
  autoClose: boolean = false,
)

Source from the content-addressed store, hash-verified

352 * Creates a mock child process that emits events asynchronously
353 */
354function createMockChildProcess(
355 exitCode: number = 0,
356 autoClose: boolean = false,
357): ChildProcess {
358 const mockChild = new EventEmitter() as ChildProcess;
359
360 Object.assign(mockChild, {
361 stdin: null,
362 stdout: null,
363 stderr: null,
364 stdio: [null, null, null],
365 pid: 12345,
366 killed: false,
367 exitCode: null,
368 signalCode: null,
369 spawnargs: [],
370 spawnfile: '',
371 kill: vi.fn(),
372 send: vi.fn(),
373 disconnect: vi.fn(),
374 unref: vi.fn(),
375 ref: vi.fn(),
376 on: mockChild.on.bind(mockChild),
377 emit: mockChild.emit.bind(mockChild),
378 });
379
380 if (autoClose) {
381 setImmediate(() => {
382 mockChild.emit('close', exitCode);
383 });
384 }
385
386 return mockChild;
387}

Callers 1

relaunch.test.tsFile · 0.70

Calls 1

emitMethod · 0.45

Tested by

no test coverage detected