Do not print a title if none is specified in the config

This commit is contained in:
Michael Marcus 2025-03-28 16:59:54 -04:00 committed by Jozef Izso
parent 0840d7c281
commit 2b2d091d3d
20 changed files with 52 additions and 28 deletions

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%205%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%205%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-803%20passed%2C%201%20skipped-success)
<details><summary>Expand for details</summary>

View file

@ -1,4 +1,3 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
<details><summary>Expand for details</summary>

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
<details><summary>Expand for details</summary>

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-4207%20passed%2C%202%20failed%2C%2030%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20failed-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-833%20passed%2C%206%20skipped-success)
<details><summary>Expand for details</summary>

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-268%20passed%2C%201%20failed-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-793%20passed%2C%201%20failed%2C%2014%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -1,4 +1,3 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-67%20passed%2C%2012%20skipped-success)
<details><summary>Expand for details</summary>

View file

@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-2%20passed%2C%201%20failed-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|

View file

@ -7,6 +7,15 @@ import {ReportOptions, getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils'
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 () => {
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'java-junit.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
@ -91,8 +100,8 @@ describe('java-junit tests', () => {
expect(result.failed === 1)
})
it('report includes the default report title', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'java-junit.xml')
it('report does not include a title by default', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'junit-with-message.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
@ -104,8 +113,33 @@ describe('java-junit tests', () => {
const parser = new JavaJunitParser(opts)
const result = await parser.parse(filePath, fileContent)
const report = getReport([result])
// Report should have the title as the first line
expect(report).toMatch(/^# Test Results\n/)
// Report should have the badge as the first line
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 () => {

9
dist/index.js generated vendored
View file

@ -1817,8 +1817,7 @@ const defaultOptions = {
baseUrl: '',
onlySummary: false,
useActionsSummary: true,
badgeTitle: 'tests',
reportTitle: 'Test Results'
badgeTitle: 'tests'
};
function getReport(results, options = defaultOptions) {
core.info('Generating check run summary');
@ -1881,7 +1880,11 @@ function getByteLength(text) {
}
function renderReport(results, options) {
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);
sections.push(badge);
const runs = getTestRunsReport(results, options);

View file

@ -15,7 +15,7 @@ export interface ReportOptions {
onlySummary: boolean
useActionsSummary: boolean
badgeTitle: string
reportTitle: string
reportTitle?: string
}
const defaultOptions: ReportOptions = {
@ -24,8 +24,7 @@ const defaultOptions: ReportOptions = {
baseUrl: '',
onlySummary: false,
useActionsSummary: true,
badgeTitle: 'tests',
reportTitle: 'Test Results'
badgeTitle: 'tests'
}
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[] {
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)
sections.push(badge)