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