Fix broken links in report summary

Resolves #566
This commit is contained in:
Michael Marcus 2025-03-25 14:35:49 -04:00
parent 6e6a65b7a0
commit 314ef1dd49
19 changed files with 667 additions and 664 deletions

View file

@ -185,7 +185,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites
if (options.listSuites !== 'none') {
const trSlug = makeRunSlug(runIndex)
const trSlug = makeRunSlug(runIndex, options)
const nameLink = `<a id="${trSlug.id}" href="${options.baseUrl + trSlug.link}">${tr.path}</a>`
const icon = getResultIcon(tr.result)
sections.push(`## ${icon}\xa0${nameLink}`)
@ -205,7 +205,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
const tsTime = formatTime(s.time)
const tsName = s.name
const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed')
const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link
const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex, options).link
const tsNameLink = skipLink ? tsName : link(tsName, tsAddr)
const passed = s.passed > 0 ? `${s.passed} ${Icon.success}` : ''
const failed = s.failed > 0 ? `${s.failed} ${Icon.fail}` : ''
@ -240,7 +240,7 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe
const sections: string[] = []
const tsName = ts.name
const tsSlug = makeSuiteSlug(runIndex, suiteIndex)
const tsSlug = makeSuiteSlug(runIndex, suiteIndex, options)
const tsNameLink = `<a id="${tsSlug.id}" href="${options.baseUrl + tsSlug.link}">${tsName}</a>`
const icon = getResultIcon(ts.result)
sections.push(`### ${icon}\xa0${tsNameLink}`)
@ -269,14 +269,14 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe
return sections
}
function makeRunSlug(runIndex: number): {id: string; link: string} {
function makeRunSlug(runIndex: number, options: ReportOptions): {id: string; link: string} {
// use prefix to avoid slug conflicts after escaping the paths
return slug(`r${runIndex}`)
return slug(`r${runIndex}`, options)
}
function makeSuiteSlug(runIndex: number, suiteIndex: number): {id: string; link: string} {
function makeSuiteSlug(runIndex: number, suiteIndex: number, options: ReportOptions): {id: string; link: string} {
// use prefix to avoid slug conflicts after escaping the paths
return slug(`r${runIndex}s${suiteIndex}`)
return slug(`r${runIndex}s${suiteIndex}`, options)
}
function getResultIcon(result: TestExecutionResult): string {

View file

@ -1,7 +1,9 @@
// Returns HTML element id and href link usable as manual anchor links
// This is needed because Github in check run summary doesn't automatically
// create links out of headings as it normally does for other markdown content
export function slug(name: string): {id: string; link: string} {
import {ReportOptions} from '../report/get-report'
export function slug(name: string, options: ReportOptions): {id: string; link: string} {
const slugId = name
.trim()
.replace(/_/g, '')
@ -9,6 +11,7 @@ export function slug(name: string): {id: string; link: string} {
.replace(/[^\w-]/g, '')
const id = `user-content-${slugId}`
const link = `#${slugId}`
// When using the Action Summary for display, links must include the "user-content-" prefix.
const link = options.useActionsSummary ? `#${id}` : `#${slugId}`
return {id, link}
}