Simplify 'only-failed' to 'failed'

This commit is contained in:
Michal Dorner 2021-01-28 22:18:29 +01:00
parent f55c0119bb
commit 96e91aa726
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
7 changed files with 29 additions and 25 deletions

View file

@ -63,7 +63,7 @@ jobs:
# Limits which test suites are listed: # Limits which test suites are listed:
# all # all
# only-failed # failed
list-suites: 'all' list-suites: 'all'
# Limits which test cases are listed: # Limits which test cases are listed:

View file

@ -6,11 +6,8 @@ import {ParseOptions} from '../src/parsers/parser-types'
import {getReport} from '../src/report/get-report' import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/file-utils' import {normalizeFilePath} from '../src/utils/file-utils'
describe('dotnet-trx tests', () => { describe('dotnet-trx tests', () => {
it('matches report snapshot', async () => { it('matches report snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx') const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md') const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md')
const xmlFixture = { const xmlFixture = {
@ -49,7 +46,7 @@ describe('dotnet-trx tests', () => {
const result = await parseDotnetTrx([xmlFixture], opts) const result = await parseDotnetTrx([xmlFixture], opts)
expect(result).toMatchSnapshot() expect(result).toMatchSnapshot()
const report = getReport(result.testRuns, {listTests: 'only-failed'}) const report = getReport(result.testRuns, {listTests: 'failed'})
fs.mkdirSync(path.dirname(outputPath), {recursive: true}) fs.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, report) fs.writeFileSync(outputPath, report)
}) })

View file

@ -48,7 +48,7 @@ describe('jest-junit tests', () => {
const result = await parseJestJunit([xmlFixture], opts) const result = await parseJestJunit([xmlFixture], opts)
expect(result).toMatchSnapshot() expect(result).toMatchSnapshot()
const report = getReport(result.testRuns, {listTests: 'only-failed'}) const report = getReport(result.testRuns, {listTests: 'failed'})
fs.mkdirSync(path.dirname(outputPath), {recursive: true}) fs.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, report) fs.writeFileSync(outputPath, report)
}) })

21
dist/index.js generated vendored
View file

@ -61,11 +61,11 @@ async function main() {
const failOnError = core.getInput('fail-on-error', { required: true }) === 'true'; const failOnError = core.getInput('fail-on-error', { required: true }) === 'true';
const workDirInput = core.getInput('working-directory', { required: false }); const workDirInput = core.getInput('working-directory', { required: false });
const token = core.getInput('token', { required: true }); const token = core.getInput('token', { required: true });
if (listSuites !== 'all' && listSuites !== 'only-failed') { if (listSuites !== 'all' && listSuites !== 'failed') {
core.setFailed(`Input parameter 'list-suites' has invalid value`); core.setFailed(`Input parameter 'list-suites' has invalid value`);
return; return;
} }
if (listTests !== 'all' && listTests !== 'only-failed' && listTests !== 'none') { if (listTests !== 'all' && listTests !== 'failed' && listTests !== 'none') {
core.setFailed(`Input parameter 'list-tests' has invalid value`); core.setFailed(`Input parameter 'list-tests' has invalid value`);
return; return;
} }
@ -743,6 +743,7 @@ const slugger_1 = __nccwpck_require__(3328);
function getReport(results, options = {}) { function getReport(results, options = {}) {
const maxReportLength = 65535; const maxReportLength = 65535;
const sections = []; const sections = [];
applySort(results);
const badge = getBadge(results); const badge = getBadge(results);
sections.push(badge); sections.push(badge);
const runsSummary = results.map((tr, i) => getRunSummary(tr, i, options)).join('\n\n'); const runsSummary = results.map((tr, i) => getRunSummary(tr, i, options)).join('\n\n');
@ -750,7 +751,7 @@ function getReport(results, options = {}) {
if (options.listTests !== 'none') { if (options.listTests !== 'none') {
const suitesSummary = results const suitesSummary = results
.map((tr, runIndex) => { .map((tr, runIndex) => {
const suites = options.listSuites === 'only-failed' ? tr.failedSuites : tr.suites; const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites;
return suites return suites
.map((ts, suiteIndex) => getSuiteSummary(ts, runIndex, suiteIndex, options)) .map((ts, suiteIndex) => getSuiteSummary(ts, runIndex, suiteIndex, options))
.filter(str => str !== ''); .filter(str => str !== '');
@ -776,6 +777,12 @@ function getReport(results, options = {}) {
return report; return report;
} }
exports.getReport = getReport; exports.getReport = getReport;
function applySort(results) {
results.sort((a, b) => a.path.localeCompare(b.path));
for (const res of results) {
res.suites.sort((a, b) => a.name.localeCompare(b.name));
}
}
function getBadge(results) { function getBadge(results) {
const passed = results.reduce((sum, tr) => sum + tr.passed, 0); const passed = results.reduce((sum, tr) => sum + tr.passed, 0);
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0); const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
@ -800,11 +807,11 @@ function getRunSummary(tr, runIndex, options) {
const time = `${(tr.time / 1000).toFixed(3)}s`; const time = `${(tr.time / 1000).toFixed(3)}s`;
const headingLine1 = `### ${tr.path}`; const headingLine1 = `### ${tr.path}`;
const headingLine2 = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`; const headingLine2 = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`;
const suites = options.listSuites === 'only-failed' ? tr.failedSuites : tr.suites; const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites;
const suitesSummary = suites.map((s, suiteIndex) => { const suitesSummary = suites.map((s, suiteIndex) => {
const tsTime = `${Math.round(s.time)}ms`; const tsTime = `${Math.round(s.time)}ms`;
const tsName = s.name; const tsName = s.name;
const skipLink = options.listTests === 'none' || (options.listTests === 'only-failed' && s.result !== 'failed'); const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed');
const tsAddr = makeSuiteSlug(runIndex, suiteIndex, tsName).link; const tsAddr = makeSuiteSlug(runIndex, suiteIndex, tsName).link;
const tsNameLink = skipLink ? tsName : markdown_utils_1.link(tsName, tsAddr); const tsNameLink = skipLink ? tsName : markdown_utils_1.link(tsName, tsAddr);
const passed = s.passed > 0 ? `${s.passed}${markdown_utils_1.Icon.success}` : ''; const passed = s.passed > 0 ? `${s.passed}${markdown_utils_1.Icon.success}` : '';
@ -818,14 +825,14 @@ function getRunSummary(tr, runIndex, options) {
return [headingLine1, headingLine2, summary].join('\n\n'); return [headingLine1, headingLine2, summary].join('\n\n');
} }
function getSuiteSummary(ts, runIndex, suiteIndex, options) { function getSuiteSummary(ts, runIndex, suiteIndex, options) {
const groups = options.listTests === 'only-failed' ? ts.failedGroups : ts.groups; const groups = options.listTests === 'failed' ? ts.failedGroups : ts.groups;
if (groups.length === 0) { if (groups.length === 0) {
return ''; return '';
} }
const icon = getResultIcon(ts.result); const icon = getResultIcon(ts.result);
const content = groups const content = groups
.map(grp => { .map(grp => {
const tests = options.listTests === 'only-failed' ? grp.failedTests : grp.tests; const tests = options.listTests === 'failed' ? grp.failedTests : grp.tests;
if (tests.length === 0) { if (tests.length === 0) {
return ''; return '';
} }

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -31,12 +31,12 @@ async function main(): Promise<void> {
const workDirInput = core.getInput('working-directory', {required: false}) const workDirInput = core.getInput('working-directory', {required: false})
const token = core.getInput('token', {required: true}) const token = core.getInput('token', {required: true})
if (listSuites !== 'all' && listSuites !== 'only-failed') { if (listSuites !== 'all' && listSuites !== 'failed') {
core.setFailed(`Input parameter 'list-suites' has invalid value`) core.setFailed(`Input parameter 'list-suites' has invalid value`)
return return
} }
if (listTests !== 'all' && listTests !== 'only-failed' && listTests !== 'none') { if (listTests !== 'all' && listTests !== 'failed' && listTests !== 'none') {
core.setFailed(`Input parameter 'list-tests' has invalid value`) core.setFailed(`Input parameter 'list-tests' has invalid value`)
return return
} }

View file

@ -4,8 +4,8 @@ import {Align, Icon, link, table} from '../utils/markdown-utils'
import {slug} from '../utils/slugger' import {slug} from '../utils/slugger'
export interface ReportOptions { export interface ReportOptions {
listSuites?: 'all' | 'only-failed' listSuites?: 'all' | 'failed'
listTests?: 'all' | 'only-failed' | 'none' listTests?: 'all' | 'failed' | 'none'
} }
export function getReport(results: TestRunResult[], options: ReportOptions = {}): string { export function getReport(results: TestRunResult[], options: ReportOptions = {}): string {
@ -23,7 +23,7 @@ export function getReport(results: TestRunResult[], options: ReportOptions = {})
if (options.listTests !== 'none') { if (options.listTests !== 'none') {
const suitesSummary = results const suitesSummary = results
.map((tr, runIndex) => { .map((tr, runIndex) => {
const suites = options.listSuites === 'only-failed' ? tr.failedSuites : tr.suites const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites
return suites return suites
.map((ts, suiteIndex) => getSuiteSummary(ts, runIndex, suiteIndex, options)) .map((ts, suiteIndex) => getSuiteSummary(ts, runIndex, suiteIndex, options))
.filter(str => str !== '') .filter(str => str !== '')
@ -87,11 +87,11 @@ function getRunSummary(tr: TestRunResult, runIndex: number, options: ReportOptio
const headingLine1 = `### ${tr.path}` const headingLine1 = `### ${tr.path}`
const headingLine2 = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.` const headingLine2 = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`
const suites = options.listSuites === 'only-failed' ? tr.failedSuites : tr.suites const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites
const suitesSummary = suites.map((s, suiteIndex) => { const suitesSummary = suites.map((s, suiteIndex) => {
const tsTime = `${Math.round(s.time)}ms` const tsTime = `${Math.round(s.time)}ms`
const tsName = s.name const tsName = s.name
const skipLink = options.listTests === 'none' || (options.listTests === 'only-failed' && s.result !== 'failed') const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed')
const tsAddr = makeSuiteSlug(runIndex, suiteIndex, tsName).link const tsAddr = makeSuiteSlug(runIndex, suiteIndex, tsName).link
const tsNameLink = skipLink ? tsName : link(tsName, tsAddr) const tsNameLink = skipLink ? tsName : link(tsName, tsAddr)
const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : '' const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : ''
@ -113,7 +113,7 @@ function getRunSummary(tr: TestRunResult, runIndex: number, options: ReportOptio
} }
function getSuiteSummary(ts: TestSuiteResult, runIndex: number, suiteIndex: number, options: ReportOptions): string { function getSuiteSummary(ts: TestSuiteResult, runIndex: number, suiteIndex: number, options: ReportOptions): string {
const groups = options.listTests === 'only-failed' ? ts.failedGroups : ts.groups const groups = options.listTests === 'failed' ? ts.failedGroups : ts.groups
if (groups.length === 0) { if (groups.length === 0) {
return '' return ''
} }
@ -121,7 +121,7 @@ function getSuiteSummary(ts: TestSuiteResult, runIndex: number, suiteIndex: numb
const icon = getResultIcon(ts.result) const icon = getResultIcon(ts.result)
const content = groups const content = groups
.map(grp => { .map(grp => {
const tests = options.listTests === 'only-failed' ? grp.failedTests : grp.tests const tests = options.listTests === 'failed' ? grp.failedTests : grp.tests
if (tests.length === 0) { if (tests.length === 0) {
return '' return ''
} }