Skip to content

Commit 29aefa7

Browse files
authored
Merge pull request #568 from micmarc/feature/summary-title
Feature: Add summary title
2 parents d1bf678 + f1fa471 commit 29aefa7

13 files changed

Lines changed: 6997 additions & 421 deletions

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ jobs:
154154
# Allows you to generate reports for Actions Summary
155155
# https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/
156156
use-actions-summary: 'true'
157+
158+
# Optionally specify a title (Heading level 1) for the report. Leading and trailing whitespace are ignored.
159+
# This is useful for separating your test report from other sections in the build summary.
160+
# If omitted or set to whitespace/empty, no title will be printed.
161+
report-title: ''
157162
158163
# Customize the title of badges shown for each Actions Summary.
159164
# Useful when distinguish summaries for tests ran in multiple Actions steps.
@@ -345,7 +350,7 @@ Support for Swift test results in xUnit format is experimental - should work but
345350

346351
Unfortunately, there are some known issues and limitations caused by GitHub API:
347352

348-
- Test report (i.e. Check Run summary) is markdown text. No custom styling or HTML is possible.
353+
- Test report (i.e. build summary) is Markdown text. No custom styling or HTML is possible.
349354
- Maximum report size is 65535 bytes. Input parameters `list-suites` and `list-tests` will be automatically adjusted if max size is exceeded.
350355
- Test report can't reference any additional files (e.g. screenshots). You can use `actions/upload-artifact@v4` to upload them and inspect them manually.
351356
- Check Runs are created for specific commit SHA. It's not possible to specify under which workflow test report should belong if more

__tests__/__outputs__/jest-test-results.md

Lines changed: 6425 additions & 398 deletions
Large diffs are not rendered by default.

__tests__/dart-json.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33

44
import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser'
55
import {ParseOptions} from '../src/test-parser'
6-
import {getReport} from '../src/report/get-report'
6+
import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report'
77
import {normalizeFilePath} from '../src/utils/path-utils'
88

