Compare commits

...

6 commits

Author SHA1 Message Date
Jozef Izso
e2f0ff6339
Merge pull request #645 from micmarc/fix/report-title-short-summary
Some checks are pending
Check dist/ / check-dist (push) Waiting to run
CI / Build & Test (push) Waiting to run
2025-11-14 20:00:35 +01:00
Jozef Izso
bc8c29617e
test-reporter release v2.2.0
Merge pull request #679 from dorny/release/v2.2.0
2025-11-14 18:46:03 +01:00
Michael Marcus
9aef9d168f Remove info log 2025-11-14 12:01:42 -05:00
Michael Marcus
6b64465c34 Rebuild index.js after rebase from main 2025-11-14 11:59:46 -05:00
Michael Marcus
6617053f9c Fix short summary formatting when a report title is present 2025-11-14 11:58:16 -05:00
Jozef Izso
7b7927aa7d
test-reporter release v2.2.0 2025-11-13 21:35:26 +01:00
7 changed files with 86 additions and 27 deletions

View file

@ -1,5 +1,11 @@
# Changelog # Changelog
## 2.2.0
* Feature: Add collapsed option to control report summary visibility https://github.com/dorny/test-reporter/pull/664
* Fix badge encoding for values including underscore and hyphens https://github.com/dorny/test-reporter/pull/672
* Fix missing `report-title` attribute in action definition https://github.com/dorny/test-reporter/pull/637
* Refactor variable names to fix shadowing issues https://github.com/dorny/test-reporter/pull/630
## 2.1.1 ## 2.1.1
* Fix error when a TestMethod element does not have a className attribute in a trx file https://github.com/dorny/test-reporter/pull/623 * Fix error when a TestMethod element does not have a className attribute in a trx file https://github.com/dorny/test-reporter/pull/623
* Add stack trace from trx to summary https://github.com/dorny/test-reporter/pull/615 * Add stack trace from trx to summary https://github.com/dorny/test-reporter/pull/615

View file

@ -303,4 +303,47 @@ describe('jest-junit tests', () => {
expect(report).not.toContain('<details><summary>Expand for details</summary>') expect(report).not.toContain('<details><summary>Expand for details</summary>')
expect(report).not.toContain('</details>') expect(report).not.toContain('</details>')
}) })
it('report includes the short summary', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const opts: ParseOptions = {
parseErrors: true,
trackedFiles: []
}
const parser = new JestJunitParser(opts)
const result = await parser.parse(filePath, fileContent)
const shortSummary = '1 passed, 4 failed and 1 skipped'
const report = getReport([result], DEFAULT_OPTIONS, shortSummary)
// Report should have the title as the first line
expect(report).toMatch(/^## 1 passed, 4 failed and 1 skipped\n/)
})
it('report includes a custom report title and short summary', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
const opts: ParseOptions = {
parseErrors: true,
trackedFiles: []
}
const parser = new JestJunitParser(opts)
const result = await parser.parse(filePath, fileContent)
const shortSummary = '1 passed, 4 failed and 1 skipped'
const report = getReport(
[result],
{
...DEFAULT_OPTIONS,
reportTitle: 'My Custom Title'
},
shortSummary
)
// Report should have the title as the first line
expect(report).toMatch(/^# My Custom Title\n## 1 passed, 4 failed and 1 skipped\n/)
})
}) })

15
dist/index.js generated vendored
View file

