diff --git a/src/dashboard.ts b/src/dashboard.ts index 90bf997..24fcb0b 100644 --- a/src/dashboard.ts +++ b/src/dashboard.ts @@ -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 += "
\n" - table += "
"
-                table += escapeHTML(testcase.details)
-                table += "
" + + if (testcase.message) { + table += "
"
+                    table += escapeHTML(testcase.message)
+                    table += "
" + } + + if (testcase.details) { + table += "
"
+                    table += escapeHTML(testcase.details)
+                    table += "
" + } } table += "\n" diff --git a/src/test_parser.ts b/src/test_parser.ts index 11a3346..830b193 100644 --- a/src/test_parser.ts +++ b/src/test_parser.ts @@ -34,6 +34,7 @@ export interface TestCase { status: TestStatus name?: string description?: string + message?: string details?: string duration?: string } @@ -235,15 +236,21 @@ async function parseJunitXml(xml: any): Promise { 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 { @@ -254,6 +261,7 @@ async function parseJunitXml(xml: any): Promise { status: status, name: name, description: classname, + message: message, details: details, duration: duration }) diff --git a/test/dashboard.ts b/test/dashboard.ts index ede9b51..5d93a15 100644 --- a/test/dashboard.ts +++ b/test/dashboard.ts @@ -54,4 +54,27 @@ describe("dashboard", async () => { const actual = dashboardResults(result, TestStatus.Fail) expect(actual).contains("<no name>") }) + + 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 ", + details: "details escaped " + } + ] + } + ] + } + + const actual = dashboardResults(result, TestStatus.Fail) + + expect(actual).contains("message escaped <properly>") + expect(actual).contains("details escaped <properly>") + }) }) diff --git a/test/junit.ts b/test/junit.ts index 109969d..891f69f 100644 --- a/test/junit.ts +++ b/test/junit.ts @@ -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")