mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 13:57: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|
|
||||
|:---|---:|---:|---:|---:|
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
# Test Results
|
||||

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

|
||||
|Report|Passed|Failed|Skipped|Time|
|
||||
|:---|---:|---:|---:|---:|
|
||||
|
|
|
|||
|
|
@ -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
9
dist/index.js
generated
vendored
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue