Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to generate only the summary from processed test results files #123

Merged
merged 2 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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