Skip to content

mocha escapes the grave character incorrectly in xunit reporter #3002

@arwilczek90

Description

@arwilczek90

Prerequisites

  • Checked that your issue isn't already filed by cross referencing issues with the common mistake label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
    node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

The mocha xunit reporter escapes the grave character (`) incorrectly in the xunit reporter when placed in the spec name. It escapes it with ` which is valid in html but not in xml causing junit parsers (specifically jenkins in my test case but I have tested it with the w3schools validator as well with the same result) to not be able to parse test results.

Steps to Reproduce

Run the following code in the terminal.

npm init --yes
npm i -D mocha
echo "const assert = require('assert');\nit('this `creates` bad xml', () => {assert.ok(true);});" > test.js
./node_modules/.bin/mocha -R xunit -O output=report.xml test.js

Then take the resulting file and run it through an xml validator or a junit test result parser.

Expected behavior: [What you expect to happen]
produces a valid xml file

<testsuite name="Mocha Tests" tests="1" failures="0" errors="0" skipped="0" timestamp="Mon, 11 Sep 2017 18:19:30 GMT" time="0.004">
<testcase classname="" name="this `creates` bad xml" time="0.001"/>
</testsuite>

Actual behavior: [What actually happens]
Produces an invalid xml file with &grave; instead of the "`" character

<testsuite name="Mocha Tests" tests="1" failures="0" errors="0" skipped="0" timestamp="Mon, 11 Sep 2017 18:19:30 GMT" time="0.004">
<testcase classname="" name="this &grave;creates&grave; bad xml" time="0.001"/>
</testsuite>

Reproduces how often: [What percentage of the time does it reproduce?]
I am able to reproduce this 100% of the time.

Versions

Happens on mocha>=3.5.1
tested on osx 10.12 and ubuntu 14.04 with node 6.11.1, 6.11.2, 6.11.3

Additional Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions