michaelleeallen / mocha-junit-reporter

A JUnit XML reporter for mocha.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"time" attribute of "testsuite" tag too long for jenkins xUnit

Avalancs opened this issue · comments

Hi! Hope I'm reporting this at the right place.

I'm using cypress 3.4.1 with mocha 6.1.4 and mocha-junit-reporter 1.23.1 to generate junit test output, with the following parameters in cypress.json:

"reporterOptions": {
"mochaFile": "test-result/JUnit-[hash].xml",
"toConsole": false,
"outputs": true,
"antMode": true,
"jenkinsMode": true
}

I'm trying to publish them on jenkins with the xUnit plugin, but received the following message in the build log:
WARNING: At line 11 of file:/.../test-result/JUnit-e78c63fec54eadbedb7d94d2b95e557f.xml:cvc-pattern-valid: Value '5.007000000000001' is not facet-valid with respect to pattern '(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?' for type 'SUREFIRE_TIME'.

Said 11th line:
<testsuite name="Root Suite.Issues test" timestamp="2019-09-16T16:08:13" tests="3" package="Root Suite.Issues test" hostname="undefined" id="1" errors="0" failures="0" time="5.007000000000001">

As you can see the time attribute has too many fractional digits, failing the xsd of xUnit (which is hopefully Ant compliant). Can you round/truncate it?

Although I am no javascript expert, I tried adding .toFixed(4) to every possible location in the code where the 'time' attribute is set, there were still xml's produced with too many digits. My guess is that when exporting to xml the values get re-rounded?

In the end as a workaround I wrote a groovy lib that would load the xml's, round the floats and convert them to string, and then overwrite the original xml file with the modified contents.

The problem still happens with version 1.23.3 (with jenkinsMode=true,antMode=true):

WARNING: At line 11 of file:a7493d66b9f1746cd34c1cef56451fd3.xml:cvc-pattern-valid: Value '69.44999999999999' is not facet-valid with respect to pattern '(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?' for type 'SUREFIRE_TIME'.
WARNING: At line 11 of file:a7493d66b9f1746cd34c1cef56451fd3.xml:cvc-attribute.3: The value '69.44999999999999' of attribute 'time' on element 'testsuite' is not valid with respect to its type, 'SUREFIRE_TIME'.

WARNING: At line 11 of file:cb754fe9e80190fde564527874a44a77.xml:cvc-pattern-valid: Value '28.406999999999996' is not facet-valid with respect to pattern '(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?' for type 'SUREFIRE_TIME'.
WARNING: At line 11 of file:cb754fe9e80190fde564527874a44a77.xml:cvc-attribute.3: The value '28.406999999999996' of attribute 'time' on element 'testsuite' is not valid with respect to its type, 'SUREFIRE_TIME'.

WARNING: At line 11 of file:f458459d91e468a29a372ec1e04a2d62.xml:cvc-pattern-valid: Value '58.276999999999994' is not facet-valid with respect to pattern '(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?' for type 'SUREFIRE_TIME'.
WARNING: At line 11 of file:f458459d91e468a29a372ec1e04a2d62.xml:cvc-attribute.3: The value '58.276999999999994' of attribute 'time' on element 'testsuite' is not valid with respect to its type, 'SUREFIRE_TIME'.

Can you provide a minimum working example so that we can test/fix this regression?

I don't think so. It depends on the length of the test and it is fairly random. Altough I have not seen it happening with tests that takes more than a minute yet.

The problem happens with cypress testing that has this reporter bundled. At best I could try to put together some project with tests on a random website and hope the problem will persist there.

Hey Guys
I am facing similar issue in Jenkins:

16:11:12 WARNING: At line 2 of file:pathToreport/final-report.xml:cvc-pattern-valid: Value '0.0000' is not facet-valid with respect to pattern '(([0-9]{0,3},)*[0-9]{3}|[0-9]{0,3})*(\.[0-9]{0,3})?' for type 'SUREFIRE_TIME'.
16:11:12 WARNING: At line 2 of file:file:pathToreport/final-report.xml:cvc-attribute.3: The value '0.0000' of attribute 'time' on element 'testsuite' is not valid with respect to its type, 'SUREFIRE_TIME'.

Any thoughts what could be done to have them displayed?
Thanks

I think this issue has been resolved