mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 06:17:10 +01:00
Compare commits
No commits in common. "e2f0ff63390c1e595b4d343f81b365138ce433b5" and "eeac280b8ec99aedc4e08392049b432f643cad57" have entirely different histories.
e2f0ff6339
...
eeac280b8e
7 changed files with 27 additions and 86 deletions
|
|
@ -1,11 +1,5 @@
|
|||
# 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
|
||||
|
|
|
|||
|
|
@ -303,47 +303,4 @@ describe('jest-junit tests', () => {
|
|||
expect(report).not.toContain('<details><summary>Expand for details</summary>')
|
||||
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
15
dist/index.js
generated
vendored
|
|
@ -422,9 +422,10 @@ class TestReporter {
|
|||
badgeTitle,
|
||||
reportTitle,
|
||||
collapsed
|
||||
}, shortSummary);
|
||||
});
|
||||
core.info('Summary content:');
|
||||
core.info(summary);
|
||||
core.summary.addRaw(`# ${shortSummary}`);
|
||||
await core.summary.addRaw(summary).write();
|
||||
}
|
||||
else {
|
||||
|
|
@ -1933,10 +1934,11 @@ exports.DEFAULT_OPTIONS = {
|
|||
reportTitle: '',
|
||||
collapsed: 'auto'
|
||||
};
|
||||
function getReport(results, options = exports.DEFAULT_OPTIONS, shortSummary = '') {
|
||||
function getReport(results, options = exports.DEFAULT_OPTIONS) {
|
||||
core.info('Generating check run summary');
|
||||
applySort(results);
|
||||
const opts = { ...options };
|
||||
let lines = renderReport(results, opts, shortSummary);
|
||||
let lines = renderReport(results, opts);
|
||||
let report = lines.join('\n');
|
||||
if (getByteLength(report) <= getMaxReportLength(options)) {
|
||||
return report;
|
||||
|
|
@ -1944,7 +1946,7 @@ function getReport(results, options = exports.DEFAULT_OPTIONS, shortSummary = ''
|
|||
if (opts.listTests === 'all') {
|
||||
core.info("Test report summary is too big - setting 'listTests' to 'failed'");
|
||||
opts.listTests = 'failed';
|
||||
lines = renderReport(results, opts, shortSummary);
|
||||
lines = renderReport(results, opts);
|
||||
report = lines.join('\n');
|
||||
if (getByteLength(report) <= getMaxReportLength(options)) {
|
||||
return report;
|
||||
|
|
@ -1991,15 +1993,12 @@ function applySort(results) {
|
|||
function getByteLength(text) {
|
||||
return Buffer.byteLength(text, 'utf8');
|
||||
}
|
||||
function renderReport(results, options, shortSummary) {
|
||||
function renderReport(results, options) {
|
||||
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);
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "test-reporter",
|
||||
"version": "2.2.0",
|
||||
"version": "2.1.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "test-reporter",
|
||||
"version": "2.2.0",
|
||||
"version": "2.1.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "test-reporter",
|
||||
"version": "2.2.0",
|
||||
"version": "2.1.1",
|
||||
"private": true,
|
||||
"description": "Presents test results from popular testing frameworks as Github check run",
|
||||
"main": "lib/main.js",
|
||||
|
|
|
|||
|
|
@ -181,9 +181,7 @@ class TestReporter {
|
|||
|
||||
let baseUrl = ''
|
||||
if (this.useActionsSummary) {
|
||||
const summary = getReport(
|
||||
results,
|
||||
{
|
||||
const summary = getReport(results, {
|
||||
listSuites,
|
||||
listTests,
|
||||
baseUrl,
|
||||
|
|
@ -192,12 +190,11 @@ class TestReporter {
|
|||
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}`)
|
||||
|
|
|
|||
|
|
@ -30,15 +30,13 @@ export const DEFAULT_OPTIONS: ReportOptions = {
|
|||
collapsed: 'auto'
|
||||
}
|
||||
|
||||
export function getReport(
|
||||
results: TestRunResult[],
|
||||
options: ReportOptions = DEFAULT_OPTIONS,
|
||||
shortSummary = ''
|
||||
): string {
|
||||
export function getReport(results: TestRunResult[], options: ReportOptions = DEFAULT_OPTIONS): string {
|
||||
core.info('Generating check run summary')
|
||||
|
||||
applySort(results)
|
||||
|
||||
const opts = {...options}
|
||||
let lines = renderReport(results, opts, shortSummary)
|
||||
let lines = renderReport(results, opts)
|
||||
let report = lines.join('\n')
|
||||
|
||||
if (getByteLength(report) <= getMaxReportLength(options)) {
|
||||
|
|
@ -48,7 +46,7 @@ export function getReport(
|
|||
if (opts.listTests === 'all') {
|
||||
core.info("Test report summary is too big - setting 'listTests' to 'failed'")
|
||||
opts.listTests = 'failed'
|
||||
lines = renderReport(results, opts, shortSummary)
|
||||
lines = renderReport(results, opts)
|
||||
report = lines.join('\n')
|
||||
if (getByteLength(report) <= getMaxReportLength(options)) {
|
||||
return report
|
||||
|
|
@ -105,7 +103,7 @@ function getByteLength(text: string): number {
|
|||
return Buffer.byteLength(text, 'utf8')
|
||||
}
|
||||
|
||||
function renderReport(results: TestRunResult[], options: ReportOptions, shortSummary: string): string[] {
|
||||
function renderReport(results: TestRunResult[], options: ReportOptions): string[] {
|
||||
const sections: string[] = []
|
||||
|
||||
const reportTitle: string = options.reportTitle.trim()
|
||||
|
|
@ -113,10 +111,6 @@ function renderReport(results: TestRunResult[], options: ReportOptions, shortSum
|
|||
sections.push(`# ${reportTitle}`)
|
||||
}
|
||||
|
||||
if (shortSummary) {
|
||||
sections.push(`## ${shortSummary}`)
|
||||
}
|
||||
|
||||
const badge = getReportBadge(results, options)
|
||||
sections.push(badge)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue