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
|
|
@ -89,6 +89,14 @@ inputs:
|
|||
description: Customize badge title
|
||||
required: false
|
||||
default: 'tests'
|
||||
collapsed:
|
||||
description: |
|
||||
Controls whether test report details are collapsed or expanded. Supported options:
|
||||
- auto: Collapse only if all tests pass (default behavior)
|
||||
- always: Always collapse the report details
|
||||
- never: Always expand the report details
|
||||
required: false
|
||||
default: 'auto'
|
||||
token:
|
||||
description: GitHub Access Token
|
||||
required: false
|
||||
|
|
|
|||
19
dist/index.js
generated
vendored
19
dist/index.js
generated
vendored
|
|
@ -309,6 +309,7 @@ class TestReporter {
|
|||
useActionsSummary = core.getInput('use-actions-summary', { required: false }) === 'true';
|
||||
badgeTitle = core.getInput('badge-title', { required: false });
|
||||
reportTitle = core.getInput('report-title', { required: false });
|
||||
collapsed = core.getInput('collapsed', { required: false });
|
||||
token = core.getInput('token', { required: true });
|
||||
octokit;
|
||||
context = (0, github_utils_1.getCheckRunContext)();
|
||||
|
|
@ -401,7 +402,7 @@ class TestReporter {
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
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);
|
||||
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
|
||||
|
|
@ -415,7 +416,8 @@ class TestReporter {
|
|||
onlySummary,
|
||||
useActionsSummary,
|
||||
badgeTitle,
|
||||
reportTitle
|
||||
reportTitle,
|
||||
collapsed
|
||||
});
|
||||
core.info('Summary content:');
|
||||
core.info(summary);
|
||||
|
|
@ -443,7 +445,8 @@ class TestReporter {
|
|||
onlySummary,
|
||||
useActionsSummary,
|
||||
badgeTitle,
|
||||
reportTitle
|
||||
reportTitle,
|
||||
collapsed
|
||||
});
|
||||
core.info('Creating annotations');
|
||||
const annotations = (0, get_annotations_1.getAnnotations)(results, this.maxAnnotations);
|
||||
|
|
@ -1924,7 +1927,8 @@ exports.DEFAULT_OPTIONS = {
|
|||
onlySummary: false,
|
||||
useActionsSummary: true,
|
||||
badgeTitle: 'tests',
|
||||
reportTitle: ''
|
||||
reportTitle: '',
|
||||
collapsed: 'auto'
|
||||
};
|
||||
function getReport(results, options = exports.DEFAULT_OPTIONS) {
|
||||
core.info('Generating check run summary');
|
||||
|
|
@ -2031,7 +2035,10 @@ function getBadge(passed, failed, skipped, options) {
|
|||
function getTestRunsReport(testRuns, options) {
|
||||
const sections = [];
|
||||
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(` `);
|
||||
}
|
||||
|
|
@ -2056,7 +2063,7 @@ function getTestRunsReport(testRuns, options) {
|
|||
const suitesReports = testRuns.map((tr, i) => getSuitesReport(tr, i, options)).flat();
|
||||
sections.push(...suitesReports);
|
||||
}
|
||||
if (totalFailed === 0) {
|
||||
if (shouldCollapse) {
|
||||
sections.push(`</details>`);
|
||||
}
|
||||
return sections;
|
||||
|
|
|
|||
|
|
@ -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