mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 13:57:09 +01:00
feat: add collapsed option to control report visibility
This commit is contained in:
parent
4a41472ca4
commit
828632acd0
4 changed files with 38 additions and 12 deletions
|
|
@ -49,6 +49,7 @@ class TestReporter {
|
|||
readonly useActionsSummary = core.getInput('use-actions-summary', {required: false}) === 'true'
|
||||
readonly badgeTitle = core.getInput('badge-title', {required: false})
|
||||
readonly reportTitle = core.getInput('report-title', {required: false})
|
||||
readonly collapsed = core.getInput('collapsed', {required: false}) as 'auto' | 'always' | 'never'
|
||||
readonly token = core.getInput('token', {required: true})
|
||||
readonly octokit: InstanceType<typeof GitHub>
|
||||
readonly context = getCheckRunContext()
|
||||
|
|
@ -166,7 +167,7 @@ class TestReporter {
|
|||
}
|
||||
}
|
||||
|
||||
const {listSuites, listTests, onlySummary, useActionsSummary, badgeTitle, reportTitle} = this
|
||||
const {listSuites, listTests, onlySummary, useActionsSummary, badgeTitle, reportTitle, collapsed} = this
|
||||
|
||||
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
|
||||
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
|
||||
|
|
@ -182,7 +183,8 @@ class TestReporter {
|
|||
onlySummary,
|
||||
useActionsSummary,
|
||||
badgeTitle,
|
||||
reportTitle
|
||||
reportTitle,
|
||||
collapsed
|
||||
})
|
||||
|
||||
core.info('Summary content:')
|
||||
|
|
@ -211,7 +213,8 @@ class TestReporter {
|
|||
onlySummary,
|
||||
useActionsSummary,
|
||||
badgeTitle,
|
||||
reportTitle
|
||||
reportTitle,
|
||||
collapsed
|
||||
})
|
||||
|
||||
core.info('Creating annotations')
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export interface ReportOptions {
|
|||
useActionsSummary: boolean
|
||||
badgeTitle: string
|
||||
reportTitle: string
|
||||
collapsed: 'auto' | 'always' | 'never'
|
||||
}
|
||||
|
||||
export const DEFAULT_OPTIONS: ReportOptions = {
|
||||
|
|
@ -25,7 +26,8 @@ export const DEFAULT_OPTIONS: ReportOptions = {
|
|||
onlySummary: false,
|
||||
useActionsSummary: true,
|
||||
badgeTitle: 'tests',
|
||||
reportTitle: ''
|
||||
reportTitle: '',
|
||||
collapsed: 'auto'
|
||||
}
|
||||
|
||||
export function getReport(results: TestRunResult[], options: ReportOptions = DEFAULT_OPTIONS): string {
|
||||
|
|
@ -154,7 +156,13 @@ export function getBadge(passed: number, failed: number, skipped: number, option
|
|||
function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): string[] {
|
||||
const sections: string[] = []
|
||||
const totalFailed = testRuns.reduce((sum, tr) => sum + tr.failed, 0)
|
||||
if (totalFailed === 0) {
|
||||
|
||||
// Determine if report should be collapsed based on collapsed option
|
||||
const shouldCollapse =
|
||||
options.collapsed === 'always' ||
|
||||
(options.collapsed === 'auto' && totalFailed === 0)
|
||||
|
||||
if (shouldCollapse) {
|
||||
sections.push(`<details><summary>Expand for details</summary>`)
|
||||
sections.push(` `)
|
||||
}
|
||||
|
|
@ -187,7 +195,7 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
|
|||
sections.push(...suitesReports)
|
||||
}
|
||||
|
||||
if (totalFailed === 0) {
|
||||
if (shouldCollapse) {
|
||||
sections.push(`</details>`)
|
||||
}
|
||||
return sections
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue