Skip to content

Commit

Permalink
Merge pull request #55 from oodle-ai/main
Browse files Browse the repository at this point in the history
Parse attributeless <failure> tags correctly
  • Loading branch information
ethomson authored Jan 15, 2025
2 parents 4cdf687 + d63e209 commit 8e33c5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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>

0 comments on commit 8e33c5c

Please sign in to comment.