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

Conversation

sujeet
Copy link

@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.
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.

1 participant