| 12 | import { handleVis, type VisDeps } from '#/cli/sub/vis'; |
| 13 | |
| 14 | function makeDeps(over: Partial<VisDeps> = {}): { |
| 15 | deps: VisDeps; |
| 16 | opened: string[]; |
| 17 | out: string[]; |
| 18 | } { |
| 19 | const opened: string[] = []; |
| 20 | const out: string[] = []; |
| 21 | const deps: VisDeps = { |
| 22 | getHomeDir: () => '/home/k', |
| 23 | startVisServer: vi.fn(async (o) => ({ |
| 24 | port: 41234, |
| 25 | host: '127.0.0.1', |
| 26 | url: 'http://127.0.0.1:41234/', |
| 27 | close: async () => {}, |
| 28 | _opts: o, |
| 29 | })) as unknown as VisDeps['startVisServer'], |
| 30 | openUrl: async (u: string) => { |
| 31 | opened.push(u); |
| 32 | }, |
| 33 | waitForShutdown: async () => {}, |
| 34 | stdout: { |
| 35 | write: (s: string) => { |
| 36 | out.push(s); |
| 37 | return true; |
| 38 | }, |
| 39 | }, |
| 40 | stderr: { write: () => true }, |
| 41 | exit: vi.fn() as unknown as VisDeps['exit'], |
| 42 | ...over, |
| 43 | }; |
| 44 | return { deps, opened, out }; |
| 45 | } |
| 46 | |
| 47 | describe('handleVis', () => { |
| 48 | it('starts the server with the home dir + auto port and opens the browser', async () => { |