forked from mikepenz/action-junit-report
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtable.ts
143 lines (132 loc) · 4.66 KB
/
table.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import * as core from '@actions/core'
// eslint-disable-next-line import/extensions
import {SummaryTableRow} from '@actions/core/lib/summary.js'
import {ActualTestResult, TestResult} from './testParser.js'
export function buildSummaryTables(
testResults: TestResult[],
includePassed: boolean,
detailedSummary: boolean,
flakySummary: boolean,
verboseSummary: boolean,
skipSuccessSummary: boolean,
groupSuite = false
): [SummaryTableRow[], SummaryTableRow[], SummaryTableRow[]] {
// only include a warning icon if there are skipped tests
const hasPassed = testResults.some(testResult => testResult.passed > 0)
const hasSkipped = testResults.some(testResult => testResult.skipped > 0)
const hasFailed = testResults.some(testResult => testResult.failed > 0)
const hasTests = testResults.some(testResult => testResult.totalCount > 0)
if (skipSuccessSummary && !hasFailed) {
// if we have skip success summary enabled, and we don't have any test failures, return empty tables
return [[], [], []]
}
const passedHeader = hasTests ? (hasPassed ? (hasFailed ? 'Passed ☑️' : 'Passed ✅') : 'Passed') : 'Passed ❌️'
const skippedHeader = hasSkipped ? 'Skipped ⚠️' : 'Skipped'
const failedHeader = hasFailed ? 'Failed ❌️' : 'Failed'
const table: SummaryTableRow[] = [
[
{data: '', header: true},
{data: 'Tests', header: true},
{data: passedHeader, header: true},
{data: skippedHeader, header: true},
{data: failedHeader, header: true}
]
]
const detailsTable: SummaryTableRow[] = !detailedSummary
? []
: [
[
{data: 'Test', header: true},
{data: 'Result', header: true}
]
]
const flakyTable: SummaryTableRow[] = !flakySummary
? []
: [
[
{data: 'Test', header: true},
{data: 'Retries', header: true}
]
]
for (const testResult of testResults) {
table.push([
`${testResult.checkName}`,
`${testResult.totalCount} ran`,
`${testResult.passed} passed`,
`${testResult.skipped} skipped`,
`${testResult.failed} failed`
])
const annotations = testResult.globalAnnotations.filter(
annotation => includePassed || annotation.annotation_level !== 'notice'
)
if (annotations.length === 0) {
if (!includePassed) {
core.info(
`⚠️ No annotations found for ${testResult.checkName}. If you want to include passed results in this table please configure 'include_passed' as 'true'`
)
}
if (verboseSummary) {
detailsTable.push([{data: `No test annotations available`, colspan: '2'}])
}
} else {
if (detailedSummary) {
detailsTable.push([{data: `<strong>${testResult.checkName}</strong>`, colspan: '2'}])
if (!groupSuite) {
for (const annotation of annotations) {
detailsTable.push([
`${annotation.title}`,
`${
annotation.status === 'success'
? '✅ pass'
: annotation.status === 'skipped'
? `⚠️️ skipped`
: `❌ ${annotation.annotation_level}`
}`
])
}
} else {
for (const internalTestResult of testResult.testResults) {
appendDetailsTable(internalTestResult, detailsTable, includePassed)
}
}
}
if (flakySummary) {
const flakyAnnotations = annotations.filter(annotation => annotation.retries > 0)
if (flakyAnnotations.length > 0) {
flakyTable.push([{data: `<strong>${testResult.checkName}</strong>`, colspan: '2'}])
for (const annotation of flakyAnnotations) {
flakyTable.push([`${annotation.title}`, `${annotation.retries}`])
}
}
}
}
}
return [table, detailsTable, flakyTable]
}
function appendDetailsTable(
testResult: ActualTestResult,
detailsTable: SummaryTableRow[],
includePassed: boolean
): void {
const annotations = testResult.annotations.filter(
annotation => includePassed || annotation.annotation_level !== 'notice'
)
if (annotations.length > 0) {
detailsTable.push([{data: `<em>${testResult.name}</em>`, colspan: '2'}])
for (const annotation of annotations) {
detailsTable.push([
`${annotation.title}`,
`${
annotation.status === 'success'
? '✅ pass'
: annotation.status === 'skipped'
? `⚠️️ skipped`
: `❌ ${annotation.annotation_level}`
}`
])
}
}
for (const childTestResult of testResult.testResults) {
appendDetailsTable(childTestResult, detailsTable, includePassed)
}
}