@ -422,10 +422,9 @@ class TestReporter {
badgeTitle, badgeTitle,
reportTitle, reportTitle,
collapsed collapsed
}); }, shortSummary);
core.info('Summary content:'); core.info('Summary content:');
core.info(summary); core.info(summary);
core.summary.addRaw(`# ${shortSummary}`);
await core.summary.addRaw(summary).write(); await core.summary.addRaw(summary).write();
} }
else { else {
@ -1934,11 +1933,10 @@ exports.DEFAULT_OPTIONS = {
reportTitle: '', reportTitle: '',
collapsed: 'auto' collapsed: 'auto'
}; };
function getReport(results, options = exports.DEFAULT_OPTIONS) { function getReport(results, options = exports.DEFAULT_OPTIONS, shortSummary = '') {
core.info('Generating check run summary');
applySort(results); applySort(results);
const opts = { ...options }; const opts = { ...options };
let lines = renderReport(results, opts); let lines = renderReport(results, opts, shortSummary);
let report = lines.join('\n'); let report = lines.join('\n');
if (getByteLength(report) <= getMaxReportLength(options)) { if (getByteLength(report) <= getMaxReportLength(options)) {
return report; return report;
@ -1946,7 +1944,7 @@ function getReport(results, options = exports.DEFAULT_OPTIONS) {
if (opts.listTests === 'all') { if (opts.listTests === 'all') {
core.info("Test report summary is too big - setting 'listTests' to 'failed'"); core.info("Test report summary is too big - setting 'listTests' to 'failed'");
opts.listTests = 'failed'; opts.listTests = 'failed';
lines = renderReport(results, opts); lines = renderReport(results, opts, shortSummary);
report = lines.join('\n'); report = lines.join('\n');
if (getByteLength(report) <= getMaxReportLength(options)) { if (getByteLength(report) <= getMaxReportLength(options)) {
return report; return report;
@ -1993,12 +1991,15 @@ function applySort(results) {
function getByteLength(text) { function getByteLength(text) {
return Buffer.byteLength(text, 'utf8'); return Buffer.byteLength(text, 'utf8');
} }
function renderReport(results, options) { function renderReport(results, options, shortSummary) {
const sections = []; const sections = [];
const reportTitle = options.reportTitle.trim(); const reportTitle = options.reportTitle.trim();
if (reportTitle) { if (reportTitle) {
sections.push(`# ${reportTitle}`); sections.push(`# ${reportTitle}`);
} }
if (shortSummary) {
sections.push(`## ${shortSummary}`);
}
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);

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "test-reporter", "name": "test-reporter",
"version": "2.1.1", "version": "2.2.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "test-reporter", "name": "test-reporter",
"version": "2.1.1", "version": "2.2.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",

View file

@ -1,6 +1,6 @@
{ {
"name": "test-reporter", "name": "test-reporter",
"version": "2.1.1", "version": "2.2.0",
"private": true, "private": true,
"description": "Presents test results from popular testing frameworks as Github check run", "description": "Presents test results from popular testing frameworks as Github check run",
"main": "lib/main.js", "main": "lib/main.js",

View file

@ -181,20 +181,23 @@ class TestReporter {
let baseUrl = '' let baseUrl = ''
if (this.useActionsSummary) { if (this.useActionsSummary) {
const summary = getReport(results, { const summary = getReport(
listSuites, results,
listTests, {
baseUrl, listSuites,
onlySummary, listTests,
useActionsSummary, baseUrl,
badgeTitle, onlySummary,
reportTitle, useActionsSummary,
collapsed badgeTitle,
}) reportTitle,
collapsed
},
shortSummary
)
core.info('Summary content:') core.info('Summary content:')
core.info(summary) core.info(summary)
core.summary.addRaw(`# ${shortSummary}`)
await core.summary.addRaw(summary).write() await core.summary.addRaw(summary).write()
} else { } else {
core.info(`Creating check run ${name}`) core.info(`Creating check run ${name}`)

View file

@ -30,13 +30,15 @@ export const DEFAULT_OPTIONS: ReportOptions = {
collapsed: 'auto' collapsed: 'auto'
} }
export function getReport(results: TestRunResult[], options: ReportOptions = DEFAULT_OPTIONS): string { export function getReport(
core.info('Generating check run summary') results: TestRunResult[],
options: ReportOptions = DEFAULT_OPTIONS,
shortSummary = ''
): string {
applySort(results) applySort(results)
const opts = {...options} const opts = {...options}
let lines = renderReport(results, opts) let lines = renderReport(results, opts, shortSummary)
let report = lines.join('\n') let report = lines.join('\n')
if (getByteLength(report) <= getMaxReportLength(options)) { if (getByteLength(report) <= getMaxReportLength(options)) {
@ -46,7 +48,7 @@ export function getReport(results: TestRunResult[], options: ReportOptions = DEF
if (opts.listTests === 'all') { if (opts.listTests === 'all') {
core.info("Test report summary is too big - setting 'listTests' to 'failed'") core.info("Test report summary is too big - setting 'listTests' to 'failed'")
opts.listTests = 'failed' opts.listTests = 'failed'
lines = renderReport(results, opts) lines = renderReport(results, opts, shortSummary)
report = lines.join('\n') report = lines.join('\n')
if (getByteLength(report) <= getMaxReportLength(options)) { if (getByteLength(report) <= getMaxReportLength(options)) {
return report return report
@ -103,7 +105,7 @@ function getByteLength(text: string): number {
return Buffer.byteLength(text, 'utf8') return Buffer.byteLength(text, 'utf8')
} }
function renderReport(results: TestRunResult[], options: ReportOptions): string[] { function renderReport(results: TestRunResult[], options: ReportOptions, shortSummary: string): string[] {
const sections: string[] = [] const sections: string[] = []
const reportTitle: string = options.reportTitle.trim() const reportTitle: string = options.reportTitle.trim()
@ -111,6 +113,10 @@ function renderReport(results: TestRunResult[], options: ReportOptions): string[
sections.push(`# ${reportTitle}`) sections.push(`# ${reportTitle}`)
} }
if (shortSummary) {
sections.push(`## ${shortSummary}`)
}
const badge = getReportBadge(results, options) const badge = getReportBadge(results, options)
sections.push(badge) sections.push(badge)