Files

32 lines
1.2 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushShellBootstrap } from '../../src/utils/shellIO'
describe('flushShellBootstrap', () => {
beforeEach(() => {
vi.mocked(window.opsxApi.localOpenOutput).mockClear()
vi.mocked(window.opsxApi.sshShellOpenOutput).mockClear()
vi.mocked(window.opsxApi.localOpenOutput).mockResolvedValue({
success: true,
data: [98, 97, 115, 104],
})
vi.mocked(window.opsxApi.sshShellOpenOutput).mockResolvedValue({
success: true,
data: [109, 111, 116, 100],
})
})
it('opens buffered local PTY output for local-* ids', async () => {
const boot = await flushShellBootstrap('local-abc')
expect(window.opsxApi.localOpenOutput).toHaveBeenCalledWith('local-abc')
expect(window.opsxApi.sshShellOpenOutput).not.toHaveBeenCalled()
expect(boot).toEqual(new Uint8Array([98, 97, 115, 104]))
})
it('opens buffered SSH output for remote shell ids', async () => {
const boot = await flushShellBootstrap('shell-abc')
expect(window.opsxApi.sshShellOpenOutput).toHaveBeenCalledWith('shell-abc')
expect(window.opsxApi.localOpenOutput).not.toHaveBeenCalled()
expect(boot).toEqual(new Uint8Array([109, 111, 116, 100]))
})
})