mirror of
https://github.com/stablyai/orca.git
synced 2026-11-15 18:37:24 +00:00
30 lines
937 B
TypeScript
30 lines
937 B
TypeScript
import { PassThrough } from 'node:stream'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import '../runtime/types'
|
|
import { createTerminalConfirm } from './plugin-dev-watch-approval'
|
|
|
|
import './plugin-dev-watch-loop'
|
|
|
|
function terminal(isTTY = true) {
|
|
const input = Object.assign(new PassThrough(), { isTTY })
|
|
const output = Object.assign(new PassThrough(), { isTTY })
|
|
let printed = ''
|
|
output.on('data', (chunk: Buffer) => {
|
|
printed += chunk.toString()
|
|
})
|
|
return { input, output, printed: () => printed }
|
|
}
|
|
|
|
describe('pluginDevWatchConfirmFor', () => {
|
|
it.each([
|
|
['end of input', (input: PassThrough) => input.end()],
|
|
['Ctrl-C', (input: PassThrough) => input.write('\u0003')]
|
|
])('reads %s as no', async (_name, stop) => {
|
|
const streams = terminal()
|
|
const answer = createTerminalConfirm(streams)('Approve and load? [y/N] ')
|
|
stop(streams.input)
|
|
await expect(answer).resolves.toBe(false)
|
|
})
|
|
})
|