Skip to content

Commit

Permalink
Merge pull request dorny#89 from dorny/fix-suite-links
Browse files Browse the repository at this point in the history
Use full URL to link test suites
  • Loading branch information
dorny authored Mar 31, 2021
2 parents f486461 + 4c2f9f3 commit 39f7ac7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
32 changes: 22 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,22 @@ class TestReporter {
results.push(tr)
}

core.info(`Creating check run ${name}`)
const createResp = await this.octokit.checks.create({
head_sha: this.context.sha,
name,
status: 'in_progress',
output: {
title: name,
summary: ''
},
...github.context.repo
})

core.info('Creating report summary')
const {listSuites, listTests} = this
const summary = getReport(results, {listSuites, listTests})
const baseUrl = createResp.data.html_url
const summary = getReport(results, {listSuites, listTests, baseUrl})

core.info('Creating annotations')
const annotations = getAnnotations(results, this.maxAnnotations)
Expand All @@ -157,10 +170,9 @@ class TestReporter {
const conclusion = isFailed ? 'failure' : 'success'
const icon = isFailed ? Icon.fail : Icon.success

core.info(`Creating check run with conclusion ${conclusion}`)
const resp = await this.octokit.checks.create({
head_sha: this.context.sha,
name,
core.info(`Updating check run conclusion (${conclusion}) and output`)
const resp = await this.octokit.checks.update({
check_run_id: createResp.data.id,
conclusion,
status: 'completed',
output: {
Expand Down
12 changes: 7 additions & 5 deletions src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const MAX_REPORT_LENGTH = 65535
export interface ReportOptions {
listSuites: 'all' | 'failed'
listTests: 'all' | 'failed' | 'none'
baseUrl: string
}

const defaultOptions: ReportOptions = {
listSuites: 'all',
listTests: 'all'
listTests: 'all',
baseUrl: ''
}

export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
Expand Down Expand Up @@ -134,7 +136,7 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
const tableData = testRuns.map((tr, runIndex) => {
const time = formatTime(tr.time)
const name = tr.path
const addr = makeRunSlug(runIndex).link
const addr = options.baseUrl + makeRunSlug(runIndex).link
const nameLink = link(name, addr)
const passed = tr.passed > 0 ? `${tr.passed}${Icon.success}` : ''
const failed = tr.failed > 0 ? `${tr.failed}${Icon.fail}` : ''
Expand All @@ -159,7 +161,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
const sections: string[] = []

const trSlug = makeRunSlug(runIndex)
const nameLink = `<a id="${trSlug.id}" href="${trSlug.link}">${tr.path}</a>`
const nameLink = `<a id="${trSlug.id}" href="${options.baseUrl + trSlug.link}">${tr.path}</a>`
const icon = getResultIcon(tr.result)
sections.push(`## ${icon}\xa0${nameLink}`)

Expand All @@ -179,7 +181,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 = makeSuiteSlug(runIndex, suiteIndex).link
const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).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}` : ''
Expand Down Expand Up @@ -214,7 +216,7 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe

const tsName = ts.name
const tsSlug = makeSuiteSlug(runIndex, suiteIndex)
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`
const tsNameLink = `<a id="${tsSlug.id}" href="${options.baseUrl + tsSlug.link}">${tsName}</a>`
const icon = getResultIcon(ts.result)
sections.push(`### ${icon}\xa0${tsNameLink}`)

Expand Down

0 comments on commit 39f7ac7

Please sign in to comment.