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 # mocha-json
reporter: '' 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: # Limits which test suites are listed:
# all # all
# failed # failed

View file

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

View file

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