1
0
Fork 0
mirror of https://github.com/dorny/test-reporter.git synced 2026-05-07 02:57:36 +02:00

feat: add sort-suites input to order suites by time descending

Add a new 'sort-suites' input parameter that accepts 'name' (default,
alphabetical) or 'time-desc' (slowest first). This allows consumers
to surface the slowest test suites at the top of the report.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
alexanderthoren 2026-02-23 16:12:01 +01:00 committed by Jozef Izso
parent 093d99bd59
commit 0e1fe1690f
Failed to extract signature
4 changed files with 52 additions and 8 deletions

View file

@ -43,6 +43,7 @@ class TestReporter {
readonly pathReplaceBackslashes = core.getInput('path-replace-backslashes', {required: false}) === 'true'
readonly reporter = core.getInput('reporter', {required: true})
readonly listSuites = core.getInput('list-suites', {required: true}) as 'all' | 'failed' | 'none'
readonly sortSuites = core.getInput('sort-suites', {required: false}) as 'name' | 'time-desc'
readonly listTests = core.getInput('list-tests', {required: true}) as 'all' | 'failed' | 'none'
readonly maxAnnotations = parseInt(core.getInput('max-annotations', {required: true}))
readonly failOnError = core.getInput('fail-on-error', {required: true}) === 'true'
@ -66,6 +67,11 @@ class TestReporter {
return
}
if (this.sortSuites !== 'name' && this.sortSuites !== 'time-desc') {
core.setFailed(`Input parameter 'sort-suites' has invalid value`)
return
}
if (this.listTests !== 'all' && this.listTests !== 'failed' && this.listTests !== 'none') {
core.setFailed(`Input parameter 'list-tests' has invalid value`)
return
@ -177,7 +183,17 @@ class TestReporter {
}
}
const {listSuites, listTests, slugPrefix, onlySummary, useActionsSummary, badgeTitle, reportTitle, collapsed} = this
const {
listSuites,
sortSuites,
listTests,
slugPrefix,
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)
@ -190,6 +206,7 @@ class TestReporter {
results,
{
listSuites,
sortSuites,
listTests,
slugPrefix,
baseUrl,
@ -222,6 +239,7 @@ class TestReporter {
baseUrl = createResp.data.html_url as string
const summary = getReport(results, {
listSuites,
sortSuites,
listTests,
slugPrefix,
baseUrl,

View file

@ -12,6 +12,7 @@ export interface ReportOptions {
listSuites: 'all' | 'failed' | 'none'
listTests: 'all' | 'failed' | 'none'
slugPrefix: string
sortSuites: 'name' | 'time-desc'
baseUrl: string
onlySummary: boolean
useActionsSummary: boolean
@ -24,6 +25,7 @@ export const DEFAULT_OPTIONS: ReportOptions = {
listSuites: 'all',
listTests: 'all',
slugPrefix: '',
sortSuites: 'name',
baseUrl: '',
onlySummary: false,
useActionsSummary: true,
@ -37,7 +39,7 @@ export function getReport(
options: ReportOptions = DEFAULT_OPTIONS,
shortSummary = ''
): string {
applySort(results)
applySort(results, options)
const opts = {...options}
let lines = renderReport(results, opts, shortSummary)
@ -96,10 +98,14 @@ function trimReport(lines: string[], options: ReportOptions): string {
return reportLines.join('\n')
}
function applySort(results: TestRunResult[]): void {
function applySort(results: TestRunResult[], options: ReportOptions): void {
results.sort((a, b) => a.path.localeCompare(b.path, DEFAULT_LOCALE))
for (const res of results) {
res.suites.sort((a, b) => a.name.localeCompare(b.name, DEFAULT_LOCALE))
if (options.sortSuites === 'time-desc') {
res.suites.sort((a, b) => b.time - a.time)
} else {
res.suites.sort((a, b) => a.name.localeCompare(b.name, DEFAULT_LOCALE))
}
}
}