Skip to content

Commit 72cfc3b

Browse files
Feat/conditionally show failed/flaky/skipped reports based on results (#167)
1 parent ec7e4ee commit 72cfc3b

File tree

10 files changed

+1265
-99
lines changed

10 files changed

+1265
-99
lines changed

__tests__/ctrf/report-preparation.test.ts

Lines changed: 601 additions & 0 deletions
Large diffs are not rendered by default.

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 304 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reports/flaky-table.hbs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ctrf/report-preparation.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import {
1010
import { stripAnsiFromErrors } from './helpers'
1111
import { processPreviousResultsAndMetrics } from './metrics'
1212
import { convertJUnitToCTRFReport } from 'junit-to-ctrf'
13+
import {
14+
numberOfReportsEnabled,
15+
isAnyFailedOnlyReportEnabled,
16+
isAnyFlakyOnlyReportEnabled,
17+
isAnySkippedReportEnabled
18+
} from '../utils/report-utils'
1319

1420
/**
1521
* Prepares a CTRF report by applying various processing steps, including
@@ -59,6 +65,8 @@ export async function prepareReport(
5965
)
6066
}
6167

68+
report = addFooterDisplayFlags(report, inputs)
69+
6270
if (inputs.writeCtrfToFile) writeReportToFile(inputs.writeCtrfToFile, report)
6371

6472
return report
@@ -116,3 +124,102 @@ function shouldProcessPreviousResults(inputs: Inputs): boolean {
116124
function hasJunitIntegration(inputs: Inputs): boolean {
117125
return Boolean(inputs.integrationsConfig?.['junit-to-ctrf'])
118126
}
127+
128+
/**
129+
* Adds boolean flags to determine what to display for failed, flaky and skipped test reports.
130+
*
131+
* @param report - The CTRF report to enhance.
132+
* @param inputs - The user-provided inputs.
133+
* @returns The enhanced CTRF report with display flags.
134+
*/
135+
export function addFooterDisplayFlags(
136+
report: CtrfReport,
137+
inputs: Inputs
138+
): CtrfReport {
139+
if (!report.results.summary.extra) {
140+
report.results.summary.extra = {
141+
flakyRate: 0,
142+
flakyRateChange: 0,
143+
failRate: 0,
144+
failRateChange: 0,
145+
finalResults: 0,
146+
finalFailures: 0,
147+
includeFailedReportCurrentFooter: false,
148+
includeFlakyReportCurrentFooter: false,
149+
includeFailedReportAllFooter: false,
150+
includeFlakyReportAllFooter: false,
151+
includeMeasuredOverFooter: false,
152+
includeSkippedReportCurrentFooter: false,
153+
includeSkippedReportAllFooter: false,
154+
showSkippedReports: true,
155+
showFailedReports: true,
156+
showFlakyReports: true
157+
}
158+
} else {
159+
report.results.summary.extra.includeFailedReportCurrentFooter = false
160+
report.results.summary.extra.includeFailedReportAllFooter = false
161+
report.results.summary.extra.includeFlakyReportCurrentFooter = false
162+
report.results.summary.extra.includeFlakyReportAllFooter = false
163+
report.results.summary.extra.includeSkippedReportCurrentFooter = false
164+
report.results.summary.extra.showSkippedReports = true
165+
report.results.summary.extra.showFailedReports = true
166+
report.results.summary.extra.showFlakyReports = true
167+
}
168+
169+
const includesPreviousResults =
170+
(report.results.extra?.previousReports?.length ?? 0) > 0
171+
172+
let numOfReportsEnabled = numberOfReportsEnabled(inputs)
173+
// If no reports are enabled, set to 5 to show default reports
174+
numOfReportsEnabled = numOfReportsEnabled === 0 ? 5 : numOfReportsEnabled
175+
176+
const flakyThisRun = report.results.tests.some(test => test.flaky === true)
177+
const failsThisRun = report.results.summary.failed > 0
178+
179+
const flakyAllRuns = (report.results.summary.extra.totalFlakyTests ?? 0) > 0
180+
const failsAllRuns = (report.results.summary.extra.finalFailures ?? 0) > 0
181+
182+
const skippedThisRun = report.results.summary.skipped > 0
183+
184+
if (skippedThisRun === false) {
185+
report.results.summary.extra.includeSkippedReportCurrentFooter =
186+
isAnySkippedReportEnabled(inputs) && numOfReportsEnabled > 1
187+
if (numOfReportsEnabled > 1) {
188+
report.results.summary.extra.showSkippedReports = false
189+
}
190+
}
191+
if (includesPreviousResults) {
192+
report.results.summary.extra.includeMeasuredOverFooter = true
193+
if (flakyAllRuns === false) {
194+
report.results.summary.extra.includeFlakyReportAllFooter =
195+
isAnyFlakyOnlyReportEnabled(inputs) && numOfReportsEnabled > 1
196+
if (numOfReportsEnabled > 1) {
197+
report.results.summary.extra.showFlakyReports = false
198+
}
199+
}
200+
if (failsAllRuns === false) {
201+
report.results.summary.extra.includeFailedReportAllFooter =
202+
isAnyFailedOnlyReportEnabled(inputs) && numOfReportsEnabled > 1
203+
if (numOfReportsEnabled > 1) {
204+
report.results.summary.extra.showFailedReports = false
205+
}
206+
}
207+
return report
208+
} else {
209+
if (flakyThisRun === false) {
210+
report.results.summary.extra.includeFlakyReportCurrentFooter =
211+
isAnyFlakyOnlyReportEnabled(inputs) && numOfReportsEnabled > 1
212+
if (numOfReportsEnabled > 1) {
213+
report.results.summary.extra.showFlakyReports = false
214+
}
215+
}
216+
if (failsThisRun === false) {
217+
report.results.summary.extra.includeFailedReportCurrentFooter =
218+
isAnyFailedOnlyReportEnabled(inputs) && numOfReportsEnabled > 1
219+
if (numOfReportsEnabled > 1) {
220+
report.results.summary.extra.showFailedReports = false
221+
}
222+
}
223+
return report
224+
}
225+
}

src/github/core.ts

Lines changed: 132 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as core from '@actions/core'
2-
import { limitPreviousReports, stripAnsi } from '../ctrf'
2+
import { limitPreviousReports, stripAnsi, getEmoji } from '../ctrf'
33
import { generateMarkdown } from '../handlebars/core'
44
import { Inputs, CtrfReport } from '../types'
55
import { readTemplate, reportTypeToInputKey } from '../utils'
66
import { BuiltInReports, getBasePath } from '../reports/core'
77
import { COMMUNITY_REPORTS_PATH } from '../config'
88
import { DEFAULT_REPORT_ORDER } from '../reports/constants'
99
import { join } from 'path'
10+
import { isAnyReportEnabled } from '../utils/report-utils'
1011

1112
/**
1213
* Generates various views of the CTRF report and adds them to the GitHub Actions summary.
@@ -19,39 +20,30 @@ export function generateViews(inputs: Inputs, report: CtrfReport): void {
1920
core.summary.addHeading(inputs.title, 2).addEOL().addEOL()
2021
}
2122

22-
const isAnyReportEnabled =
23-
inputs.summaryReport ||
24-
inputs.githubReport ||
25-
inputs.failedReport ||
26-
inputs.flakyReport ||
27-
inputs.flakyRateReport ||
28-
inputs.failedFoldedReport ||
29-
inputs.failRateReport ||
30-
inputs.previousResultsReport ||
31-
inputs.aiReport ||
32-
inputs.skippedReport ||
33-
inputs.testReport ||
34-
inputs.testListReport ||
35-
inputs.suiteFoldedReport ||
36-
inputs.suiteListReport ||
37-
inputs.pullRequestReport ||
38-
inputs.commitReport ||
39-
inputs.customReport ||
40-
inputs.communityReport ||
41-
inputs.insightsReport ||
42-
inputs.slowestReport
43-
44-
if (!isAnyReportEnabled) {
23+
if (!isAnyReportEnabled(inputs)) {
4524
core.info(
4625
'No specific report selected. Generating default reports: summary, failed, flaky, skipped, and tests.'
4726
)
4827

4928
addViewToSummary('### Summary', BuiltInReports.SummaryTable, report)
50-
addViewToSummary('### Failed Tests', BuiltInReports.FailedTable, report)
51-
addViewToSummary('### Flaky Tests', BuiltInReports.FlakyTable, report)
52-
addViewToSummary('### Skipped', BuiltInReports.SkippedTable, report)
29+
if (report.results.summary.extra?.showFailedReports) {
30+
addViewToSummary('### Failed Tests', BuiltInReports.FailedTable, report)
31+
} else {
32+
core.info('No failed tests to display, skipping failed-report')
33+
}
34+
if (report.results.summary.extra?.showFlakyReports) {
35+
addViewToSummary('### Flaky Tests', BuiltInReports.FlakyTable, report)
36+
} else {
37+
core.info('No flaky tests to display, skipping flaky-report')
38+
}
39+
if (report.results.summary.extra?.showSkippedReports) {
40+
addViewToSummary('### Skipped', BuiltInReports.SkippedTable, report)
41+
} else {
42+
core.info('No skipped tests to display, skipping skipped-report')
43+
}
5344
addViewToSummary('### Tests', BuiltInReports.TestTable, report)
5445

46+
addReportFooters(report, inputs, false)
5547
addFooter()
5648
return
5749
}
@@ -116,16 +108,7 @@ export function generateViews(inputs: Inputs, report: CtrfReport): void {
116108
hasPreviousResultsReports = true
117109
}
118110
}
119-
120-
if (hasPreviousResultsReports && report.results.summary.extra?.reportsUsed) {
121-
core.summary
122-
.addRaw(
123-
`<sub><i>Measured over ${report.results.summary.extra.reportsUsed} runs.</i></sub>`
124-
)
125-
.addEOL()
126-
.addEOL()
127-
}
128-
111+
addReportFooters(report, inputs, hasPreviousResultsReports)
129112
addFooter()
130113
}
131114

@@ -138,6 +121,64 @@ function addFooter(): void {
138121
)
139122
}
140123

124+
/**
125+
* Adds appropriate footers based on the report's footer display flags
126+
*/
127+
function addReportFooters(
128+
report: CtrfReport,
129+
inputs: Inputs,
130+
hasPreviousResultsReports: boolean
131+
): void {
132+
const extra = report.results.summary.extra
133+
const footerMessages: string[] = []
134+
135+
if (extra?.includeFailedReportCurrentFooter) {
136+
footerMessages.push(`🎉 No failed tests in this run.`)
137+
}
138+
if (extra?.includeFailedReportAllFooter) {
139+
footerMessages.push(`🎉 No failed tests detected across all runs.`)
140+
}
141+
if (extra?.includeFlakyReportCurrentFooter) {
142+
footerMessages.push(`${getEmoji('flaky')} No flaky tests in this run.`)
143+
}
144+
if (extra?.includeFlakyReportAllFooter) {
145+
footerMessages.push(
146+
`${getEmoji('flaky')} No flaky tests detected across all runs.`
147+
)
148+
}
149+
if (extra?.includeSkippedReportCurrentFooter) {
150+
footerMessages.push(`${getEmoji('skipped')} No skipped tests in this run.`)
151+
}
152+
153+
if (
154+
extra?.includeMeasuredOverFooter &&
155+
extra?.reportsUsed &&
156+
hasPreviousResultsReports
157+
) {
158+
footerMessages.push(
159+
`${getEmoji('duration')} Measured over ${extra.reportsUsed} runs.`
160+
)
161+
}
162+
163+
const hasHiddenReports =
164+
extra?.includeFailedReportCurrentFooter ||
165+
extra?.includeFailedReportAllFooter ||
166+
extra?.includeFlakyReportCurrentFooter ||
167+
extra?.includeFlakyReportAllFooter ||
168+
extra?.includeSkippedReportCurrentFooter
169+
170+
if (hasHiddenReports) {
171+
footerMessages.push(`📋 Some reports are hidden`)
172+
}
173+
174+
if (footerMessages.length > 0) {
175+
core.summary
176+
.addRaw(`<sub><i>${footerMessages.join(' | ')}</i></sub>`)
177+
.addEOL()
178+
.addEOL()
179+
}
180+
}
181+
141182
/**
142183
* Generates a specific report based on the report type
143184
*
@@ -172,32 +213,72 @@ function generateReportByType(
172213
addViewToSummary('### Insights', BuiltInReports.InsightsTable, report)
173214
break
174215
case 'failed-report':
175-
core.info('Adding failed tests report to summary')
176-
addViewToSummary('### Failed Tests', BuiltInReports.FailedTable, report)
216+
if (report.results.summary.extra?.showFailedReports) {
217+
core.info('Adding failed tests report to summary')
218+
addViewToSummary('### Failed Tests', BuiltInReports.FailedTable, report)
219+
} else {
220+
core.info('No failed tests to display, skipping failed-report')
221+
}
177222
break
178223
case 'fail-rate-report':
179-
core.info('Adding fail rate report to summary')
180-
addViewToSummary('### Failed Rate', BuiltInReports.FailRateTable, report)
224+
if (report.results.summary.extra?.showFailedReports) {
225+
core.info('Adding fail rate report to summary')
226+
addViewToSummary(
227+
'### Failed Rate',
228+
BuiltInReports.FailRateTable,
229+
report
230+
)
231+
} else {
232+
core.info('No failed tests to display, skipping fail-rate-report')
233+
}
181234
break
182235
case 'failed-folded-report':
183-
core.info('Adding failed tests folded report to summary')
184-
addViewToSummary('### Failed Tests', BuiltInReports.FailedFolded, report)
236+
if (report.results.summary.extra?.showFailedReports) {
237+
core.info('Adding failed tests folded report to summary')
238+
addViewToSummary(
239+
'### Failed Tests',
240+
BuiltInReports.FailedFolded,
241+
report
242+
)
243+
} else {
244+
core.info('No failed tests to display, skipping failed-folded-report')
245+
}
185246
break
186247
case 'flaky-report':
187-
core.info('Adding flaky tests report to summary')
188-
addViewToSummary('### Flaky Tests', BuiltInReports.FlakyTable, report)
248+
if (report.results.summary.extra?.showFlakyReports) {
249+
core.info('Adding flaky tests report to summary')
250+
addViewToSummary('### Flaky Tests', BuiltInReports.FlakyTable, report)
251+
} else {
252+
core.info('No flaky tests to display, skipping flaky-report')
253+
}
189254
break
190255
case 'flaky-rate-report':
191-
core.info('Adding flaky rate report to summary')
192-
addViewToSummary('### Flaky Rate', BuiltInReports.FlakyRateTable, report)
256+
if (report.results.summary.extra?.showFlakyReports) {
257+
core.info('Adding flaky rate report to summary')
258+
addViewToSummary(
259+
'### Flaky Rate',
260+
BuiltInReports.FlakyRateTable,
261+
report
262+
)
263+
} else {
264+
core.info('No flaky tests to display, skipping flaky-rate-report')
265+
}
193266
break
194267
case 'skipped-report':
195-
core.info('Adding skipped report to summary')
196-
addViewToSummary('### Skipped', BuiltInReports.SkippedTable, report)
268+
if (report.results.summary.extra?.showSkippedReports) {
269+
core.info('Adding skipped report to summary')
270+
addViewToSummary('### Skipped', BuiltInReports.SkippedTable, report)
271+
} else {
272+
core.info('No skipped tests to display, skipping skipped-report')
273+
}
197274
break
198275
case 'ai-report':
199-
core.info('Adding AI analysis report to summary')
200-
addViewToSummary('### AI Analysis', BuiltInReports.AiTable, report)
276+
if (report.results.summary.extra?.showFailedReports) {
277+
core.info('Adding AI analysis report to summary')
278+
addViewToSummary('### AI Analysis', BuiltInReports.AiTable, report)
279+
} else {
280+
core.info('No AI analysis to display, skipping ai-report')
281+
}
201282
break
202283
case 'pull-request-report':
203284
core.info('Adding pull request report to summary')

src/reports/flaky-table.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| --- | --- |
44
{{#each ctrf.tests}}
55
{{#if flaky}}
6-
| {{getCtrfEmoji "flaky"}} {{name}} | {{retries}} |
6+
| {{name}} | {{retries}} |
77
{{/if}}
88
{{/each}}
99
{{else}}

0 commit comments

Comments
 (0)