Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add folded option #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ Options are specified on the [`with` map](https://docs.github.com/en/actions/usi
show: "fail, skip"
```

* **`folded`: display test details in a folded details block** (optional)
When enabled the details for each test result will be nested in a details blocks which can be expanded by clicking on the test name. This option can be `true` or `false` (The default).

```yaml
- uses: test-summary/action@v2
with:
paths: "test/results/**/TEST-*.xml"
folded: true
```

FAQ
---
* **How is the summary graphic generated? Does any of my data ever leave GitHub?**
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ inputs:
description: File to write with rendered output
show:
description: Types of tests to show in the results table
folded:
description: Show each result in a folded details block
runs:
using: 'node20'
main: 'index.js'
Expand Down
13 changes: 12 additions & 1 deletion src/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function dashboardSummary(result: TestResult): string {
return `<img src="${dashboardUrl}?p=${count.passed}&f=${count.failed}&s=${count.skipped}" alt="${summary}">`
}

export function dashboardResults(result: TestResult, show: number): string {
export function dashboardResults(result: TestResult, show: number, folded: boolean): string {
let table = "<table>"
let count = 0

Expand All @@ -41,6 +41,9 @@ export function dashboardResults(result: TestResult, show: number): string {
}

table += "<tr><td>"
if (folded) {
table += "<details><summary>"
}

const icon = statusIcon(testcase.status)
if (icon) {
Expand All @@ -55,6 +58,10 @@ export function dashboardResults(result: TestResult, show: number): string {
table += escapeHTML(testcase.description)
}

if (folded) {
table += "</summary>"
}

if (testcase.message || testcase.details) {
table += "<br/>\n"

Expand All @@ -71,6 +78,10 @@ export function dashboardResults(result: TestResult, show: number): string {
}
}

if (folded) {
table += "</details>"
}

table += "</td></tr>\n"

count++
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function run(): Promise<void> {
const pathGlobs = core.getInput("paths", { required: true })
const outputFile = core.getInput("output") || process.env.GITHUB_STEP_SUMMARY || "-"
const showList = core.getInput("show")
const folded = JSON.parse(core.getInput("folded") || "false")

/*
* Given paths may either be an individual path (eg "foo.xml"),
Expand Down Expand Up @@ -99,7 +100,7 @@ async function run(): Promise<void> {
let output = dashboardSummary(total)

if (show) {
output += dashboardResults(total, show)
output += dashboardResults(total, show, folded)
}

if (outputFile === "-") {
Expand Down
6 changes: 3 additions & 3 deletions test/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("dashboard", async () => {
}
]
}
const actual = dashboardResults(result, TestStatus.Fail)
const actual = dashboardResults(result, TestStatus.Fail, false)
expect(actual).contains("name escaped &lt;properly&gt;")
expect(actual).contains("description escaped &quot;properly&quot;")
expect(actual).contains("another name escaped &apos;properly&apos;")
Expand All @@ -51,7 +51,7 @@ describe("dashboard", async () => {
}
]
}
const actual = dashboardResults(result, TestStatus.Fail)
const actual = dashboardResults(result, TestStatus.Fail, false)
expect(actual).contains("&lt;no name&gt;")
})

Expand All @@ -72,7 +72,7 @@ describe("dashboard", async () => {
]
}

const actual = dashboardResults(result, TestStatus.Fail)
const actual = dashboardResults(result, TestStatus.Fail, false)

expect(actual).contains("message escaped &lt;properly&gt;")
expect(actual).contains("details escaped &lt;properly&gt;")
Expand Down