99
describe('dart-json tests', () => {
@@ -66,4 +66,66 @@ describe('dart-json tests', () => {
6666
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
6767
fs.writeFileSync(outputPath, report)
6868
})
69+
70+
it('report does not include a title by default', async () => {
71+
const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
72+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
73+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
74+
75+
const opts: ParseOptions = {
76+
parseErrors: true,
77+
trackedFiles: []
78+
}
79+
80+
const parser = new DartJsonParser(opts, 'dart')
81+
const result = await parser.parse(filePath, fileContent)
82+
const report = getReport([result])
83+
// Report should have the badge as the first line
84+
expect(report).toMatch(/^!\[Tests failed]/)
85+
})
86+
87+
it.each([
88+
['empty string', ''],
89+
['space', ' '],
90+
['tab', '\t'],
91+
['newline', '\n']
92+
])('report does not include a title when configured value is %s', async (_, reportTitle) => {
93+
const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
94+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
95+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
96+
97+
const opts: ParseOptions = {
98+
parseErrors: true,
99+
trackedFiles: []
100+
}
101+
102+
const parser = new DartJsonParser(opts, 'dart')
103+
const result = await parser.parse(filePath, fileContent)
104+
const report = getReport([result], {
105+
...DEFAULT_OPTIONS,
106+
reportTitle
107+
})
108+
// Report should have the badge as the first line
109+
expect(report).toMatch(/^!\[Tests failed]/)
110+
})
111+
112+
it('report includes a custom report title', async () => {
113+
const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
114+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
115+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
116+
117+
const opts: ParseOptions = {
118+
parseErrors: true,
119+
trackedFiles: []
120+
}
121+
122+
const parser = new DartJsonParser(opts, 'dart')
123+
const result = await parser.parse(filePath, fileContent)
124+
const report = getReport([result], {
125+
...DEFAULT_OPTIONS,
126+
reportTitle: 'My Custom Title'
127+
})
128+
// Report should have the title as the first line
129+
expect(report).toMatch(/^# My Custom Title\n/)
130+
})
69131
})

__tests__/dotnet-nunit.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33

44
import {DotnetNunitParser} from '../src/parsers/dotnet-nunit/dotnet-nunit-parser'
55
import {ParseOptions} from '../src/test-parser'
6-
import {getReport} from '../src/report/get-report'
6+
import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report'
77
import {normalizeFilePath} from '../src/utils/path-utils'
88

99
describe('dotnet-nunit tests', () => {
@@ -26,4 +26,66 @@ describe('dotnet-nunit tests', () => {
2626
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
2727
fs.writeFileSync(outputPath, report)
2828
})
29+
30+
it('report does not include a title by default', async () => {
31+
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-nunit.xml')
32+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
33+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
34+
35+
const opts: ParseOptions = {
36+
parseErrors: true,
37+
trackedFiles: []
38+
}
39+
40+
const parser = new DotnetNunitParser(opts)
41+
const result = await parser.parse(filePath, fileContent)
42+
const report = getReport([result])
43+
// Report should have the badge as the first line
44+
expect(report).toMatch(/^!\[Tests failed]/)
45+
})
46+
47+
it.each([
48+
['empty string', ''],
49+
['space', ' '],
50+
['tab', '\t'],
51+
['newline', '\n']
52+
])('report does not include a title when configured value is %s', async (_, reportTitle) => {
53+
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-nunit.xml')
54+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
55+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
56+
57+
const opts: ParseOptions = {
58+
parseErrors: true,
59+
trackedFiles: []
60+
}
61+
62+
const parser = new DotnetNunitParser(opts)
63+
const result = await parser.parse(filePath, fileContent)
64+
const report = getReport([result], {
65+
...DEFAULT_OPTIONS,
66+
reportTitle
67+
})
68+
// Report should have the badge as the first line
69+
expect(report).toMatch(/^!\[Tests failed]/)
70+
})
71+
72+
it('report includes a custom report title', async () => {
73+
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-nunit.xml')
74+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
75+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
76+
77+
const opts: ParseOptions = {
78+
parseErrors: true,
79+
trackedFiles: []
80+
}
81+
82+
const parser = new DotnetNunitParser(opts)
83+
const result = await parser.parse(filePath, fileContent)
84+
const report = getReport([result], {
85+
...DEFAULT_OPTIONS,
86+
reportTitle: 'My Custom Title'
87+
})
88+
// Report should have the title as the first line
89+
expect(report).toMatch(/^# My Custom Title\n/)
90+
})
2991
})

__tests__/dotnet-trx.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33

44
import {DotnetTrxParser} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
55
import {ParseOptions} from '../src/test-parser'
6-
import {getReport} from '../src/report/get-report'
6+
import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report'
77
import {normalizeFilePath} from '../src/utils/path-utils'
88

99
describe('dotnet-trx tests', () => {
@@ -99,4 +99,66 @@ describe('dotnet-trx tests', () => {
9999
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
100100
fs.writeFileSync(outputPath, report)
101101
})
102+
103+
it('report does not include a title by default', async () => {
104+
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
105+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
106+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
107+
108+
const opts: ParseOptions = {
109+
parseErrors: true,
110+
trackedFiles: []
111+
}
112+
113+
const parser = new DotnetTrxParser(opts)
114+
const result = await parser.parse(filePath, fileContent)
115+
const report = getReport([result])
116+
// Report should have the badge as the first line
117+
expect(report).toMatch(/^!\[Tests failed]/)
118+
})
119+
120+
it.each([
121+
['empty string', ''],
122+
['space', ' '],
123+
['tab', '\t'],
124+
['newline', '\n']
125+
])('report does not include a title when configured value is %s', async (_, reportTitle) => {
126+
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
127+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
128+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
129+
130+
const opts: ParseOptions = {
131+
parseErrors: true,
132+
trackedFiles: []
133+
}
134+
135+
const parser = new DotnetTrxParser(opts)
136+
const result = await parser.parse(filePath, fileContent)
137+
const report = getReport([result], {
138+
...DEFAULT_OPTIONS,
139+
reportTitle
140+
})
141+
// Report should have the badge as the first line
142+
expect(report).toMatch(/^!\[Tests failed]/)
143+
})
144+
145+
it('report includes a custom report title', async () => {
146+
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
147+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
148+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
149+
150+
const opts: ParseOptions = {
151+
parseErrors: true,
152+
trackedFiles: []
153+
}
154+
155+
const parser = new DotnetTrxParser(opts)
156+
const result = await parser.parse(filePath, fileContent)
157+
const report = getReport([result], {
158+
...DEFAULT_OPTIONS,
159+
reportTitle: 'My Custom Title'
160+
})
161+
// Report should have the title as the first line
162+
expect(report).toMatch(/^# My Custom Title\n/)
163+
})
102164
})

__tests__/java-junit.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33

44
import {JavaJunitParser} from '../src/parsers/java-junit/java-junit-parser'
55
import {ParseOptions} from '../src/test-parser'
6-
import {getReport} from '../src/report/get-report'
6+
import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report'
77
import {normalizeFilePath} from '../src/utils/path-utils'
88

99
describe('java-junit tests', () => {
@@ -90,4 +90,66 @@ describe('java-junit tests', () => {
9090
expect(result.result === 'failed')
9191
expect(result.failed === 1)
9292
})
93+
94+
it('report does not include a title by default', async () => {
95+
const fixturePath = path.join(__dirname, 'fixtures', 'junit-with-message.xml')
96+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
97+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
98+
99+
const opts: ParseOptions = {
100+
parseErrors: true,
101+
trackedFiles: []
102+
}
103+
104+
const parser = new JavaJunitParser(opts)
105+
const result = await parser.parse(filePath, fileContent)
106+
const report = getReport([result])
107+
// Report should have the badge as the first line
108+
expect(report).toMatch(/^!\[Tests failed]/)
109+
})
110+
111+
it.each([
112+
['empty string', ''],
113+
['space', ' '],
114+
['tab', '\t'],
115+
['newline', '\n']
116+
])('report does not include a title when configured value is %s', async (_, reportTitle) => {
117+
const fixturePath = path.join(__dirname, 'fixtures', 'junit-with-message.xml')
118+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
119+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
120+
121+
const opts: ParseOptions = {
122+
parseErrors: true,
123+
trackedFiles: []
124+
}
125+
126+
const parser = new JavaJunitParser(opts)
127+
const result = await parser.parse(filePath, fileContent)
128+
const report = getReport([result], {
129+
...DEFAULT_OPTIONS,
130+
reportTitle
131+
})
132+
// Report should have the badge as the first line
133+
expect(report).toMatch(/^!\[Tests failed]/)
134+
})
135+
136+
it('report includes a custom report title', async () => {
137+
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'java-junit.xml')
138+
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
139+
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
140+
141+
const opts: ParseOptions = {
142+
parseErrors: true,
143+
trackedFiles: []
144+
}
145+
146+
const parser = new JavaJunitParser(opts)
147+
const result = await parser.parse(filePath, fileContent)
148+
const report = getReport([result], {
149+
...DEFAULT_OPTIONS,
150+
reportTitle: 'My Custom Title'
151+
})
152+
// Report should have the title as the first line
153+
expect(report).toMatch(/^# My Custom Title\n/)
154+
})
93155
})

0 commit comments

Comments
 (0)