dify/cli/src/printers/format-text.test.ts
Yunlu Wen c0ee821d45
refactor: use absolute path for inter dir importing (#36822)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-06-01 01:32:16 +00:00

22 lines
900 B
TypeScript

import { describe, expect, it } from 'vitest'
import { TextPrintFlags } from './format-text'
describe('TextPrintFlags', () => {
it('routes to handler by mode', () => {
const f = new TextPrintFlags()
f.register({ render: v => `chat:${(v as { x: string }).x}\n` }, 'chat')
f.register({ render: v => `wf:${(v as { y: string }).y}\n` }, 'workflow')
expect(f.toPrinter('').print({ mode: () => 'chat', raw: () => ({ x: '1' }) })).toBe('chat:1\n')
expect(f.toPrinter('text').print({ mode: () => 'workflow', raw: () => ({ y: '2' }) })).toBe('wf:2\n')
})
it('rejects unknown formats', () => {
expect(() => new TextPrintFlags().toPrinter('json')).toThrow(/not supported/)
})
it('errors on unregistered mode', () => {
const f = new TextPrintFlags()
expect(() => f.toPrinter('').print({ mode: () => 'agent', raw: () => ({}) })).toThrow(/no handler for mode/)
})
})