diff --git a/__tests__/jest-junit.test.ts b/__tests__/jest-junit.test.ts
index f4b8335..938cdd7 100644
--- a/__tests__/jest-junit.test.ts
+++ b/__tests__/jest-junit.test.ts
@@ -207,4 +207,78 @@ describe('jest-junit tests', () => {
// Report should have the title as the first line
expect(report).toMatch(/^# My Custom Title\n/)
})
+
+ it('report can be collapsed when configured', async () => {
+ const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
+ const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
+ const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
+
+ const opts: ParseOptions = {
+ parseErrors: true,
+ trackedFiles: []
+ }
+
+ const parser = new JestJunitParser(opts)
+ const result = await parser.parse(filePath, fileContent)
+ const report = getReport([result], {
+ ...DEFAULT_OPTIONS,
+ collapsed: 'always'
+ })
+ // Report should include collapsible details
+ expect(report).toContain('Expand for details
')
+ expect(report).toContain(' ')
+ })
+
+ it('report is not collapsed when configured to never', async () => {
+ const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
+ const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
+ const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
+
+ const opts: ParseOptions = {
+ parseErrors: true,
+ trackedFiles: []
+ }
+
+ const parser = new JestJunitParser(opts)
+ const result = await parser.parse(filePath, fileContent)
+ const report = getReport([result], {
+ ...DEFAULT_OPTIONS,
+ collapsed: 'never'
+ })
+ // Report should not include collapsible details
+ expect(report).not.toContain('Expand for details
')
+ expect(report).not.toContain(' ')
+ })
+
+ it('report auto-collapses only when all tests pass', async () => {
+ // Test with a fixture that has passing tests (no failures)
+ const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
+ const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
+ const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
+
+ const opts: ParseOptions = {
+ parseErrors: true,
+ trackedFiles: []
+ }
+
+ const parser = new JestJunitParser(opts)
+ const result = await parser.parse(filePath, fileContent)
+
+ // Check if this fixture has failures to determine expected behavior
+ const hasFailed = result.failed > 0
+
+ const report = getReport([result], {
+ ...DEFAULT_OPTIONS,
+ collapsed: 'auto'
+ })
+
+ if (hasFailed) {
+ // Should not collapse when there are failures
+ expect(report).not.toContain('Expand for details
')
+ } else {
+ // Should collapse when all tests pass
+ expect(report).toContain('Expand for details
')
+ expect(report).toContain(' ')
+ }
+ })
})
diff --git a/src/report/get-report.ts b/src/report/get-report.ts
index 08bea71..d893b0e 100644
--- a/src/report/get-report.ts
+++ b/src/report/get-report.ts
@@ -158,9 +158,7 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
const totalFailed = testRuns.reduce((sum, tr) => sum + tr.failed, 0)
// Determine if report should be collapsed based on collapsed option
- const shouldCollapse =
- options.collapsed === 'always' ||
- (options.collapsed === 'auto' && totalFailed === 0)
+ const shouldCollapse = options.collapsed === 'always' || (options.collapsed === 'auto' && totalFailed === 0)
if (shouldCollapse) {
sections.push(`Expand for details
`)