Skip to content

Commit 9c6657e

Browse files
committed
refactor: optimize format-output utility
1 parent c701c09 commit 9c6657e

File tree

2 files changed

+178
-171
lines changed

2 files changed

+178
-171
lines changed

apps/sim/lib/core/utils/format-output.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('format-output utilities', () => {
8888
obj.self = obj
8989
const result = formatOutputForDisplay(obj, { mode: 'raw' })
9090
expect(result).toContain('[Circular]')
91-
expect(result).not.toThrow()
91+
expect(() => formatOutputForDisplay(obj, { mode: 'raw' })).not.toThrow()
9292
})
9393

9494
// Large arrays
@@ -126,16 +126,21 @@ describe('format-output utilities', () => {
126126

127127
// Mode-specific formatting
128128
it('formats correctly for different modes', () => {
129-
const obj = { data: 'test' }
129+
const obj = { someField: 'value', type: 'test' }
130130

131131
const chatFormat = formatOutputForDisplay(obj, { mode: 'chat' })
132-
expect(chatFormat).toContain('test')
133-
134132
const workflowFormat = formatOutputForDisplay(obj, { mode: 'workflow' })
133+
const rawFormat = formatOutputForDisplay(obj, { mode: 'raw' })
134+
135+
// Chat mode should show JSON for objects without text fields
136+
expect(chatFormat).toContain('someField')
137+
138+
// Workflow mode should wrap in code blocks
135139
expect(workflowFormat).toMatch(/```json/)
140+
expect(workflowFormat).toContain('someField')
136141

137-
const rawFormat = formatOutputForDisplay(obj, { mode: 'raw' })
138-
expect(rawFormat).toBe('{"data":"test"}')
142+
// Raw mode should show plain JSON
143+
expect(rawFormat).toMatch(/"someField":\s*"value"/)
139144
})
140145

141146
// Edge cases

0 commit comments

Comments
 (0)