Skip to content

Commit 828632a

Browse files
pespineljozefizso
authored andcommitted
feat: add collapsed option to control report visibility
1 parent 4a41472 commit 828632a

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ inputs:
8989
description: Customize badge title
9090
required: false
9191
default: 'tests'
92+
collapsed:
93+
description: |
94+
Controls whether test report details are collapsed or expanded. Supported options:
95+
- auto: Collapse only if all tests pass (default behavior)
96+
- always: Always collapse the report details
97+
- never: Always expand the report details
98+
required: false
99+
default: 'auto'
92100
token:
93101
description: GitHub Access Token
94102
required: false

dist/index.js

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class TestReporter {
4949
readonly useActionsSummary = core.getInput('use-actions-summary', {required: false}) === 'true'
5050
readonly badgeTitle = core.getInput('badge-title', {required: false})
5151
readonly reportTitle = core.getInput('report-title', {required: false})
52+
readonly collapsed = core.getInput('collapsed', {required: false}) as 'auto' | 'always' | 'never'
5253
readonly token = core.getInput('token', {required: true})
5354
readonly octokit: InstanceType<typeof GitHub>
5455
readonly context = getCheckRunContext()
@@ -166,7 +167,7 @@ class TestReporter {
166167
}
167168
}
168169

169-
const {listSuites, listTests, onlySummary, useActionsSummary, badgeTitle, reportTitle} = this
170+
const {listSuites, listTests, onlySummary, useActionsSummary, badgeTitle, reportTitle, collapsed} = this
170171

171172
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
172173
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
@@ -182,7 +183,8 @@ class TestReporter {
182183
onlySummary,
183184
useActionsSummary,
184185
badgeTitle,
185-
reportTitle
186+
reportTitle,
187+
collapsed
186188
})
187189

188190
core.info('Summary content:')
@@ -211,7 +213,8 @@ class TestReporter {
211213
onlySummary,
212214
useActionsSummary,
213215
badgeTitle,
214-
reportTitle
216+
reportTitle,
217+
collapsed
215218
})
216219

217220
core.info('Creating annotations')

src/report/get-report.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ReportOptions {
1616
useActionsSummary: boolean
1717
badgeTitle: string
1818
reportTitle: string
19+
collapsed: 'auto' | 'always' | 'never'
1920
}
2021

2122
export const DEFAULT_OPTIONS: ReportOptions = {
@@ -25,7 +26,8 @@ export const DEFAULT_OPTIONS: ReportOptions = {
2526
onlySummary: false,
2627
useActionsSummary: true,
2728
badgeTitle: 'tests',
28-
reportTitle: ''
29+
reportTitle: '',
30+
collapsed: 'auto'
2931
}
3032

3133
export function getReport(results: TestRunResult[], options: ReportOptions = DEFAULT_OPTIONS): string {
@@ -154,7 +156,13 @@ export function getBadge(passed: number, failed: number, skipped: number, option
154156
function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): string[] {
155157
const sections: string[] = []
156158
const totalFailed = testRuns.reduce((sum, tr) => sum + tr.failed, 0)
157-
if (totalFailed === 0) {
159+
160+
// Determine if report should be collapsed based on collapsed option
161+
const shouldCollapse =
162+
options.collapsed === 'always' ||
163+
(options.collapsed === 'auto' && totalFailed === 0)
164+
165+
if (shouldCollapse) {
158166
sections.push(`<details><summary>Expand for details</summary>`)
159167
sections.push(` `)
160168
}
@@ -187,7 +195,7 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
187195
sections.push(...suitesReports)
188196
}
189197

190-
if (totalFailed === 0) {
198+
if (shouldCollapse) {
191199
sections.push(`</details>`)
192200
}
193201
return sections

0 commit comments

Comments
 (0)