diff --git a/__tests__/jest-junit.test.ts b/__tests__/jest-junit.test.ts index 1628016..6fb6c64 100644 --- a/__tests__/jest-junit.test.ts +++ b/__tests__/jest-junit.test.ts @@ -250,8 +250,35 @@ describe('jest-junit tests', () => { expect(report).not.toContain('') }) - it('report auto-collapses only when all tests pass', async () => { - // Test with a fixture that has passing tests (no failures) + it('report auto-collapses when all tests pass', async () => { + // Test with a fixture that has all passing tests (no failures) + const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit-eslint.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) + + // Verify this fixture has no failures + expect(result.failed).toBe(0) + + const report = getReport([result], { + ...DEFAULT_OPTIONS, + collapsed: 'auto' + }) + + // Should collapse when all tests pass + expect(report).toContain('
Expand for details') + expect(report).toContain('
') + }) + + it('report does not auto-collapse when tests fail', async () => { + // Test with a fixture that has failing tests const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml') const filePath = normalizeFilePath(path.relative(__dirname, fixturePath)) const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'}) @@ -264,21 +291,16 @@ describe('jest-junit tests', () => { 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 + // Verify this fixture has failures + expect(result.failed).toBeGreaterThan(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('
') - } + // Should not collapse when there are failures + expect(report).not.toContain('
Expand for details') + expect(report).not.toContain('
') }) })