mirror of
https://github.com/dorny/test-reporter.git
synced 2026-05-06 10:37:36 +02:00
159 lines
5.8 KiB
TypeScript
159 lines
5.8 KiB
TypeScript
import {DEFAULT_OPTIONS, getBadge, getReport, ReportOptions} from '../../src/report/get-report.js'
|
|
import {TestCaseResult, TestGroupResult, TestRunResult, TestSuiteResult} from '../../src/test-results.js'
|
|
|
|
describe('getBadge', () => {
|
|
describe('URI encoding with special characters', () => {
|
|
it('generates correct URI with simple badge title', () => {
|
|
const options: ReportOptions = {
|
|
...DEFAULT_OPTIONS,
|
|
badgeTitle: 'tests'
|
|
}
|
|
const badge = getBadge(5, 0, 1, options)
|
|
expect(badge).toBe(
|
|
''
|
|
)
|
|
})
|
|
|
|
it('handles badge title with single hyphen', () => {
|
|
const options: ReportOptions = {
|
|
...DEFAULT_OPTIONS,
|
|
badgeTitle: 'unit-tests'
|
|
}
|
|
const badge = getBadge(3, 0, 0, options)
|
|
// The hyphen in the badge title should be encoded as --
|
|
expect(badge).toBe('')
|
|
})
|
|
|
|
it('handles badge title with multiple hyphens', () => {
|
|
const options: ReportOptions = {
|
|
...DEFAULT_OPTIONS,
|
|
badgeTitle: 'integration-api-tests'
|
|
}
|
|
const badge = getBadge(10, 0, 0, options)
|
|
// All hyphens in the title should be encoded as --
|
|
expect(badge).toBe(
|
|
''
|
|
)
|
|
})
|
|
|
|
it('handles badge title with multiple underscores', () => {
|
|
const options: ReportOptions = {
|
|
...DEFAULT_OPTIONS,
|
|
badgeTitle: 'my_integration_test'
|
|
}
|
|
const badge = getBadge(10, 0, 0, options)
|
|
// All underscores in the title should be encoded as __
|
|
expect(badge).toBe(
|
|
''
|
|
)
|
|
})
|
|
|
|
it('handles badge title with version format containing hyphen', () => {
|
|
const options: ReportOptions = {
|
|
...DEFAULT_OPTIONS,
|
|
badgeTitle: 'MariaDb 12.0-ubi database tests'
|
|
}
|
|
const badge = getBadge(1, 0, 0, options)
|
|
// The hyphen in "12.0-ubi" should be encoded as --
|
|
expect(badge).toBe(
|
|
''
|
|
)
|
|
})
|
|
|
|
it('handles badge title with dots and hyphens', () => {
|
|
const options: ReportOptions = {
|
|
...DEFAULT_OPTIONS,
|
|
badgeTitle: 'v1.2.3-beta-test'
|
|
}
|
|
const badge = getBadge(4, 1, 0, options)
|
|
expect(badge).toBe(
|
|
''
|
|
)
|
|
})
|
|
|
|
it('preserves structural hyphens between label and message', () => {
|
|
const options: ReportOptions = {
|
|
...DEFAULT_OPTIONS,
|
|
badgeTitle: 'test-suite'
|
|
}
|
|
const badge = getBadge(2, 3, 1, options)
|
|
// The URI should have literal hyphens separating title-message-color
|
|
expect(badge).toBe(
|
|
''
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('generates test outcome as color name for imgshields', () => {
|
|
it('uses success color when all tests pass', () => {
|
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
|
const badge = getBadge(5, 0, 0, options)
|
|
expect(badge).toContain('-success)')
|
|
})
|
|
|
|
it('uses critical color when tests fail', () => {
|
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
|
const badge = getBadge(5, 2, 0, options)
|
|
expect(badge).toContain('-critical)')
|
|
})
|
|
|
|
it('uses yellow color when no tests found', () => {
|
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
|
const badge = getBadge(0, 0, 0, options)
|
|
expect(badge).toContain('-yellow)')
|
|
})
|
|
})
|
|
|
|
describe('badge message composition', () => {
|
|
it('includes only passed count when no failures or skips', () => {
|
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
|
const badge = getBadge(5, 0, 0, options)
|
|
expect(badge).toBe('')
|
|
})
|
|
|
|
it('includes passed and failed counts', () => {
|
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
|
const badge = getBadge(5, 2, 0, options)
|
|
expect(badge).toBe('')
|
|
})
|
|
|
|
it('includes passed, failed and skipped counts', () => {
|
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
|
const badge = getBadge(5, 2, 1, options)
|
|
expect(badge).toBe(
|
|
''
|
|
)
|
|
})
|
|
|
|
it('uses "none" message when no tests', () => {
|
|
const options: ReportOptions = {...DEFAULT_OPTIONS}
|
|
const badge = getBadge(0, 0, 0, options)
|
|
expect(badge).toBe('')
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('getReport', () => {
|
|
it('sorts suites by descending time when configured', () => {
|
|
const results = [
|
|
new TestRunResult('report.xml', [
|
|
createSuite('unit', 10),
|
|
createSuite('integration', 30),
|
|
createSuite('smoke', 20)
|
|
])
|
|
]
|
|
|
|
const report = getReport(results, {
|
|
...DEFAULT_OPTIONS,
|
|
sortSuites: 'time-desc',
|
|
listTests: 'none'
|
|
})
|
|
|
|
expect(report.indexOf('integration')).toBeLessThan(report.indexOf('smoke'))
|
|
expect(report.indexOf('smoke')).toBeLessThan(report.indexOf('unit'))
|
|
})
|
|
})
|
|
|
|
function createSuite(name: string, time: number): TestSuiteResult {
|
|
return new TestSuiteResult(name, [new TestGroupResult(name, [new TestCaseResult(`${name}-test`, 'success', time)])])
|
|
}
|