mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 13:57:09 +01:00
test: fix linter and create tests
This commit is contained in:
parent
828632acd0
commit
7148297f02
2 changed files with 75 additions and 3 deletions
|
|
@ -207,4 +207,78 @@ describe('jest-junit tests', () => {
|
||||||
// Report should have the title as the first line
|
// Report should have the title as the first line
|
||||||
expect(report).toMatch(/^# My Custom Title\n/)
|
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('<details><summary>Expand for details</summary>')
|
||||||
|
expect(report).toContain('</details>')
|
||||||
|
})
|
||||||
|
|
||||||
|
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('<details><summary>Expand for details</summary>')
|
||||||
|
expect(report).not.toContain('</details>')
|
||||||
|
})
|
||||||
|
|
||||||
|
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('<details><summary>Expand for details</summary>')
|
||||||
|
} else {
|
||||||
|
// Should collapse when all tests pass
|
||||||
|
expect(report).toContain('<details><summary>Expand for details</summary>')
|
||||||
|
expect(report).toContain('</details>')
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -158,9 +158,7 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
|
||||||
const totalFailed = testRuns.reduce((sum, tr) => sum + tr.failed, 0)
|
const totalFailed = testRuns.reduce((sum, tr) => sum + tr.failed, 0)
|
||||||
|
|
||||||
// Determine if report should be collapsed based on collapsed option
|
// Determine if report should be collapsed based on collapsed option
|
||||||
const shouldCollapse =
|
const shouldCollapse = options.collapsed === 'always' || (options.collapsed === 'auto' && totalFailed === 0)
|
||||||
options.collapsed === 'always' ||
|
|
||||||
(options.collapsed === 'auto' && totalFailed === 0)
|
|
||||||
|
|
||||||
if (shouldCollapse) {
|
if (shouldCollapse) {
|
||||||
sections.push(`<details><summary>Expand for details</summary>`)
|
sections.push(`<details><summary>Expand for details</summary>`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue