@@ -41,7 +41,10 @@ describe("containers info", () => {
4141 -h, --help Show help [boolean]
4242 --install-skills Install Cloudflare skills for detected AI coding agents before running the command [boolean] [default: false]
4343 --profile Use a specific auth profile [string]
44- -v, --version Show version number [boolean]"
44+ -v, --version Show version number [boolean]
45+
46+ OPTIONS
47+ --json Return output as JSON [boolean] [default: false]"
4548 ` ) ;
4649 } ) ;
4750
@@ -58,6 +61,85 @@ describe("containers info", () => {
5861 ) ;
5962 } ) ;
6063
64+ it ( "should output JSON via --json flag in TTY mode" , async ( { expect } ) => {
65+ setIsTTY ( true ) ;
66+ setWranglerConfig ( { } ) ;
67+ msw . use (
68+ http . get (
69+ "*/applications/asdf" ,
70+ async ( { request } ) => {
71+ expect ( await request . text ( ) ) . toEqual ( "" ) ;
72+ return HttpResponse . json (
73+ `{"success": true, "result": ${ MOCK_APPLICATION_SINGLE } }`
74+ ) ;
75+ } ,
76+ { once : true }
77+ )
78+ ) ;
79+ await runWrangler ( "containers info asdf --json" ) ;
80+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
81+ expect ( std . out ) . toMatchInlineSnapshot ( `
82+ "{
83+ "id": "asdf",
84+ "created_at": "2025-02-14T18:03:13.268999936Z",
85+ "account_id": "test-account",
86+ "name": "app-test",
87+ "version": 1,
88+ "configuration": {
89+ "image": "registry.test.cfdata.org/test-app:v1",
90+ "network": {
91+ "mode": "private"
92+ }
93+ },
94+ "scheduling_policy": "regional",
95+ "instances": 2,
96+ "jobs": false,
97+ "constraints": {
98+ "region": "WNAM"
99+ },
100+ "durable_objects": {
101+ "namespace_id": "test-id"
102+ },
103+ "health": {
104+ "instances": {
105+ "healthy": 2,
106+ "failed": 0,
107+ "scheduling": 0,
108+ "starting": 0
109+ }
110+ }
111+ }"
112+ ` ) ;
113+ } ) ;
114+
115+ it ( "should throw JsonFriendlyFatalError on unexpected API error with --json" , async ( {
116+ expect,
117+ } ) => {
118+ setIsTTY ( true ) ;
119+ setWranglerConfig ( { } ) ;
120+ msw . use (
121+ http . get (
122+ "*/applications/asdf" ,
123+ async ( ) => {
124+ return HttpResponse . json (
125+ {
126+ success : false ,
127+ result : null ,
128+ errors : [ { code : 2000 , message : "boom" } ] ,
129+ } ,
130+ { status : 500 }
131+ ) ;
132+ } ,
133+ { once : true }
134+ )
135+ ) ;
136+ await expect ( runWrangler ( "containers info asdf --json" ) ) . rejects . toThrow (
137+ / T h e r e h a s b e e n a n i n t e r n a l e r r o r /
138+ ) ;
139+ expect ( ( ) => JSON . parse ( std . out ) ) . not . toThrow ( ) ;
140+ expect ( JSON . parse ( std . out ) ) . toHaveProperty ( "error" ) ;
141+ } ) ;
142+
61143 it ( "should show a single container when given an ID (json)" , async ( {
62144 expect,
63145 } ) => {
@@ -75,8 +157,8 @@ describe("containers info", () => {
75157 { once : true }
76158 )
77159 ) ;
78- expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
79160 await runWrangler ( "containers info asdf" ) ;
161+ expect ( std . err ) . toMatchInlineSnapshot ( `""` ) ;
80162 expect ( std . out ) . toMatchInlineSnapshot ( `
81163 "{
82164 "id": "asdf",
0 commit comments