@@ -107,6 +107,11 @@ describe('trackCommand', () => {
107107 }
108108 } ) ;
109109
110+ function parsePayload ( ) {
111+ const [ , options ] = fetchSpy . mock . calls [ 0 ] as [ string , RequestInit ] ;
112+ return JSON . parse ( options . body as string ) ;
113+ }
114+
110115 test ( 'sends correct payload to PostHog endpoint' , ( ) => {
111116 trackCommand ( 'emails send' , { json : true } ) ;
112117
@@ -115,10 +120,9 @@ describe('trackCommand', () => {
115120 expect ( url ) . toBe ( 'https://us.i.posthog.com/capture/' ) ;
116121 expect ( options . method ) . toBe ( 'POST' ) ;
117122
118- const body = JSON . parse ( options . body as string ) ;
123+ const body = parsePayload ( ) ;
119124 expect ( body . event ) . toBe ( 'cli.used' ) ;
120125 expect ( body . properties . command ) . toBe ( 'emails send' ) ;
121- expect ( body . properties . json_mode ) . toBe ( true ) ;
122126 expect ( body . properties . os ) . toBe ( process . platform ) ;
123127 expect ( body . properties . arch ) . toBe ( process . arch ) ;
124128 expect ( body . properties . node_version ) . toBe ( process . version ) ;
@@ -128,6 +132,67 @@ describe('trackCommand', () => {
128132 ) ;
129133 } ) ;
130134
135+ test ( 'interactive is false when --json flag is set' , ( ) => {
136+ Object . defineProperty ( process . stdin , 'isTTY' , {
137+ value : true ,
138+ writable : true ,
139+ } ) ;
140+ Object . defineProperty ( process . stdout , 'isTTY' , {
141+ value : true ,
142+ writable : true ,
143+ } ) ;
144+ delete process . env . CI ;
145+ delete process . env . GITHUB_ACTIONS ;
146+
147+ trackCommand ( 'emails send' , { json : true } ) ;
148+ expect ( parsePayload ( ) . properties . interactive ) . toBe ( false ) ;
149+ } ) ;
150+
151+ test ( 'interactive is false when not a TTY' , ( ) => {
152+ Object . defineProperty ( process . stdin , 'isTTY' , {
153+ value : undefined ,
154+ writable : true ,
155+ } ) ;
156+ Object . defineProperty ( process . stdout , 'isTTY' , {
157+ value : undefined ,
158+ writable : true ,
159+ } ) ;
160+
161+ trackCommand ( 'emails list' , { } ) ;
162+ expect ( parsePayload ( ) . properties . interactive ) . toBe ( false ) ;
163+ } ) ;
164+
165+ test ( 'interactive is false in CI even with TTY' , ( ) => {
166+ Object . defineProperty ( process . stdin , 'isTTY' , {
167+ value : true ,
168+ writable : true ,
169+ } ) ;
170+ Object . defineProperty ( process . stdout , 'isTTY' , {
171+ value : true ,
172+ writable : true ,
173+ } ) ;
174+ process . env . CI = 'true' ;
175+
176+ trackCommand ( 'emails list' , { } ) ;
177+ expect ( parsePayload ( ) . properties . interactive ) . toBe ( false ) ;
178+ } ) ;
179+
180+ test ( 'interactive is true with TTY and no --json' , ( ) => {
181+ Object . defineProperty ( process . stdin , 'isTTY' , {
182+ value : true ,
183+ writable : true ,
184+ } ) ;
185+ Object . defineProperty ( process . stdout , 'isTTY' , {
186+ value : true ,
187+ writable : true ,
188+ } ) ;
189+ delete process . env . CI ;
190+ delete process . env . GITHUB_ACTIONS ;
191+
192+ trackCommand ( 'emails list' , { } ) ;
193+ expect ( parsePayload ( ) . properties . interactive ) . toBe ( true ) ;
194+ } ) ;
195+
131196 test ( 'does nothing when disabled' , ( ) => {
132197 process . env . RESEND_TELEMETRY_DISABLED = '1' ;
133198 trackCommand ( 'emails send' , { } ) ;
0 commit comments