Skip to content

Commit e2f0ff6

Browse files
authored
Merge pull request #645 from micmarc/fix/report-title-short-summary
2 parents bc8c296 + 9aef9d1 commit e2f0ff6

File tree

4 files changed

+77
-24
lines changed

4 files changed

+77
-24
lines changed

__tests__/jest-junit.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,47 @@ describe('jest-junit tests', () => {
303303
expect(report).not.toContain('<details><summary>Expand for details</summary>')
304304
expect(report).not.toContain('</details>')
305305
})
306+
307+
it('report includes the short summary', async () => {
308+
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
309+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
310+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
311+
312+
const opts: ParseOptions = {
313+
parseErrors: true,
314+
trackedFiles: []
315+
}
316+
317+
const parser = new JestJunitParser(opts)
318+
const result = await parser.parse(filePath, fileContent)
319+
const shortSummary = '1 passed, 4 failed and 1 skipped'
320+
const report = getReport([result], DEFAULT_OPTIONS, shortSummary)
321+
// Report should have the title as the first line
322+
expect(report).toMatch(/^## 1 passed, 4 failed and 1 skipped\n/)
323+
})
324+
325+
it('report includes a custom report title and short summary', async () => {
326+
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
327+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
328+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
329+
330+
const opts: ParseOptions = {
331+
parseErrors: true,
332+
trackedFiles: []
333+
}
334+
335+
const parser = new JestJunitParser(opts)
336+
const result = await parser.parse(filePath, fileContent)
337+
const shortSummary = '1 passed, 4 failed and 1 skipped'
338+
const report = getReport(
339+
[result],
340+
{
341+
...DEFAULT_OPTIONS,
342+
reportTitle: 'My Custom Title'
343+
},
344+
shortSummary
345+
)
346+
// Report should have the title as the first line
347+
expect(report).toMatch(/^# My Custom Title\n## 1 passed, 4 failed and 1 skipped\n/)
348+
})
306349
})

dist/index.js

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

src/main.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,23 @@ class TestReporter {
181181

182182
let baseUrl = ''
183183
if (this.useActionsSummary) {
184-
const summary = getReport(results, {
185-
listSuites,
186-
listTests,
187-
baseUrl,
188-
onlySummary,
189-
useActionsSummary,
190-
badgeTitle,
191-
reportTitle,
192-
collapsed
193-
})
184+
const summary = getReport(
185+
results,
186+
{
187+
listSuites,
188+
listTests,
189+
baseUrl,
190+
onlySummary,
191+
useActionsSummary,
192+
badgeTitle,
193+
reportTitle,
194+
collapsed
195+
},
196+
shortSummary
197+
)
194198

195199
core.info('Summary content:')
196200
core.info(summary)
197-
core.summary.addRaw(`# ${shortSummary}`)
198201
await core.summary.addRaw(summary).write()
199202
} else {
200203
core.info(`Creating check run ${name}`)

src/report/get-report.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ export const DEFAULT_OPTIONS: ReportOptions = {
3030
collapsed: 'auto'
3131
}
3232

33-
export function getReport(results: TestRunResult[], options: ReportOptions = DEFAULT_OPTIONS): string {
34-
core.info('Generating check run summary')
35-
33+
export function getReport(
34+
results: TestRunResult[],
35+
options: ReportOptions = DEFAULT_OPTIONS,
36+
shortSummary = ''
37+
): string {
3638
applySort(results)
3739

3840
const opts = {...options}
39-
let lines = renderReport(results, opts)
41+
let lines = renderReport(results, opts, shortSummary)
4042
let report = lines.join('\n')
4143

4244
if (getByteLength(report) <= getMaxReportLength(options)) {
@@ -46,7 +48,7 @@ export function getReport(results: TestRunResult[], options: ReportOptions = DEF
4648
if (opts.listTests === 'all') {
4749
core.info("Test report summary is too big - setting 'listTests' to 'failed'")
4850
opts.listTests = 'failed'
49-
lines = renderReport(results, opts)
51+
lines = renderReport(results, opts, shortSummary)
5052
report = lines.join('\n')
5153
if (getByteLength(report) <= getMaxReportLength(options)) {
5254
return report
@@ -103,14 +105,18 @@ function getByteLength(text: string): number {
103105
return Buffer.byteLength(text, 'utf8')
104106
}
105107

106-
function renderReport(results: TestRunResult[], options: ReportOptions): string[] {
108+
function renderReport(results: TestRunResult[], options: ReportOptions, shortSummary: string): string[] {
107109
const sections: string[] = []
108110

109111
const reportTitle: string = options.reportTitle.trim()
110112
if (reportTitle) {
111113
sections.push(`# ${reportTitle}`)
112114
}
113115

116+
if (shortSummary) {
117+
sections.push(`## ${shortSummary}`)
118+
}
119+
114120
const badge = getReportBadge(results, options)
115121
sections.push(badge)
116122

0 commit comments

Comments
 (0)