Skip to content

Commit

Permalink
Simplify 'only-failed' to 'failed'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Jan 28, 2021
1 parent f55c011 commit 96e91aa
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:

# Limits which test suites are listed:
# all
# only-failed
# failed
list-suites: 'all'

# Limits which test cases are listed:
Expand Down
5 changes: 1 addition & 4 deletions __tests__/dotnet-trx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import {ParseOptions} from '../src/parsers/parser-types'
import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/file-utils'



describe('dotnet-trx tests', () => {
it('matches report snapshot', async () => {

const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md')
const xmlFixture = {
Expand Down Expand Up @@ -49,7 +46,7 @@ describe('dotnet-trx tests', () => {
const result = await parseDotnetTrx([xmlFixture], opts)
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.writeFileSync(outputPath, report)
})
Expand Down
2 changes: 1 addition & 1 deletion __tests__/jest-junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('jest-junit tests', () => {
const result = await parseJestJunit([xmlFixture], opts)
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.writeFileSync(outputPath, report)
})
Expand Down
21 changes: 14 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ async function main(): Promise<void> {
const workDirInput = core.getInput('working-directory', {required: false})
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`)
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`)
return
}
Expand Down
18 changes: 9 additions & 9 deletions src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {Align, Icon, link, table} from '../utils/markdown-utils'
import {slug} from '../utils/slugger'

export interface ReportOptions {
listSuites?: 'all' | 'only-failed'
listTests?: 'all' | 'only-failed' | 'none'
listSuites?: 'all' | 'failed'
listTests?: 'all' | 'failed' | 'none'
}

export function getReport(results: TestRunResult[], options: ReportOptions = {}): string {
Expand All @@ -23,7 +23,7 @@ export function getReport(results: TestRunResult[], options: ReportOptions = {})
if (options.listTests !== 'none') {
const suitesSummary = results
.map((tr, runIndex) => {
const suites = options.listSuites === 'only-failed' ? tr.failedSuites : tr.suites
const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites
return suites
.map((ts, suiteIndex) => getSuiteSummary(ts, runIndex, suiteIndex, options))
.filter(str => str !== '')
Expand Down Expand Up @@ -54,9 +54,9 @@ export function getReport(results: TestRunResult[], options: ReportOptions = {})
}

function applySort(results: TestRunResult[]): void {
results.sort((a,b) => a.path.localeCompare(b.path))
results.sort((a, b) => a.path.localeCompare(b.path))
for (const res of results) {
res.suites.sort((a,b)=> a.name.localeCompare(b.name))
res.suites.sort((a, b) => a.name.localeCompare(b.name))
}
}

Expand Down Expand Up @@ -87,11 +87,11 @@ function getRunSummary(tr: TestRunResult, runIndex: number, options: ReportOptio
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 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 tsTime = `${Math.round(s.time)}ms`
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 tsNameLink = skipLink ? tsName : link(tsName, tsAddr)
const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : ''
Expand All @@ -113,15 +113,15 @@ function getRunSummary(tr: TestRunResult, runIndex: number, options: ReportOptio
}

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) {
return ''
}

const icon = getResultIcon(ts.result)
const content = groups
.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) {
return ''
}
Expand Down

0 comments on commit 96e91aa

Please sign in to comment.