Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions tests/e2e/helpers/terminal-pty-write-spy.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import type { ElectronApplication } from '@stablyai/playwright-test'
import * as electron from 'electron'
import { afterEach, expect, it, vi } from 'vitest'
import { setTerminalPtyWriteDelay } from './terminal-pty-write-spy'

afterEach(() => vi.unstubAllGlobals())

it('sets and clears paste backpressure using the main-process evaluate argument', async () => {
vi.stubGlobal('__terminalPtyWriteDelayMs', 0)
const evaluate = vi.fn()
evaluate.mockImplementation(
(callback: (electron: object, argument: number) => void, delay: number) => callback({}, delay)
)
const evaluate = vi.fn<ElectronApplication['evaluate']>()
evaluate.mockImplementation(async (callback, delay) => {
if (typeof callback !== 'function') {
throw new Error('Expected a main-process evaluate callback')
}
return callback(electron, delay)
})
const app = { evaluate }

if (!('__terminalPtyWriteDelayMs' in globalThis)) {
throw new Error('Expected the stubbed PTY write delay')
}

await setTerminalPtyWriteDelay(app, 35)
expect(Reflect.get(globalThis, '__terminalPtyWriteDelayMs')).toBe(35)
expect(globalThis.__terminalPtyWriteDelayMs).toBe(35)
await setTerminalPtyWriteDelay(app, 0)
expect(Reflect.get(globalThis, '__terminalPtyWriteDelayMs')).toBe(0)
expect(globalThis.__terminalPtyWriteDelayMs).toBe(0)
})
Loading