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

Include stack trace into summary #61

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion __tests__/dotnet-trx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ describe('dotnet-trx tests', () => {
listTests: 'failed',
onlySummary: false,
slugPrefix: '',
baseUrl: ''
baseUrl: '',
stackTraceInSummary: false
}
const report = getReport([result], reportOptions)
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class TestReporter {
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 stackTraceInSummary = this.outputTo === 'step-summary' ? true : false
readonly token = core.getInput('token', {required: true})
readonly slugPrefix: string = ''
readonly octokit: InstanceType<typeof GitHub>
Expand Down Expand Up @@ -205,8 +206,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, onlySummary, slugPrefix, stackTraceInSummary} = this
const summary = getReport(results, {listSuites, listTests, baseUrl, slugPrefix, onlySummary, stackTraceInSummary})

core.info('Creating annotations')
const annotations = getAnnotations(results, this.maxAnnotations)
Expand Down
14 changes: 10 additions & 4 deletions src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ export interface ReportOptions {
slugPrefix: string
baseUrl: string
onlySummary: boolean
stackTraceInSummary: boolean
}

const defaultOptions: ReportOptions = {
listSuites: 'all',
listTests: 'all',
slugPrefix: '',
baseUrl: '',
onlySummary: false
onlySummary: false,
stackTraceInSummary: false
}

export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
Expand Down Expand Up @@ -239,9 +241,13 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe
const result = getResultIcon(tc.result)
sections.push(`${space}${result} ${tc.name}`)
if (tc.error) {
const lines = (tc.error.message ?? getFirstNonEmptyLine(tc.error.details)?.trim())
?.split(/\r?\n/g)
.map(l => '\t' + l)
let errorData = ''
if (options.stackTraceInSummary) {
errorData = tc.error.details ?? ''
} else {
errorData = tc.error.message ?? getFirstNonEmptyLine(tc.error.details)?.trim() ?? ''
}
const lines = errorData.split(/\r?\n/g).map(l => '\t' + l)
if (lines) {
sections.push(...lines)
}
Expand Down