Support none for list-suites

This commit is contained in:
Ray Xu 2022-04-24 22:07:42 +00:00 committed by Zach Renner
parent 49667db475
commit bd77050543
6 changed files with 63 additions and 57 deletions

View file

@ -141,6 +141,7 @@ jobs:
# Limits which test suites are listed:
# all
# failed
# none
list-suites: 'all'
# Limits which test cases are listed:

View file

@ -37,6 +37,7 @@ inputs:
Limits which test suites are listed. Supported options:
- all
- only-failed
- none
required: true
default: 'all'
list-tests:

48
dist/index.js generated vendored
View file

@ -298,7 +298,7 @@ class TestReporter {
this.token = core.getInput('token', { required: true });
this.context = (0, github_utils_1.getCheckRunContext)();
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;
}
@ -1524,29 +1524,31 @@ function getTestRunsReport(testRuns, options) {
}
function getSuitesReport(tr, runIndex, options) {
const sections = [];
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 = (0, markdown_utils_1.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 = (0, markdown_utils_1.table)(['Test suite', 'Passed', 'Failed', 'Skipped', 'Time'], [markdown_utils_1.Align.Left, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right], ...suites.map((s, suiteIndex) => {
const tsTime = (0, markdown_utils_1.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 : (0, markdown_utils_1.link)(tsName, tsAddr);
const passed = s.passed > 0 ? `${s.passed}${markdown_utils_1.Icon.success}` : '';
const failed = s.failed > 0 ? `${s.failed}${markdown_utils_1.Icon.fail}` : '';
const skipped = s.skipped > 0 ? `${s.skipped}${markdown_utils_1.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 = (0, markdown_utils_1.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 = (0, markdown_utils_1.table)(['Test suite', 'Passed', 'Failed', 'Skipped', 'Time'], [markdown_utils_1.Align.Left, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right], ...suites.map((s, suiteIndex) => {
const tsTime = (0, markdown_utils_1.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 : (0, markdown_utils_1.link)(tsName, tsAddr);
const passed = s.passed > 0 ? `${s.passed}${markdown_utils_1.Icon.success}` : '';
const failed = s.failed > 0 ? `${s.failed}${markdown_utils_1.Icon.fail}` : '';
const skipped = s.skipped > 0 ? `${s.skipped}${markdown_utils_1.Icon.skip}` : '';
return [tsNameLink, passed, failed, skipped, tsTime];
}));
sections.push(suitesTable);
}
}
if (options.listTests !== 'none') {
const tests = suites.map((ts, suiteIndex) => getTestsReport(ts, runIndex, suiteIndex, options)).flat();

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -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'
@ -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
}

View file

@ -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
@ -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') {