Skip to content

Commit

Permalink
Support none for list-suites
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Xu authored and Zach Renner committed Jan 4, 2023
1 parent 49667db commit bd77050
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 57 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ jobs:
# Limits which test suites are listed:
# all
# failed
# none
list-suites: 'all'
# Limits which test cases are listed:
Expand Down
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ inputs:
Limits which test suites are listed. Supported options:
- all
- only-failed
- none
required: true
default: 'all'
list-tests:
Expand Down
48 changes: 25 additions & 23 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.

4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestReporter {
readonly path = core.getInput('path', {required: true})
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'
readonly listSuites = core.getInput('list-suites', {required: true}) as 'all' | 'failed' | 'none'
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'
Expand All @@ -49,7 +49,7 @@ class TestReporter {
constructor() {
this.octokit = github.getOctokit(this.token)

if (this.listSuites !== 'all' && this.listSuites !== 'failed') {
if (this.listSuites !== 'all' && this.listSuites !== 'failed' && this.listSuites !== 'none') {
core.setFailed(`Input parameter 'list-suites' has invalid value`)
return
}
Expand Down
64 changes: 33 additions & 31 deletions src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {slug} from '../utils/slugger'
const MAX_REPORT_LENGTH = 65535

export interface ReportOptions {
listSuites: 'all' | 'failed'
listSuites: 'all' | 'failed' | 'none'
listTests: 'all' | 'failed' | 'none'
baseUrl: string
onlySummary: boolean
Expand Down Expand Up @@ -166,37 +166,39 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s

function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOptions): string[] {
const sections: string[] = []

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

const time = formatTime(tr.time)
const headingLine2 =
tr.tests > 0
? `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`
: 'No tests found'
sections.push(headingLine2)

const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites
if (suites.length > 0) {
const suitesTable = table(
['Test suite', 'Passed', 'Failed', 'Skipped', 'Time'],
[Align.Left, Align.Right, Align.Right, Align.Right, Align.Right],
...suites.map((s, suiteIndex) => {
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 tsNameLink = skipLink ? tsName : link(tsName, tsAddr)
const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : ''
const failed = s.failed > 0 ? `${s.failed}${Icon.fail}` : ''
const skipped = s.skipped > 0 ? `${s.skipped}${Icon.skip}` : ''
return [tsNameLink, passed, failed, skipped, tsTime]
})
)
sections.push(suitesTable)

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

const time = formatTime(tr.time)
const headingLine2 =
tr.tests > 0
? `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`
: 'No tests found'
sections.push(headingLine2)

if (suites.length > 0) {
const suitesTable = table(
['Test suite', 'Passed', 'Failed', 'Skipped', 'Time'],
[Align.Left, Align.Right, Align.Right, Align.Right, Align.Right],
...suites.map((s, suiteIndex) => {
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 tsNameLink = skipLink ? tsName : link(tsName, tsAddr)
const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : ''
const failed = s.failed > 0 ? `${s.failed}${Icon.fail}` : ''
const skipped = s.skipped > 0 ? `${s.skipped}${Icon.skip}` : ''
return [tsNameLink, passed, failed, skipped, tsTime]
})
)
sections.push(suitesTable)
}
}

if (options.listTests !== 'none') {
Expand Down

0 comments on commit bd77050

Please sign in to comment.