eslint: JUnit reporter XML output missing required classname attribute on testcase element

When producing JUnit XML output, the resulting XML file seems to be missing required attributes.

I found the following XML Schema Definition that indicates the required fields.

While I don’t think it is necessary to support every optional attribute, I think it would make sense to provide those that are mandatory.

I stumbled across this, as I tried to integrate ESlint output in GitLab CI, but GitLab CI will not display the report, as it requires the classname attribute to be present.

There is also an issue filed over at GitLab, but maybe it was more obvious to fix the issue in ESlint.

If you think here’s the right place to fix this, I’d be happy to contribute a Pull Request.

Tell us about your environment

  • ESLint Version: v5.8.0
  • Node Version: v10.12.0
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration: ø

Configuration
#  cat eslintconfig.json
{
  "plugins": [],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module"
  },
  "extends": ["eslint:recommended"]
}
#  cat test.js
console.log('foo');

What did you expect to happen?

Expected the attribute classname to be present on element <testcase /> — I suggest that classname will be set to basename of the parents <testsuite/> file attribute.

<testsuites>
<testsuite package="org.eslint" time="0" tests="1" errors="1" name="/path/to/test.js">
  <testcase time="0" classname="test" name="org.eslint.no-console">…</testcase>
</testsuite>
</testsuites>

What actually happened? Please include the actual, raw output from ESLint.

<!-- ⇒  ./node_modules/.bin/eslint -c eslintconfig.json -f junit test.js -->
<testsuites>
<testsuite package="org.eslint" time="0" tests="1" errors="1" name="/path/to/test.js">
  <testcase time="0" name="org.eslint.no-console">… </testcase>
</testsuite>
</testsuites>

Are you willing to submit a pull request to fix this bug?

👍

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@platinumazure Sorry, I did not want to rush things. The empty string turned out to be not too useful in terms of GitLab’s CI Panel (though valid w.r.t. to the schema).

I am locally playing around with using the filepath, but trimmed relative to the project root and without the filename suffix to have a things a little more readable for humans.

Currently it I imagine something like this:

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
  <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Users/michael/Code/foo/foo-dev/src/frontend/controllers/PageController.js">
    <testcase time="0" name="org.eslint.no-console" classname="src/frontend/controllers/PageController">
      <failure message="Unexpected console statement."><![CDATA[line 41, col 9, Error - Unexpected console statement. (no-console)]]></failure>
    </testcase>
  </testsuite>
</testsuites>

Still this decision is kind of arbitrary as obviously the reporting format was invented for Java.

Feedback is very welcome. 😃

mostly correct in the UI — multiple errors of the same category per File will only show up once —

@micheee, 90% of something, is better than 0% of nothing, hombré. I’ll take what I can get!

We ran into this also. To me, the filename would be useful

The Filename — maybe without the extension — would be my proposal as well.

Any other thoughts?

We ran into this also. To me, the filename would be useful