mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 14:27:10 +01:00
Implements jest-junit report parsing
This commit is contained in:
parent
7bda3b9f6f
commit
bc706859ad
11 changed files with 381 additions and 34 deletions
52
src/utils/markdown-utils.ts
Normal file
52
src/utils/markdown-utils.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
export enum Align {
|
||||
Left = ':---',
|
||||
Center = ':---:',
|
||||
Right = '---:',
|
||||
None = '---'
|
||||
}
|
||||
|
||||
export const Icon = {
|
||||
skip: '✖️', // ':heavy_multiplication_x:'
|
||||
success: '✔️', // ':heavy_check_mark:'
|
||||
fail: '❌' // ':x:'
|
||||
}
|
||||
|
||||
export function details(summary: string, content: string): string {
|
||||
return `<details><summary>${summary}</summary>${content}</details>`
|
||||
}
|
||||
|
||||
export function link(title: string, address: string): string {
|
||||
return `[${title}](${address})`
|
||||
}
|
||||
|
||||
type ToString = string | number | boolean | Date
|
||||
export function table(headers: ToString[], align: ToString[], ...rows: ToString[][]): string {
|
||||
const headerRow = `| ${headers.join(' | ')} |`
|
||||
const alignRow = `| ${align.join(' | ')} |`
|
||||
const contentRows = rows.map(row => `| ${row.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('|', '\\|')
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue