@@ -207,4 +207,78 @@ describe('jest-junit tests', () => {
207207 // Report should have the title as the first line
208208 expect ( report ) . toMatch ( / ^ # M y C u s t o m T i t l e \n / )
209209 } )
210+
211+ it ( 'report can be collapsed when configured' , async ( ) => {
212+ const fixturePath = path . join ( __dirname , 'fixtures' , 'jest-junit.xml' )
213+ const filePath = normalizeFilePath ( path . relative ( __dirname , fixturePath ) )
214+ const fileContent = fs . readFileSync ( fixturePath , { encoding : 'utf8' } )
215+
216+ const opts : ParseOptions = {
217+ parseErrors : true ,
218+ trackedFiles : [ ]
219+ }
220+
221+ const parser = new JestJunitParser ( opts )
222+ const result = await parser . parse ( filePath , fileContent )
223+ const report = getReport ( [ result ] , {
224+ ...DEFAULT_OPTIONS ,
225+ collapsed : 'always'
226+ } )
227+ // Report should include collapsible details
228+ expect ( report ) . toContain ( '<details><summary>Expand for details</summary>' )
229+ expect ( report ) . toContain ( '</details>' )
230+ } )
231+
232+ it ( 'report is not collapsed when configured to never' , async ( ) => {
233+ const fixturePath = path . join ( __dirname , 'fixtures' , 'jest-junit.xml' )
234+ const filePath = normalizeFilePath ( path . relative ( __dirname , fixturePath ) )
235+ const fileContent = fs . readFileSync ( fixturePath , { encoding : 'utf8' } )
236+
237+ const opts : ParseOptions = {
238+ parseErrors : true ,
239+ trackedFiles : [ ]
240+ }
241+
242+ const parser = new JestJunitParser ( opts )
243+ const result = await parser . parse ( filePath , fileContent )
244+ const report = getReport ( [ result ] , {
245+ ...DEFAULT_OPTIONS ,
246+ collapsed : 'never'
247+ } )
248+ // Report should not include collapsible details
249+ expect ( report ) . not . toContain ( '<details><summary>Expand for details</summary>' )
250+ expect ( report ) . not . toContain ( '</details>' )
251+ } )
252+
253+ it ( 'report auto-collapses only when all tests pass' , async ( ) => {
254+ // Test with a fixture that has passing tests (no failures)
255+ const fixturePath = path . join ( __dirname , 'fixtures' , 'jest-junit.xml' )
256+ const filePath = normalizeFilePath ( path . relative ( __dirname , fixturePath ) )
257+ const fileContent = fs . readFileSync ( fixturePath , { encoding : 'utf8' } )
258+
259+ const opts : ParseOptions = {
260+ parseErrors : true ,
261+ trackedFiles : [ ]
262+ }
263+
264+ const parser = new JestJunitParser ( opts )
265+ const result = await parser . parse ( filePath , fileContent )
266+
267+ // Check if this fixture has failures to determine expected behavior
268+ const hasFailed = result . failed > 0
269+
270+ const report = getReport ( [ result ] , {
271+ ...DEFAULT_OPTIONS ,
272+ collapsed : 'auto'
273+ } )
274+
275+ if ( hasFailed ) {
276+ // Should not collapse when there are failures
277+ expect ( report ) . not . toContain ( '<details><summary>Expand for details</summary>' )
278+ } else {
279+ // Should collapse when all tests pass
280+ expect ( report ) . toContain ( '<details><summary>Expand for details</summary>' )
281+ expect ( report ) . toContain ( '</details>' )
282+ }
283+ } )
210284} )
0 commit comments