Skip to content

Commit

Permalink
Do not print a title if none is specified in the config
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Marcus authored and Jozef Izso committed May 17, 2025
1 parent 0840d7c commit 2b2d091
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 28 deletions.
1 change: 0 additions & 1 deletion __tests__/__outputs__/dart-json.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/dotnet-nunit.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/dotnet-trx.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/fluent-validation-test-results.md
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/jest-junit-eslint.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
<details><summary>Expand for details</summary>

Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/jest-junit.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/jest-react-component-test-results.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
<details><summary>Expand for details</summary>

Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/jest-test-results.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/junit-with-message.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20failed-critical)
|Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/mocha-json.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/mocha-test-results.md
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/provider-test-results.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/pulsar-test-results-no-merge.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/pulsar-test-results.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/rspec-json.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/silent-notes-test-results.md
Original file line number Diff line number Diff line change
@@ -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>

Expand Down
1 change: 0 additions & 1 deletion __tests__/__outputs__/swift-xunit.md
Original file line number Diff line number Diff line change
@@ -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|
|:---|---:|---:|---:|---:|
Expand Down
42 changes: 38 additions & 4 deletions __tests__/java-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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'})

Expand All @@ -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 () => {
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ReportOptions {
onlySummary: boolean
useActionsSummary: boolean
badgeTitle: string
reportTitle: string
reportTitle?: string
}

const defaultOptions: ReportOptions = {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2b2d091

Please sign in to comment.