diff --git a/__tests__/__outputs__/dart-json.md b/__tests__/__outputs__/dart-json.md index 37aa462..9805d20 100644 --- a/__tests__/__outputs__/dart-json.md +++ b/__tests__/__outputs__/dart-json.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/dotnet-nunit.md b/__tests__/__outputs__/dotnet-nunit.md index a706bb0..e33c66d 100644 --- a/__tests__/__outputs__/dotnet-nunit.md +++ b/__tests__/__outputs__/dotnet-nunit.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/dotnet-trx.md b/__tests__/__outputs__/dotnet-trx.md index 0c6435d..eedab46 100644 --- a/__tests__/__outputs__/dotnet-trx.md +++ b/__tests__/__outputs__/dotnet-trx.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/fluent-validation-test-results.md b/__tests__/__outputs__/fluent-validation-test-results.md index 7a1ef40..9337a62 100644 --- a/__tests__/__outputs__/fluent-validation-test-results.md +++ b/__tests__/__outputs__/fluent-validation-test-results.md @@ -1,4 +1,3 @@ -# Test Results ![Tests passed successfully](https://img.shields.io/badge/tests-803%20passed%2C%201%20skipped-success)
Expand for details diff --git a/__tests__/__outputs__/jest-junit-eslint.md b/__tests__/__outputs__/jest-junit-eslint.md index a2052d4..d3ad9b9 100644 --- a/__tests__/__outputs__/jest-junit-eslint.md +++ b/__tests__/__outputs__/jest-junit-eslint.md @@ -1,4 +1,3 @@ -# Test Results ![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
Expand for details diff --git a/__tests__/__outputs__/jest-junit.md b/__tests__/__outputs__/jest-junit.md index 8b9086e..ed5a174 100644 --- a/__tests__/__outputs__/jest-junit.md +++ b/__tests__/__outputs__/jest-junit.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/jest-react-component-test-results.md b/__tests__/__outputs__/jest-react-component-test-results.md index d8ff9a2..d71db4c 100644 --- a/__tests__/__outputs__/jest-react-component-test-results.md +++ b/__tests__/__outputs__/jest-react-component-test-results.md @@ -1,4 +1,3 @@ -# Test Results ![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
Expand for details diff --git a/__tests__/__outputs__/jest-test-results.md b/__tests__/__outputs__/jest-test-results.md index 2c72c93..5b154f8 100644 --- a/__tests__/__outputs__/jest-test-results.md +++ b/__tests__/__outputs__/jest-test-results.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/junit-with-message.md b/__tests__/__outputs__/junit-with-message.md index 3c1197a..988d8fc 100644 --- a/__tests__/__outputs__/junit-with-message.md +++ b/__tests__/__outputs__/junit-with-message.md @@ -1,4 +1,3 @@ -# Test Results ![Tests failed](https://img.shields.io/badge/tests-1%20failed-critical) |Report|Passed|Failed|Skipped|Time| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/mocha-json.md b/__tests__/__outputs__/mocha-json.md index 29ad677..50419e1 100644 --- a/__tests__/__outputs__/mocha-json.md +++ b/__tests__/__outputs__/mocha-json.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/mocha-test-results.md b/__tests__/__outputs__/mocha-test-results.md index dfc8903..8831d7b 100644 --- a/__tests__/__outputs__/mocha-test-results.md +++ b/__tests__/__outputs__/mocha-test-results.md @@ -1,4 +1,3 @@ -# Test Results ![Tests passed successfully](https://img.shields.io/badge/tests-833%20passed%2C%206%20skipped-success)
Expand for details diff --git a/__tests__/__outputs__/provider-test-results.md b/__tests__/__outputs__/provider-test-results.md index 450a425..b2216ad 100644 --- a/__tests__/__outputs__/provider-test-results.md +++ b/__tests__/__outputs__/provider-test-results.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/pulsar-test-results-no-merge.md b/__tests__/__outputs__/pulsar-test-results-no-merge.md index baf94dc..b1738a4 100644 --- a/__tests__/__outputs__/pulsar-test-results-no-merge.md +++ b/__tests__/__outputs__/pulsar-test-results-no-merge.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/pulsar-test-results.md b/__tests__/__outputs__/pulsar-test-results.md index ed2e54c..a9a5290 100644 --- a/__tests__/__outputs__/pulsar-test-results.md +++ b/__tests__/__outputs__/pulsar-test-results.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/rspec-json.md b/__tests__/__outputs__/rspec-json.md index 8b9d300..7444608 100644 --- a/__tests__/__outputs__/rspec-json.md +++ b/__tests__/__outputs__/rspec-json.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/__outputs__/silent-notes-test-results.md b/__tests__/__outputs__/silent-notes-test-results.md index b397c16..34f5bab 100644 --- a/__tests__/__outputs__/silent-notes-test-results.md +++ b/__tests__/__outputs__/silent-notes-test-results.md @@ -1,4 +1,3 @@ -# Test Results ![Tests passed successfully](https://img.shields.io/badge/tests-67%20passed%2C%2012%20skipped-success)
Expand for details diff --git a/__tests__/__outputs__/swift-xunit.md b/__tests__/__outputs__/swift-xunit.md index be1f937..6f9ed46 100644 --- a/__tests__/__outputs__/swift-xunit.md +++ b/__tests__/__outputs__/swift-xunit.md @@ -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| |:---|---:|---:|---:|---:| diff --git a/__tests__/java-junit.test.ts b/__tests__/java-junit.test.ts index 7c87993..949341f 100644 --- a/__tests__/java-junit.test.ts +++ b/__tests__/java-junit.test.ts @@ -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 () => { diff --git a/dist/index.js b/dist/index.js index a6710fc..0e63008 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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); diff --git a/src/report/get-report.ts b/src/report/get-report.ts index 4557960..01320b7 100644 --- a/src/report/get-report.ts +++ b/src/report/get-report.ts @@ -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)