Skip to content

Commit da22238

Browse files
committed
feat(request): Pretty output
resolve [object Object] when console.log to terminal Signed-off-by: ysknsid25 <kengo071225@gmail.com>
1 parent 667d7f8 commit da22238

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/commands/request/index.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,4 +642,31 @@ describe('requestCommand', () => {
642642

643643
expect(consoleLogSpy).toHaveBeenCalledWith(expectedOutput)
644644
})
645+
646+
it('should display JSON body correctly with --json and --include options', async () => {
647+
const mockApp = new Hono()
648+
const jsonBody = { message: 'Hello JSON' }
649+
mockApp.get('/json-data', (c) => c.json(jsonBody))
650+
setupBasicMocks('test-app.js', mockApp)
651+
652+
await program.parseAsync([
653+
'node',
654+
'test',
655+
'request',
656+
'-P',
657+
'/json-data',
658+
'-J',
659+
'-i',
660+
'test-app.js',
661+
])
662+
663+
const expectedOutput = [
664+
'STATUS 200',
665+
'content-type: application/json',
666+
'',
667+
JSON.stringify(jsonBody, null, 2),
668+
].join('\n')
669+
670+
expect(consoleLogSpy).toHaveBeenCalledWith(expectedOutput)
671+
})
645672
})

src/commands/request/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function requestCommand(program: Command) {
5252
const outputBody = formatResponseBody(
5353
result.body,
5454
result.headers['content-type'],
55-
options.json
55+
options.json && !options.include
5656
)
5757
const buffer = await result.response.clone().arrayBuffer()
5858
const isBinaryData = isBinaryResponse(buffer)

0 commit comments

Comments
 (0)