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

Class MockChildProcess

src/node/services/browser/BrowserControlService.test.ts:15–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13const SESSION_NAME = "session-a";
14
15class MockChildProcess extends EventEmitter {
16 public readonly stdout = new PassThrough();
17 public readonly stderr = new PassThrough();
18 public readonly kill = mock(() => true);
19 public readonly pid = undefined;
20 public readonly stdin = null;
21 public killed = false;
22 public exitCode: number | null = null;
23 public signalCode: NodeJS.Signals | null = null;
24
25 override emit(event: string | symbol, ...args: unknown[]): boolean {
26 if (event === "close") {
27 this.exitCode = (args[0] as number | null | undefined) ?? null;
28 this.signalCode = (args[1] as NodeJS.Signals | null | undefined) ?? null;
29 }
30 if (event === "error") {
31 this.killed = true;
32 }
33 return super.emit(event, ...args);
34 }
35
36 writeStdout(chunk: string): void {
37 this.stdout.write(chunk);
38 }
39
40 writeStderr(chunk: string): void {
41 this.stderr.write(chunk);
42 }
43
44 close(code = 0, signal: NodeJS.Signals | null = null): void {
45 this.emit("close", code, signal);
46 this.stdout.end();
47 this.stderr.end();
48 }
49
50 fail(error: Error): void {
51 this.emit("error", error);
52 this.stdout.end();
53 this.stderr.end();
54 }
55}
56
57function createAttachableSession() {
58 return {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected