@@ -207,4 +207,100 @@ 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 when all tests pass' , async ( ) => {
254+ // Test with a fixture that has all passing tests (no failures)
255+ const fixturePath = path . join ( __dirname , 'fixtures' , 'jest-junit-eslint.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+ // Verify this fixture has no failures
268+ expect ( result . failed ) . toBe ( 0 )
269+
270+ const report = getReport ( [ result ] , {
271+ ...DEFAULT_OPTIONS ,
272+ collapsed : 'auto'
273+ } )
274+
275+ // Should collapse when all tests pass
276+ expect ( report ) . toContain ( '<details><summary>Expand for details</summary>' )
277+ expect ( report ) . toContain ( '</details>' )
278+ } )
279+
280+ it ( 'report does not auto-collapse when tests fail' , async ( ) => {
281+ // Test with a fixture that has failing tests
282+ const fixturePath = path . join ( __dirname , 'fixtures' , 'jest-junit.xml' )
283+ const filePath = normalizeFilePath ( path . relative ( __dirname , fixturePath ) )
284+ const fileContent = fs . readFileSync ( fixturePath , { encoding : 'utf8' } )
285+
286+ const opts : ParseOptions = {
287+ parseErrors : true ,
288+ trackedFiles : [ ]
289+ }
290+
291+ const parser = new JestJunitParser ( opts )
292+ const result = await parser . parse ( filePath , fileContent )
293+
294+ // Verify this fixture has failures
295+ expect ( result . failed ) . toBeGreaterThan ( 0 )
296+
297+ const report = getReport ( [ result ] , {
298+ ...DEFAULT_OPTIONS ,
299+ collapsed : 'auto'
300+ } )
301+
302+ // Should not collapse when there are failures
303+ expect ( report ) . not . toContain ( '<details><summary>Expand for details</summary>' )
304+ expect ( report ) . not . toContain ( '</details>' )
305+ } )
210306} )
0 commit comments