diff --git a/CHANGELOG.md b/CHANGELOG.md index 8489364..1979432 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 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 * 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 diff --git a/__tests__/jest-junit.test.ts b/__tests__/jest-junit.test.ts index 6fb6c64..912ebde 100644 --- a/__tests__/jest-junit.test.ts +++ b/__tests__/jest-junit.test.ts @@ -303,4 +303,47 @@ describe('jest-junit tests', () => { expect(report).not.toContain('
Expand for details') expect(report).not.toContain('
') }) + + 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/) + }) }) diff --git a/dist/index.js b/dist/index.js index cdd6319..ee83e34 100644 --- a/dist/index.js +++ b/dist/index.js @@ -422,10 +422,9 @@ class TestReporter { badgeTitle, reportTitle, collapsed - }); + }, shortSummary); core.info('Summary content:'); core.info(summary); - core.summary.addRaw(`# ${shortSummary}`); await core.summary.addRaw(summary).write(); } else { @@ -1934,11 +1933,10 @@ exports.DEFAULT_OPTIONS = { reportTitle: '', collapsed: 'auto' }; -function getReport(results, options = exports.DEFAULT_OPTIONS) { - core.info('Generating check run summary'); +function getReport(results, options = exports.DEFAULT_OPTIONS, shortSummary = '') { applySort(results); const opts = { ...options }; - let lines = renderReport(results, opts); + let lines = renderReport(results, opts, shortSummary); let report = lines.join('\n'); if (getByteLength(report) <= getMaxReportLength(options)) { return report; @@ -1946,7 +1944,7 @@ function getReport(results, options = exports.DEFAULT_OPTIONS) { if (opts.listTests === 'all') { core.info("Test report summary is too big - setting 'listTests' to 'failed'"); opts.listTests = 'failed'; - lines = renderReport(results, opts); + lines = renderReport(results, opts, shortSummary); report = lines.join('\n'); if (getByteLength(report) <= getMaxReportLength(options)) { return report; @@ -1993,12 +1991,15 @@ function applySort(results) { function getByteLength(text) { return Buffer.byteLength(text, 'utf8'); } -function renderReport(results, options) { +function renderReport(results, options, shortSummary) { const sections = []; const reportTitle = options.reportTitle.trim(); if (reportTitle) { sections.push(`# ${reportTitle}`); } + if (shortSummary) { + sections.push(`## ${shortSummary}`); + } const badge = getReportBadge(results, options); sections.push(badge); const runs = getTestRunsReport(results, options); diff --git a/package-lock.json b/package-lock.json index 54789e0..26ec018 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "test-reporter", - "version": "2.1.1", + "version": "2.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "test-reporter", - "version": "2.1.1", + "version": "2.2.0", "license": "MIT", "dependencies": { "@actions/core": "^1.11.1", diff --git a/package.json b/package.json index b924fee..ad18861 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "test-reporter", - "version": "2.1.1", + "version": "2.2.0", "private": true, "description": "Presents test results from popular testing frameworks as Github check run", "main": "lib/main.js", diff --git a/src/main.ts b/src/main.ts index 218377f..46ffdec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -181,20 +181,23 @@ class TestReporter { let baseUrl = '' if (this.useActionsSummary) { - const summary = getReport(results, { - listSuites, - listTests, - baseUrl, - onlySummary, - useActionsSummary, - badgeTitle, - reportTitle, - collapsed - }) + const summary = getReport( + results, + { + listSuites, + listTests, + baseUrl, + onlySummary, + useActionsSummary, + badgeTitle, + reportTitle, + collapsed + }, + shortSummary + ) core.info('Summary content:') core.info(summary) - core.summary.addRaw(`# ${shortSummary}`) await core.summary.addRaw(summary).write() } else { core.info(`Creating check run ${name}`) diff --git a/src/report/get-report.ts b/src/report/get-report.ts index d893b0e..02b9d49 100644 --- a/src/report/get-report.ts +++ b/src/report/get-report.ts @@ -30,13 +30,15 @@ export const DEFAULT_OPTIONS: ReportOptions = { collapsed: 'auto' } -export function getReport(results: TestRunResult[], options: ReportOptions = DEFAULT_OPTIONS): string { - core.info('Generating check run summary') - +export function getReport( + results: TestRunResult[], + options: ReportOptions = DEFAULT_OPTIONS, + shortSummary = '' +): string { applySort(results) const opts = {...options} - let lines = renderReport(results, opts) + let lines = renderReport(results, opts, shortSummary) let report = lines.join('\n') if (getByteLength(report) <= getMaxReportLength(options)) { @@ -46,7 +48,7 @@ export function getReport(results: TestRunResult[], options: ReportOptions = DEF if (opts.listTests === 'all') { core.info("Test report summary is too big - setting 'listTests' to 'failed'") opts.listTests = 'failed' - lines = renderReport(results, opts) + lines = renderReport(results, opts, shortSummary) report = lines.join('\n') if (getByteLength(report) <= getMaxReportLength(options)) { return report @@ -103,7 +105,7 @@ function getByteLength(text: string): number { 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 reportTitle: string = options.reportTitle.trim() @@ -111,6 +113,10 @@ function renderReport(results: TestRunResult[], options: ReportOptions): string[ sections.push(`# ${reportTitle}`) } + if (shortSummary) { + sections.push(`## ${shortSummary}`) + } + const badge = getReportBadge(results, options) sections.push(badge)