Skip to content

Commit

Permalink
Add summary badge to report
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Jan 24, 2021
1 parent 92cb68e commit 42eb11a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 6 deletions.
2 changes: 2 additions & 0 deletions __tests__/__outputs__/dart-json.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)

### fixtures/dart-json.json

**6** tests were completed in **3.760s** with **1** passed, **1** skipped and **4** failed.
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__outputs__/dotnet-trx.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%201%20skipped%2C%203%20failed-critical)

### fixtures/dotnet-trx.trx

**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.
Expand Down
2 changes: 2 additions & 0 deletions __tests__/__outputs__/jest-junit.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)

### fixtures/jest-junit.xml

**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed.
Expand Down
4 changes: 3 additions & 1 deletion __tests__/__snapshots__/dart-json.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ dart:isolate _RawReceivePortImpl._handleMessage
"title": "[test\\\\second_test.dart] Timeout test",
},
],
"summary": "### fixtures/dart-json.json
"summary": "![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)
### fixtures/dart-json.json
**6** tests were completed in **3.760s** with **1** passed, **1** skipped and **4** failed.
Expand Down
4 changes: 3 additions & 1 deletion __tests__/__snapshots__/dotnet-trx.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Actual: 2",
"title": "[DotnetTests.XUnitTests.CalculatorTests] Failing_Test",
},
],
"summary": "### fixtures/dotnet-trx.trx
"summary": "![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%201%20skipped%2C%203%20failed-critical)
### fixtures/dotnet-trx.trx
**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.
Expand Down
4 changes: 3 additions & 1 deletion __tests__/__snapshots__/jest-junit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Received: false
"title": "[__tests__\\\\second.test.js] Timeout test",
},
],
"summary": "### fixtures/jest-junit.xml
"summary": "![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)
### fixtures/jest-junit.xml
**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed.
Expand Down
22 changes: 21 additions & 1 deletion 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.

24 changes: 23 additions & 1 deletion src/report/get-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,36 @@ import {Align, Icon, link, table} from '../utils/markdown-utils'
import {slug} from '../utils/slugger'

export default function getReport(results: TestRunResult[]): string {
const badge = getBadge(results)
const runsSummary = results.map(getRunSummary).join('\n\n')
const suites = results
.flatMap(tr => tr.suites)
.map((ts, i) => getSuiteSummary(ts, i))
.join('\n')

const suitesSection = `# Test Suites\n\n${suites}`
return [runsSummary, suitesSection].join('\n\n')
return [badge, runsSummary, suitesSection].join('\n\n')
}

function getBadge(results: TestRunResult[]): string {
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)

const passedText = passed > 0 ? `${passed} passed` : null
const skippedText = skipped > 0 ? `${skipped} skipped` : null
const failedText = failed > 0 ? `${failed} failed` : null
const message = [passedText, skippedText, failedText].filter(s => s != null).join(', ') || 'none'
let color = 'success'
if (failed > 0) {
color = 'critical'
} else if (passed === 0 && failed === 0) {
color = 'yellow'
}

const uri = encodeURIComponent(`tests-${message}-${color}`)
const text = failed > 0 ? 'Tests failed' : 'Tests passed successfully'
return `![${text}](https://img.shields.io/badge/${uri})`
}

function getRunSummary(tr: TestRunResult): string {
Expand Down

0 comments on commit 42eb11a

Please sign in to comment.