mirror of
https://github.com/langgenius/dify.git
synced 2026-06-07 16:32:01 +08:00
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
22 lines
900 B
TypeScript
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/)
|
|
})
|
|
})
|