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

Function createTestServer

src/cli/server.test.ts:43–82  ·  view source on GitHub ↗

* Create a test server using the actual createOrpcServer function. * Sets up services and config in a temp directory.

()

Source from the content-addressed store, hash-verified

41 * Sets up services and config in a temp directory.
42 */
43async function createTestServer(): Promise<TestServerHandle> {
44 // Create temp dir for config
45 const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "mux-server-test-"));
46 const config = new Config(tempDir);
47
48 // Mock BrowserWindow
49 const mockWindow: BrowserWindow = {
50 isDestroyed: () => false,
51 setTitle: () => undefined,
52 webContents: {
53 send: () => undefined,
54 openDevTools: () => undefined,
55 } as unknown as WebContents,
56 } as unknown as BrowserWindow;
57
58 // Initialize services
59 const services = new ServiceContainer(config);
60 await services.initialize();
61 services.windowService.setMainWindow(mockWindow);
62
63 // Build context
64 const context: ORPCContext = services.toORPCContext();
65
66 // Use the actual createOrpcServer function
67 const server = await createOrpcServer({
68 context,
69 // port 0 = random available port
70 onOrpcError: () => undefined, // Silence errors in tests
71 });
72
73 return {
74 server,
75 tempDir,
76 close: async () => {
77 await server.close();
78 // Cleanup temp directory
79 await fs.rm(tempDir, { recursive: true, force: true }).catch(() => undefined);
80 },
81 };
82}
83
84// --- HTTP Client Factory ---
85

Callers 1

server.test.tsFile · 0.70

Calls 5

initializeMethod · 0.95
toORPCContextMethod · 0.95
createOrpcServerFunction · 0.90
setMainWindowMethod · 0.80
closeMethod · 0.65

Tested by

no test coverage detected