Skip to content

Comments

Parse attributeless <failure> tags correctly#55

Merged
ethomson merged 1 commit intotest-summary:mainfrom
oodle-ai:main
Jan 15, 2025
Merged

Parse attributeless <failure> tags correctly#55
ethomson merged 1 commit intotest-summary:mainfrom
oodle-ai:main

Conversation

@sujeet
Copy link
Contributor

@sujeet sujeet commented Dec 1, 2024

jest-junit generates failure tags that have no attributes, only inner text. For example: <failure>Failed!</failure>.

The xml2js library seems to produce different objects based on whether a tag has attributes. See the minimal example:

var parseString = require('xml2js').parseString;
var print = (err, result) => console.log(JSON.stringify(result, null, 2))
var parse = (xmlStr) => parseString(xmlStr, print)

parse('<a b="c">d</a>')
{
  "a": {
    "_": "d",
    "$": {
      "b": "c"
    }
  }
}

parse('<a>d</a>')
{
  "a": "d"
}

Notice how the second output above is not {"a": {"_": "d"}}

With this change, we take into account this difference while parsing the failure messages.

[`jest-junit`](https://github.com/jest-community/jest-junit)
generates failure tags that have no attributes, only inner text.
For example: `<failure>Failed!</failure>`.

The [`xml2js`](https://www.npmjs.com/package/xml2js) library seems to
produce different objects based on whether a tag has attributes.
See the minimal example:
```js
var parseString = require('xml2js').parseString;
var print = (err, result) => console.log(JSON.stringify(result, null, 2))
var parse = (xmlStr) => parseString(xmlStr, print)

parse('<a b="c">d</a>')
{
  "a": {
    "_": "d",
    "$": {
      "b": "c"
    }
  }
}

parse('<a>d</a>')
{
  "a": "d"
}
```

Notice how the second output above is not `{"a": {"_": "d"}}`

With this change, we take into account this difference while
parsing the failure messages.
@ethomson
Copy link
Member

Thanks for the fix!

@ethomson ethomson merged commit 8e33c5c into test-summary:main Jan 15, 2025
@KyleLilly KyleLilly mentioned this pull request Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants