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

Parse attributeless <failure> tags correctly #55

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
6 changes: 5 additions & 1 deletion src/test_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ async function parseJunitXml(xml: any): Promise<TestResult> {
const element = failure_or_error[0]

message = element.$ ? element.$.message : undefined
details = element._
if (typeof element === "string") {
details = element
} else {
details = element._
}

counts.failed++
} else {
Expand Down
8 changes: 8 additions & 0 deletions test/junit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,12 @@ describe("junit", async () => {
it("parses testsuite with no failure message", async () => {
const result = await parseJunitFile(`${resourcePath}/07-no-failure-message.xml`)
})

it("parses attributeless failure tags", async () => {
// https://github.com/jest-community/jest-junit generates failure tags
// that have no attributes, only inner text.
// Example: <failure>Failed!</failure>
const result = await parseJunitFile(`${resourcePath}/08-failure-noattr-only-innertext.xml`)
expect(result.suites[0].cases[0].details).to.eql("Failed!")
})
})
8 changes: 8 additions & 0 deletions test/resources/junit/08-failure-noattr-only-innertext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="jest tests">
<testsuite name="testsuite1">
<testcase id="com.example.test1" name="Test 1" time="0.001">
<failure>Failed!</failure>
</testcase>
</testsuite>
</testsuites>