Remove 'Details' column from Test case report

Stack traces doesn't fit well into the table - there was not enough width for it.  Now the stack traces are included in annotations which looks much better
This commit is contained in:
Michal Dorner 2020-11-29 20:07:32 +01:00
parent 63b94a335a
commit bff3069f5c
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
5 changed files with 34 additions and 96 deletions

View file

@ -2,7 +2,7 @@ import {Annotation, ParseOptions, TestResult} from '../test-parser'
import {parseStringPromise} from 'xml2js'
import {JunitReport, TestCase, TestSuite, TestSuites} from './jest-junit-types'
import {Align, Icon, link, table, exceptionCell} from '../../utils/markdown-utils'
import {Align, Icon, link, table} from '../../utils/markdown-utils'
import {normalizeFilePath} from '../../utils/file-utils'
import {slug} from '../../utils/slugger'
import {parseAttribute} from '../../utils/xml-utils'
@ -83,14 +83,13 @@ function getSuiteSummary(suite: TestSuite, index: number): string {
.map(grp => {
const header = grp.describe !== '' ? `#### ${grp.describe}\n\n` : ''
const tests = table(
['Result', 'Test', 'Time', 'Details'],
[Align.Center, Align.Left, Align.Right, Align.None],
['Result', 'Test', 'Time'],
[Align.Center, Align.Left, Align.Right],
...grp.tests.map(tc => {
const name = tc.$.name
const time = `${Math.round(tc.$.time * 1000)}ms`
const result = getTestCaseIcon(tc)
const ex = getTestCaseDetails(tc)
return [result, name, time, ex]
return [result, name, time]
})
)
@ -110,19 +109,6 @@ function getTestCaseIcon(test: TestCase): string {
return Icon.success
}
function getTestCaseDetails(test: TestCase): string {
if (test.skipped !== undefined) {
return 'Skipped'
}
if (test.failure !== undefined) {
const failure = test.failure.join('\n')
return exceptionCell(failure)
}
return ''
}
function makeSuiteSlug(index: number, name: string): {id: string; link: string} {
// use "ts-$index-" as prefix to avoid slug conflicts after escaping the paths
return slug(`ts-${index}-${name}`)

View file

@ -21,32 +21,12 @@ export function link(title: string, address: string): string {
type ToString = string | number | boolean | Date
export function table(headers: ToString[], align: ToString[], ...rows: ToString[][]): string {
const headerRow = `| ${headers.join(' | ')} |`
const headerRow = `| ${headers.map(tableEscape).join(' | ')} |`
const alignRow = `| ${align.join(' | ')} |`
const contentRows = rows.map(row => `| ${row.join(' | ')} |`).join('\n')
const contentRows = rows.map(row => `| ${row.map(tableEscape).join(' | ')} |`).join('\n')
return [headerRow, alignRow, contentRows].join('\n')
}
export function exceptionCell(ex: string): string {
const lines = ex.split(/\r?\n/)
if (lines.length === 0) {
return ''
}
const summary = tableEscape(lines.shift()?.trim() || '')
const emptyLine = /^\s*$/
const firstNonEmptyLine = lines.findIndex(l => !emptyLine.test(l))
if (firstNonEmptyLine === -1) {
return summary
}
const contentLines = firstNonEmptyLine > 0 ? lines.slice(firstNonEmptyLine) : lines
const content = '<pre>' + tableEscape(contentLines.join('<br>')) + '</pre>'
return details(summary, content)
}
export function tableEscape(content: string): string {
return content.replace('|', '\\|')
export function tableEscape(content: ToString): string {
return content.toString().replace('|', '\\|')
}