mirror of
https://github.com/dorny/test-reporter.git
synced 2026-02-04 05:27:55 +01:00
Merge 74f763ce28 into a810f9bf83
This commit is contained in:
commit
6af63810a7
6 changed files with 197 additions and 9 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import {getBadge, DEFAULT_OPTIONS, ReportOptions} from '../../src/report/get-report'
|
||||
import {DEFAULT_OPTIONS, getBadge, getReport, ReportOptions} from '../../src/report/get-report'
|
||||
import {TestCaseResult, TestGroupResult, TestRunResult, TestSuiteResult} from '../../src/test-results'
|
||||
|
||||
describe('getBadge', () => {
|
||||
describe('URI encoding with special characters', () => {
|
||||
|
|
@ -118,3 +119,144 @@ describe('getBadge', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('getReport', () => {
|
||||
// Helper function to create test results
|
||||
function createTestResult(path: string, passed: number, failed: number, skipped: number): TestRunResult {
|
||||
const tests: TestCaseResult[] = []
|
||||
for (let i = 0; i < passed; i++) {
|
||||
tests.push(new TestCaseResult(`passed-test-${i}`, 'success', 100))
|
||||
}
|
||||
for (let i = 0; i < failed; i++) {
|
||||
tests.push(new TestCaseResult(`failed-test-${i}`, 'failed', 100, {
|
||||
details: 'Test failed',
|
||||
message: 'Assertion error'
|
||||
}))
|
||||
}
|
||||
for (let i = 0; i < skipped; i++) {
|
||||
tests.push(new TestCaseResult(`skipped-test-${i}`, 'skipped', 0))
|
||||
}
|
||||
|
||||
const group = new TestGroupResult('test-group', tests)
|
||||
const suite = new TestSuiteResult('test-suite', [group])
|
||||
return new TestRunResult(path, [suite])
|
||||
}
|
||||
|
||||
describe('list-files parameter', () => {
|
||||
const results = [
|
||||
createTestResult('passing-file.spec.ts', 5, 0, 0),
|
||||
createTestResult('failing-file.spec.ts', 3, 2, 1),
|
||||
createTestResult('passing-with-skipped-file.spec.ts', 8, 0, 2)
|
||||
]
|
||||
|
||||
it('shows all files when list-files is "all"', () => {
|
||||
const report = getReport(results, {
|
||||
...DEFAULT_OPTIONS,
|
||||
listFiles: 'all',
|
||||
listSuites: 'none',
|
||||
listTests: 'none'
|
||||
})
|
||||
|
||||
expect(report).toContain('passing-file.spec.ts')
|
||||
expect(report).toContain('failing-file.spec.ts')
|
||||
expect(report).toContain('passing-with-skipped-file.spec.ts')
|
||||
})
|
||||
|
||||
it('shows only failed files when list-files is "failed"', () => {
|
||||
const report = getReport(results, {
|
||||
...DEFAULT_OPTIONS,
|
||||
listFiles: 'failed',
|
||||
listSuites: 'none',
|
||||
listTests: 'none'
|
||||
})
|
||||
|
||||
expect(report).not.toContain('passing-file.spec.ts')
|
||||
expect(report).toContain('failing-file.spec.ts')
|
||||
expect(report).not.toContain('passing-with-skipped-file.spec.ts')
|
||||
})
|
||||
|
||||
it('shows no file details when list-files is "none"', () => {
|
||||
const report = getReport(results, {
|
||||
...DEFAULT_OPTIONS,
|
||||
listFiles: 'none',
|
||||
listSuites: 'none',
|
||||
listTests: 'none'
|
||||
})
|
||||
|
||||
// Should still have badge
|
||||
expect(report).toContain('![')
|
||||
// Should not have file names in detail sections
|
||||
expect(report).not.toContain('passing-file.spec.ts')
|
||||
expect(report).not.toContain('failing-file.spec.ts')
|
||||
expect(report).not.toContain('passing-with-skipped-file.spec.ts')
|
||||
})
|
||||
|
||||
it('includes summary table even with list-files "none"', () => {
|
||||
const report = getReport(results, {
|
||||
...DEFAULT_OPTIONS,
|
||||
listFiles: 'none',
|
||||
listSuites: 'all',
|
||||
listTests: 'none'
|
||||
})
|
||||
|
||||
// Badge should still be present
|
||||
expect(report).toContain('![')
|
||||
expect(report).toContain('badge')
|
||||
// File names should not be present
|
||||
expect(report).not.toContain('passing-file.spec.ts')
|
||||
expect(report).not.toContain('failing-file.spec.ts')
|
||||
expect(report).not.toContain('passing-with-skipped-file.spec.ts')
|
||||
})
|
||||
|
||||
it('works correctly with list-suites and list-tests when list-files is "failed"', () => {
|
||||
const report = getReport(results, {
|
||||
...DEFAULT_OPTIONS,
|
||||
listFiles: 'failed',
|
||||
listSuites: 'all',
|
||||
listTests: 'all'
|
||||
})
|
||||
|
||||
expect(report).not.toContain('passing-file.spec.ts')
|
||||
expect(report).toContain('failing-file.spec.ts')
|
||||
expect(report).not.toContain('passing-with-skipped-file.spec.ts')
|
||||
// Should show suite details for the failed file
|
||||
expect(report).toContain('test-suite')
|
||||
})
|
||||
|
||||
it('filters correctly when all files pass and list-files is "failed"', () => {
|
||||
const allPassingResults = [
|
||||
createTestResult('passing-file-1.spec.ts', 5, 0, 0),
|
||||
createTestResult('passing-file-2.spec.ts', 8, 0, 2)
|
||||
]
|
||||
|
||||
const report = getReport(allPassingResults, {
|
||||
...DEFAULT_OPTIONS,
|
||||
listFiles: 'failed',
|
||||
listSuites: 'all',
|
||||
listTests: 'none'
|
||||
})
|
||||
|
||||
expect(report).not.toContain('passing-file-1.spec.ts')
|
||||
expect(report).not.toContain('passing-file-2.spec.ts')
|
||||
// Badge should still be present
|
||||
expect(report).toContain('![')
|
||||
expect(report).toContain('badge')
|
||||
})
|
||||
|
||||
it('filters correctly when all files fail and list-files is "failed"', () => {
|
||||
const allFailingResults = [
|
||||
createTestResult('failing-file-1.spec.ts', 0, 5, 0),
|
||||
createTestResult('failing-file-2.spec.ts', 1, 2, 1)
|
||||
]
|
||||
|
||||
const report = getReport(allFailingResults, {
|
||||
...DEFAULT_OPTIONS,
|
||||
listFiles: 'failed',
|
||||
listSuites: 'all',
|
||||
listTests: 'none'
|
||||
})
|
||||
|
||||
expect(report).toContain('failing-file-1.spec.ts')
|
||||
expect(report).toContain('failing-file-2.spec.ts')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue