Skip to content

Commit

Permalink
Merge pull request #40 from gstokkink/include-failure-or-error-messag…
Browse files Browse the repository at this point in the history
…e-on-dashboard

Include failure or error message on dashboard
  • Loading branch information
ethomson authored Feb 22, 2024
2 parents 50e3bd4 + 01d9c8f commit 92b70a8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ export function dashboardResults(result: TestResult, show: number): string {
table += escapeHTML(testcase.description)
}

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

if (testcase.message) {
table += "<pre><code>"
table += escapeHTML(testcase.message)
table += "</code></pre>"
}

if (testcase.details) {
table += "<pre><code>"
table += escapeHTML(testcase.details)
table += "</code></pre>"
}
}

table += "</td></tr>\n"
Expand Down
12 changes: 10 additions & 2 deletions src/test_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface TestCase {
status: TestStatus
name?: string
description?: string
message?: string
details?: string
duration?: string
}
Expand Down Expand Up @@ -235,15 +236,21 @@ async function parseJunitXml(xml: any): Promise<TestResult> {
const name = testcase.$.name
const duration = testcase.$.time

let failure_or_error
let message: string | undefined = undefined
let details: string | undefined = undefined

if (testcase.skipped) {
status = TestStatus.Skip

counts.skipped++
} else if (testcase.failure || testcase.error) {
} else if (failure_or_error = testcase.failure || testcase.error) {
status = TestStatus.Fail
details = (testcase.failure || testcase.error)[0]._

const element = failure_or_error[0]

message = element.$.message
details = element._

counts.failed++
} else {
Expand All @@ -254,6 +261,7 @@ async function parseJunitXml(xml: any): Promise<TestResult> {
status: status,
name: name,
description: classname,
message: message,
details: details,
duration: duration
})
Expand Down
23 changes: 23 additions & 0 deletions test/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,27 @@ describe("dashboard", async () => {
const actual = dashboardResults(result, TestStatus.Fail)
expect(actual).contains("&lt;no name&gt;")
})

it("includes details and message when present, using proper escaping", async () => {
const result: TestResult = {
counts: { passed: 0, failed: 1, skipped: 0 },
suites: [
{
cases: [
{
status: TestStatus.Fail,
name: "Test",
message: "message escaped <properly>",
details: "details escaped <properly>"
}
]
}
]
}

const actual = dashboardResults(result, TestStatus.Fail)

expect(actual).contains("message escaped &lt;properly&gt;")
expect(actual).contains("details escaped &lt;properly&gt;")
})
})
24 changes: 23 additions & 1 deletion test/junit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,29 @@ describe("junit", async () => {
expect(result.suites[0].cases[1].name).to.eql("passesTestTwo")
expect(result.suites[0].cases[2].name).to.eql("passesTestThree")
expect(result.suites[0].cases[3].name).to.eql("passesTestFour")
expect(result.suites[0].cases[4].name).to.eql("failsTestFive")

const case_with_message = result.suites[0].cases[4]

expect(case_with_message.name).to.eql("failsTestFive")
expect(case_with_message.message).to.be.a("string")
expect(case_with_message.details).to.be.a("string")

const message = "expected:<42> but was:<43>"

expect(case_with_message.message).to.eql(message)

const details = `junit.framework.AssertionFailedError: expected:<42> but was:<43>
\tat test.failsTestFive(Unknown Source)
\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
`

expect(case_with_message.details).to.eql(details)

expect(result.suites[0].cases[5].name).to.eql("failsTestSix")
expect(result.suites[0].cases[6].name).to.eql("failsTestSeven")
expect(result.suites[0].cases[7].name).to.eql("failsTestEight")
Expand Down

0 comments on commit 92b70a8

Please sign in to comment.