Skip to content

Commit

Permalink
Merge pull request #123 from workgroupengineering/features/only-summary
Browse files Browse the repository at this point in the history
Add option to generate only the summary from processed test results files
  • Loading branch information
dorny authored Jun 22, 2021
2 parents e8f4fdf + 2ac8b44 commit ad831af
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 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.

5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit ad831af

Please sign in to comment.