Merge pull request #123 from workgroupengineering/features/only-summary

Add option to generate only the summary from processed test results files
This commit is contained in:
Michal Dorner 2021-06-22 21:32:05 +02:00 committed by GitHub
commit ad831af420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 15 deletions

View file

@ -128,6 +128,11 @@ jobs:
# mocha-json
reporter: ''
# Allows you to generate only the summary.
# If enabled, the report will contain a table listing each test results file and the number of passed, failed, and skipped tests.
# Detailed listing of test suites and test cases will be skipped.
only-summary: 'false'
# Limits which test suites are listed:
# all
# failed

View file

@ -53,6 +53,13 @@ inputs:
working-directory:
description: Relative path under $GITHUB_WORKSPACE where the repository was checked out
required: false
only-summary:
description: |
Allows you to generate only the summary.
If enabled, the report will contain a table listing each test results file and the number of passed, failed, and skipped tests.
Detailed listing of test suites and test cases will be skipped.
default: 'false'
required: false
token:
description: GitHub Access Token
required: false

20
dist/index.js generated vendored
View file

@ -245,6 +245,7 @@ class TestReporter {
this.maxAnnotations = parseInt(core.getInput('max-annotations', { required: true }));
this.failOnError = core.getInput('fail-on-error', { required: true }) === 'true';
this.workDirInput = core.getInput('working-directory', { required: false });
this.onlySummary = core.getInput('only-summary', { required: false }) === 'true';
this.token = core.getInput('token', { required: true });
this.context = github_utils_1.getCheckRunContext();
this.octokit = github.getOctokit(this.token);
@ -337,9 +338,9 @@ class TestReporter {
...github.context.repo
});
core.info('Creating report summary');
const { listSuites, listTests } = this;
const { listSuites, listTests, onlySummary } = this;
const baseUrl = createResp.data.html_url;
const summary = get_report_1.getReport(results, { listSuites, listTests, baseUrl });
const summary = get_report_1.getReport(results, { listSuites, listTests, baseUrl, onlySummary });
core.info('Creating annotations');
const annotations = get_annotations_1.getAnnotations(results, this.maxAnnotations);
const isFailed = results.some(tr => tr.result === 'failed');
@ -947,7 +948,7 @@ class JavaJunitParser {
return undefined;
}
const failure = failures[0];
const details = typeof (failure) === 'object' ? failure._ : failure;
const details = typeof failure === 'object' ? failure._ : failure;
let filePath;
let line;
const src = this.exceptionThrowSource(details);
@ -959,7 +960,7 @@ class JavaJunitParser {
path: filePath,
line,
details,
message: typeof (failure) === 'object' ? failure.message : undefined
message: typeof failure === 'object' ? failure.message : undefined
};
}
exceptionThrowSource(stackTrace) {
@ -1350,7 +1351,8 @@ const MAX_REPORT_LENGTH = 65535;
const defaultOptions = {
listSuites: 'all',
listTests: 'all',
baseUrl: ''
baseUrl: '',
onlySummary: false
};
function getReport(results, options = defaultOptions) {
core.info('Generating check run summary');
@ -1448,7 +1450,7 @@ function getBadge(passed, failed, skipped) {
}
function getTestRunsReport(testRuns, options) {
const sections = [];
if (testRuns.length > 1) {
if (testRuns.length > 1 || options.onlySummary) {
const tableData = testRuns.map((tr, runIndex) => {
const time = markdown_utils_1.formatTime(tr.time);
const name = tr.path;
@ -1462,8 +1464,10 @@ function getTestRunsReport(testRuns, options) {
const resultsTable = markdown_utils_1.table(['Report', '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], ...tableData);
sections.push(resultsTable);
}
const suitesReports = testRuns.map((tr, i) => getSuitesReport(tr, i, options)).flat();
sections.push(...suitesReports);
if (options.onlySummary === false) {
const suitesReports = testRuns.map((tr, i) => getSuitesReport(tr, i, options)).flat();
sections.push(...suitesReports);
}
return sections;
}
function getSuitesReport(tr, runIndex, options) {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -39,6 +39,7 @@ class TestReporter {
readonly maxAnnotations = parseInt(core.getInput('max-annotations', {required: true}))
readonly failOnError = core.getInput('fail-on-error', {required: true}) === 'true'
readonly workDirInput = core.getInput('working-directory', {required: false})
readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true'
readonly token = core.getInput('token', {required: true})
readonly octokit: InstanceType<typeof GitHub>
readonly context = getCheckRunContext()
@ -160,9 +161,9 @@ class TestReporter {
})
core.info('Creating report summary')
const {listSuites, listTests} = this
const {listSuites, listTests, onlySummary} = this
const baseUrl = createResp.data.html_url
const summary = getReport(results, {listSuites, listTests, baseUrl})
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary})
core.info('Creating annotations')
const annotations = getAnnotations(results, this.maxAnnotations)

View file

@ -10,12 +10,14 @@ export interface ReportOptions {
listSuites: 'all' | 'failed'
listTests: 'all' | 'failed' | 'none'
baseUrl: string
onlySummary: boolean
}
const defaultOptions: ReportOptions = {
listSuites: 'all',
listTests: 'all',
baseUrl: ''
baseUrl: '',
onlySummary: false
}
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
@ -132,7 +134,7 @@ function getBadge(passed: number, failed: number, skipped: number): string {
function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): string[] {
const sections: string[] = []
if (testRuns.length > 1) {
if (testRuns.length > 1 || options.onlySummary) {
const tableData = testRuns.map((tr, runIndex) => {
const time = formatTime(tr.time)
const name = tr.path
@ -152,8 +154,10 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
sections.push(resultsTable)
}
const suitesReports = testRuns.map((tr, i) => getSuitesReport(tr, i, options)).flat()
sections.push(...suitesReports)
if (options.onlySummary === false) {
const suitesReports = testRuns.map((tr, i) => getSuitesReport(tr, i, options)).flat()
sections.push(...suitesReports)
}
return sections
}