MCPcopy
hub / github.com/coder/mux / mockCoderCommandResult

Function mockCoderCommandResult

src/node/services/coderService.test.ts:80–101  ·  view source on GitHub ↗
(options: {
  stdout?: string;
  stderr?: string;
  exitCode: number;
})

Source from the content-addressed store, hash-verified

78let spawnSpy: ReturnType<typeof spyOn<typeof childProcess, "spawn">> | null = null;
79
80function mockCoderCommandResult(options: {
81 stdout?: string;
82 stderr?: string;
83 exitCode: number;
84}): void {
85 const stdout = Readable.from(options.stdout ? [Buffer.from(options.stdout)] : []);
86 const stderr = Readable.from(options.stderr ? [Buffer.from(options.stderr)] : []);
87 const events = new EventEmitter();
88
89 spawnSpy?.mockReturnValue({
90 stdout,
91 stderr,
92 exitCode: null,
93 signalCode: null,
94 kill: vi.fn(),
95 on: events.on.bind(events),
96 removeListener: events.removeListener.bind(events),
97 } as never);
98
99 // Emit close after handlers are attached.
100 setTimeout(() => events.emit("close", options.exitCode), 0);
101}
102
103type RichParameter = Parameters<CoderService["computeExtraParams"]>[0][number];
104

Callers 1

Calls 1

emitMethod · 0.65

Tested by

no test coverage detected