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:

6
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,6 +1524,8 @@ function getTestRunsReport(testRuns, options) {
}
function getSuitesReport(tr, runIndex, options) {
const sections = [];
const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites;
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);
@ -1533,7 +1535,6 @@ function getSuitesReport(tr, runIndex, options) {
? `**${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);
@ -1548,6 +1549,7 @@ function getSuitesReport(tr, runIndex, options) {
}));
sections.push(suitesTable);
}
}
if (options.listTests !== 'none') {
const tests = suites.map((ts, suiteIndex) => getTestsReport(ts, runIndex, suiteIndex, options)).flat();
if (tests.length > 1) {

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,7 +166,9 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOptions): string[] {
const sections: string[] = []
const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites
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)
@ -179,7 +181,6 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
: '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'],
@ -198,6 +199,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
)
sections.push(suitesTable)
}
}
if (options.listTests !== 'none') {
const tests = suites.map((ts, suiteIndex) => getTestsReport(ts, runIndex, suiteIndex, options)).flat()