Compare commits

...

1 Commits

Author SHA1 Message Date
Nikhil Sonti
e8273a835b test: cover terminal limactl resolver errors 2026-04-28 17:06:02 -07:00

View File

@@ -56,4 +56,40 @@ describe('createTerminalSocketEvents', () => {
)
expect(close).not.toHaveBeenCalled()
})
it('sends an error and closes when the limactl resolver throws', async () => {
const close = mock(() => {})
const send = mock(() => {})
const createTerminalSession = mock(() => {
throw new Error('should not start a session')
})
const actualTerminalSession = await import(
'../../../src/api/services/terminal/terminal-session'
)
mock.module('../../../src/api/services/terminal/terminal-session', () => ({
...actualTerminalSession,
createTerminalSession,
}))
const { createTerminalSocketEvents } = await import(
'../../../src/api/routes/terminal'
)
const events = createTerminalSocketEvents({
containerName: 'gateway',
limaHome: '/tmp/lima',
limactlPath: () => {
throw new Error('limactl not found')
},
vmName: 'browseros-vm',
})
events.onOpen(new Event('open'), { send, close })
expect(createTerminalSession).not.toHaveBeenCalled()
expect(send).toHaveBeenCalledWith(
JSON.stringify({ type: 'error', message: 'limactl not found' }),
)
expect(close).toHaveBeenCalledTimes(1)
})
})