Skip to content
Open
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
23 changes: 14 additions & 9 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.

6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TestReporter {
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 outputTo = core.getInput('output-to', {required: false})
readonly outputTo = core.getInput('output-to', {required: false}) as 'checks' | 'step-summary'
readonly token = core.getInput('token', {required: true})
readonly slugPrefix: string = ''
readonly octokit: InstanceType<typeof GitHub>
Expand Down Expand Up @@ -205,8 +205,8 @@ class TestReporter {
}

core.info('Creating report summary')
const {listSuites, listTests, onlySummary, slugPrefix} = this
const summary = getReport(results, {listSuites, listTests, baseUrl, slugPrefix, onlySummary})
const {listSuites, listTests, outputTo, onlySummary, slugPrefix} = this
const summary = getReport(results, {listSuites, listTests, outputTo, baseUrl, slugPrefix, onlySummary})

core.info('Creating annotations')
const annotations = getAnnotations(results, this.maxAnnotations)
Expand Down
21 changes: 14 additions & 7 deletions src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {getFirstNonEmptyLine} from '../utils/parse-utils'
import {slug} from '../utils/slugger'

const MAX_REPORT_LENGTH = 65535
const MAX_SUMMARY_LENGTH = 1048576

export interface ReportOptions {
listSuites: 'all' | 'failed'
listTests: 'all' | 'failed' | 'none'
outputTo: 'checks' | 'step-summary'
slugPrefix: string
baseUrl: string
onlySummary: boolean
Expand All @@ -17,6 +19,7 @@ export interface ReportOptions {
const defaultOptions: ReportOptions = {
listSuites: 'all',
listTests: 'all',
outputTo: 'checks',
slugPrefix: '',
baseUrl: '',
onlySummary: false
Expand All @@ -31,7 +34,7 @@ export function getReport(results: TestRunResult[], options: ReportOptions = def
let lines = renderReport(results, opts)
let report = lines.join('\n')

if (getByteLength(report) <= MAX_REPORT_LENGTH) {
if (getByteLength(report) <= getMaxReportLength(options)) {
return report
}

Expand All @@ -40,20 +43,24 @@ export function getReport(results: TestRunResult[], options: ReportOptions = def
opts.listTests = 'failed'
lines = renderReport(results, opts)
report = lines.join('\n')
if (getByteLength(report) <= MAX_REPORT_LENGTH) {
if (getByteLength(report) <= getMaxReportLength(options)) {
return report
}
}

core.warning(`Test report summary exceeded limit of ${MAX_REPORT_LENGTH} bytes and will be trimmed`)
return trimReport(lines)
core.warning(`Test report summary exceeded limit of ${getMaxReportLength(options)} bytes and will be trimmed`)
return trimReport(lines, options)
}

function trimReport(lines: string[]): string {
function getMaxReportLength(options: ReportOptions = defaultOptions): number {
return options.outputTo === 'step-summary' ? MAX_SUMMARY_LENGTH : MAX_REPORT_LENGTH
}

function trimReport(lines: string[], options: ReportOptions): string {
const closingBlock = '```'
const errorMsg = `**Report exceeded GitHub limit of ${MAX_REPORT_LENGTH} bytes and has been trimmed**`
const errorMsg = `**Report exceeded GitHub limit of ${getMaxReportLength(options)} bytes and has been trimmed**`
const maxErrorMsgLength = closingBlock.length + errorMsg.length + 2
const maxReportLength = MAX_REPORT_LENGTH - maxErrorMsgLength
const maxReportLength = getMaxReportLength(options) - maxErrorMsgLength

let reportLength = 0
let codeBlock = false
Expand Down