mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Do not print a title if none is specified in the config
This commit is contained in:
parent
0840d7c281
commit
2b2d091d3d
20 changed files with 52 additions and 28 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
<details><summary>Expand for details</summary>
|
<details><summary>Expand for details</summary>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
<details><summary>Expand for details</summary>
|
<details><summary>Expand for details</summary>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
<details><summary>Expand for details</summary>
|
<details><summary>Expand for details</summary>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
<details><summary>Expand for details</summary>
|
<details><summary>Expand for details</summary>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
<details><summary>Expand for details</summary>
|
<details><summary>Expand for details</summary>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# Test Results
|
|
||||||

|

|
||||||
|Report|Passed|Failed|Skipped|Time|
|
|Report|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,15 @@ import {ReportOptions, getReport} from '../src/report/get-report'
|
||||||
import {normalizeFilePath} from '../src/utils/path-utils'
|
import {normalizeFilePath} from '../src/utils/path-utils'
|
||||||
|
|
||||||
describe('java-junit tests', () => {
|
describe('java-junit tests', () => {
|
||||||
|
const reportOpts: ReportOptions = {
|
||||||
|
listSuites: 'all',
|
||||||
|
listTests: 'all',
|
||||||
|
baseUrl: '',
|
||||||
|
onlySummary: false,
|
||||||
|
useActionsSummary: true,
|
||||||
|
badgeTitle: 'tests'
|
||||||
|
}
|
||||||
|
|
||||||
it('produces empty test run result when there are no test cases', async () => {
|
it('produces empty test run result when there are no test cases', async () => {
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'java-junit.xml')
|
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'java-junit.xml')
|
||||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
|
|
@ -91,8 +100,8 @@ describe('java-junit tests', () => {
|
||||||
expect(result.failed === 1)
|
expect(result.failed === 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('report includes the default report title', async () => {
|
it('report does not include a title by default', async () => {
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'java-junit.xml')
|
const fixturePath = path.join(__dirname, 'fixtures', 'junit-with-message.xml')
|
||||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
|
|
||||||
|
|
@ -104,8 +113,33 @@ describe('java-junit tests', () => {
|
||||||
const parser = new JavaJunitParser(opts)
|
const parser = new JavaJunitParser(opts)
|
||||||
const result = await parser.parse(filePath, fileContent)
|
const result = await parser.parse(filePath, fileContent)
|
||||||
const report = getReport([result])
|
const report = getReport([result])
|
||||||
// Report should have the title as the first line
|
// Report should have the badge as the first line
|
||||||
expect(report).toMatch(/^# Test Results\n/)
|
expect(report).toMatch(/^!\[Tests failed]/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['empty string', ''],
|
||||||
|
['space', ' '],
|
||||||
|
['tab', '\t'],
|
||||||
|
['newline', '\n']
|
||||||
|
])('report does not include a title when configured value is %s', async (_, reportTitle) => {
|
||||||
|
const fixturePath = path.join(__dirname, 'fixtures', 'junit-with-message.xml')
|
||||||
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
|
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
|
|
||||||
|
const opts: ParseOptions = {
|
||||||
|
parseErrors: true,
|
||||||
|
trackedFiles: []
|
||||||
|
}
|
||||||
|
|
||||||
|
const parser = new JavaJunitParser(opts)
|
||||||
|
const result = await parser.parse(filePath, fileContent)
|
||||||
|
const report = getReport([result], {
|
||||||
|
...reportOpts,
|
||||||
|
reportTitle
|
||||||
|
})
|
||||||
|
// Report should have the badge as the first line
|
||||||
|
expect(report).toMatch(/^!\[Tests failed]/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('report includes a custom report title', async () => {
|
it('report includes a custom report title', async () => {
|
||||||
|
|
|
||||||
9
dist/index.js
generated
vendored
9
dist/index.js
generated
vendored
|
|
@ -1817,8 +1817,7 @@ const defaultOptions = {
|
||||||
baseUrl: '',
|
baseUrl: '',
|
||||||
onlySummary: false,
|
onlySummary: false,
|
||||||
useActionsSummary: true,
|
useActionsSummary: true,
|
||||||
badgeTitle: 'tests',
|
badgeTitle: 'tests'
|
||||||
reportTitle: 'Test Results'
|
|
||||||
};
|
};
|
||||||
function getReport(results, options = defaultOptions) {
|
function getReport(results, options = defaultOptions) {
|
||||||
core.info('Generating check run summary');
|
core.info('Generating check run summary');
|
||||||
|
|
@ -1881,7 +1880,11 @@ function getByteLength(text) {
|
||||||
}
|
}
|
||||||
function renderReport(results, options) {
|
function renderReport(results, options) {
|
||||||
const sections = [];
|
const sections = [];
|
||||||
sections.push(`# ${options.reportTitle}`);
|
const { reportTitle } = options;
|
||||||
|
// Suppress the report title for empty string or whitespace
|
||||||
|
if (reportTitle && reportTitle.trim()) {
|
||||||
|
sections.push(`# ${reportTitle}`);
|
||||||
|
}
|
||||||
const badge = getReportBadge(results, options);
|
const badge = getReportBadge(results, options);
|
||||||
sections.push(badge);
|
sections.push(badge);
|
||||||
const runs = getTestRunsReport(results, options);
|
const runs = getTestRunsReport(results, options);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export interface ReportOptions {
|
||||||
onlySummary: boolean
|
onlySummary: boolean
|
||||||
useActionsSummary: boolean
|
useActionsSummary: boolean
|
||||||
badgeTitle: string
|
badgeTitle: string
|
||||||
reportTitle: string
|
reportTitle?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions: ReportOptions = {
|
const defaultOptions: ReportOptions = {
|
||||||
|
|
@ -24,8 +24,7 @@ const defaultOptions: ReportOptions = {
|
||||||
baseUrl: '',
|
baseUrl: '',
|
||||||
onlySummary: false,
|
onlySummary: false,
|
||||||
useActionsSummary: true,
|
useActionsSummary: true,
|
||||||
badgeTitle: 'tests',
|
badgeTitle: 'tests'
|
||||||
reportTitle: 'Test Results'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
|
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
|
||||||
|
|
@ -103,7 +102,12 @@ function getByteLength(text: string): number {
|
||||||
|
|
||||||
function renderReport(results: TestRunResult[], options: ReportOptions): string[] {
|
function renderReport(results: TestRunResult[], options: ReportOptions): string[] {
|
||||||
const sections: string[] = []
|
const sections: string[] = []
|
||||||
sections.push(`# ${options.reportTitle}`)
|
|
||||||
|
const {reportTitle} = options
|
||||||
|
// Suppress the report title for empty string or whitespace
|
||||||
|
if (reportTitle && reportTitle.trim()) {
|
||||||
|
sections.push(`# ${reportTitle}`)
|
||||||
|
}
|
||||||
|
|
||||||
const badge = getReportBadge(results, options)
|
const badge = getReportBadge(results, options)
|
||||||
sections.push(badge)
|
sections.push(badge)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue