@@ -80,7 +80,111 @@ describe('generateSummaryTable', () => {
8080 expect ( summary ) . toContain ( 'Expected 0 results, but got 1' ) ;
8181 } ) ;
8282
83- it ( 'should include query outputs for successful queries' , ( ) => {
83+ it ( 'should include query output in failed queries section (default show-results=failed)' , ( ) => {
84+ const results : QueryResult [ ] = [
85+ {
86+ query : '*:license(copyleft) --expect-results=0' ,
87+ selector : '*:license(copyleft)' ,
88+ flags : [ '--expect-results=0' ] ,
89+ output : 'gpl-pkg@1.0.0\nlgpl-lib@2.3.4\nagpl-service@0.1.0' ,
90+ stderr : '' ,
91+ exitCode : 0 ,
92+ success : true ,
93+ passed : false ,
94+ error : 'Expected 0 results, but got 3' ,
95+ expectedResults : '0' ,
96+ actualResultCount : 3 ,
97+ duration : 120 ,
98+ } ,
99+ ] ;
100+
101+ const summary = generateSummaryTable ( results ) ;
102+
103+ expect ( summary ) . toContain ( '### Failed Queries' ) ;
104+ expect ( summary ) . toContain ( 'Expected 0 results, but got 3' ) ;
105+ // The actual matched packages should be shown
106+ expect ( summary ) . toContain ( 'Output:' ) ;
107+ expect ( summary ) . toContain ( 'gpl-pkg@1.0.0' ) ;
108+ expect ( summary ) . toContain ( 'lgpl-lib@2.3.4' ) ;
109+ expect ( summary ) . toContain ( 'agpl-service@0.1.0' ) ;
110+ } ) ;
111+
112+ it ( 'should show stderr in failed queries section for CLI errors' , ( ) => {
113+ const results : QueryResult [ ] = [
114+ {
115+ query : ':diff() --expect-results=0' ,
116+ selector : ':diff()' ,
117+ flags : [ '--expect-results=0' ] ,
118+ output : '' ,
119+ stderr : 'Error: unsupported selector :diff()' ,
120+ exitCode : 1 ,
121+ success : false ,
122+ passed : false ,
123+ error : 'Error: unsupported selector :diff()' ,
124+ duration : 50 ,
125+ } ,
126+ ] ;
127+
128+ const summary = generateSummaryTable ( results ) ;
129+
130+ expect ( summary ) . toContain ( '### Failed Queries' ) ;
131+ expect ( summary ) . toContain ( 'unsupported selector' ) ;
132+ expect ( summary ) . toContain ( 'stderr' ) ;
133+ } ) ;
134+
135+ it ( 'should show both stdout and stderr for CLI errors with partial output' , ( ) => {
136+ const results : QueryResult [ ] = [
137+ {
138+ query : ':some-selector' ,
139+ selector : ':some-selector' ,
140+ flags : [ ] ,
141+ output : 'partial-result@1.0.0' ,
142+ stderr : 'Warning: query terminated early\nError: connection reset' ,
143+ exitCode : 1 ,
144+ success : false ,
145+ passed : false ,
146+ error : 'Warning: query terminated early\nError: connection reset' ,
147+ duration : 300 ,
148+ } ,
149+ ] ;
150+
151+ const summary = generateSummaryTable ( results ) ;
152+
153+ expect ( summary ) . toContain ( '### Failed Queries' ) ;
154+ expect ( summary ) . toContain ( 'connection reset' ) ;
155+ // stdout should also be shown
156+ expect ( summary ) . toContain ( 'Output:' ) ;
157+ expect ( summary ) . toContain ( 'partial-result@1.0.0' ) ;
158+ } ) ;
159+
160+ it ( 'should not show output for failed queries when show-results=never' , ( ) => {
161+ const results : QueryResult [ ] = [
162+ {
163+ query : '*:license(copyleft) --expect-results=0' ,
164+ selector : '*:license(copyleft)' ,
165+ flags : [ '--expect-results=0' ] ,
166+ output : 'gpl-pkg@1.0.0\nlgpl-lib@2.3.4' ,
167+ stderr : '' ,
168+ exitCode : 0 ,
169+ success : true ,
170+ passed : false ,
171+ error : 'Expected 0 results, but got 2' ,
172+ expectedResults : '0' ,
173+ actualResultCount : 2 ,
174+ duration : 120 ,
175+ } ,
176+ ] ;
177+
178+ const summary = generateSummaryTable ( results , 'never' ) ;
179+
180+ expect ( summary ) . toContain ( '### Failed Queries' ) ;
181+ expect ( summary ) . toContain ( 'Expected 0 results, but got 2' ) ;
182+ // Output should NOT be shown
183+ expect ( summary ) . not . toContain ( 'gpl-pkg@1.0.0' ) ;
184+ expect ( summary ) . not . toContain ( 'Output:' ) ;
185+ } ) ;
186+
187+ it ( 'should show output for successful queries when show-results=always' , ( ) => {
84188 const results : QueryResult [ ] = [
85189 {
86190 query : ':outdated --view=json' ,
@@ -95,7 +199,52 @@ describe('generateSummaryTable', () => {
95199 } ,
96200 ] ;
97201
98- const summary = generateSummaryTable ( results ) ;
202+ const summary = generateSummaryTable ( results , 'always' ) ;
203+
204+ expect ( summary ) . toContain ( '### Query Outputs' ) ;
205+ expect ( summary ) . toContain ( '```' ) ;
206+ expect ( summary ) . toContain ( '"name": "lodash"' ) ;
207+ } ) ;
208+
209+ it ( 'should not show successful query outputs with default show-results=failed' , ( ) => {
210+ const results : QueryResult [ ] = [
211+ {
212+ query : ':outdated --view=json' ,
213+ selector : ':outdated' ,
214+ flags : [ '--view=json' ] ,
215+ output : '[\n {\n "name": "lodash",\n "current": "4.17.20",\n "wanted": "4.17.21"\n }\n]' ,
216+ stderr : '' ,
217+ exitCode : 0 ,
218+ success : true ,
219+ passed : true ,
220+ duration : 200 ,
221+ } ,
222+ ] ;
223+
224+ const summary = generateSummaryTable ( results , 'failed' ) ;
225+
226+ // With 'failed' mode, successful query output should NOT be shown
227+ expect ( summary ) . not . toContain ( '### Query Outputs' ) ;
228+ expect ( summary ) . not . toContain ( '"name": "lodash"' ) ;
229+ } ) ;
230+
231+ it ( 'should include query outputs for successful queries (legacy default behavior)' , ( ) => {
232+ // When show-results is 'always', successful query outputs are shown
233+ const results : QueryResult [ ] = [
234+ {
235+ query : ':outdated --view=json' ,
236+ selector : ':outdated' ,
237+ flags : [ '--view=json' ] ,
238+ output : '[\n {\n "name": "lodash",\n "current": "4.17.20",\n "wanted": "4.17.21"\n }\n]' ,
239+ stderr : '' ,
240+ exitCode : 0 ,
241+ success : true ,
242+ passed : true ,
243+ duration : 200 ,
244+ } ,
245+ ] ;
246+
247+ const summary = generateSummaryTable ( results , 'always' ) ;
99248
100249 expect ( summary ) . toContain ( '### Query Outputs' ) ;
101250 expect ( summary ) . toContain ( '```' ) ;
@@ -159,4 +308,4 @@ describe('setOutputs', () => {
159308
160309 expect ( mockSetOutput ) . toHaveBeenCalledWith ( 'passed' , 'false' ) ;
161310 } ) ;
162- } ) ;
311+ } ) ;
0 commit comments