Skip to content

Commit

Permalink
Ensure that test time attribute is capped at 3 digits after the decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
aviskase authored and clayreimann committed Oct 14, 2021
1 parent e406663 commit fc3a735
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -431,7 +431,7 @@ MochaJUnitReporter.prototype.getXml = function(testsuites) {
// suiteTime has unrounded time as a Number of milliseconds
var suiteTime = _suiteAttr.time;

_suiteAttr.time = (suiteTime / 1000 || 0).toFixed(4);
_suiteAttr.time = (suiteTime / 1000 || 0).toFixed(3);
_suiteAttr.timestamp = new Date(_suiteAttr.timestamp).toISOString().slice(0, -5);
_suiteAttr.failures = 0;
_suiteAttr.skipped = 0;
Expand All @@ -441,7 +441,7 @@ MochaJUnitReporter.prototype.getXml = function(testsuites) {

_suiteAttr.skipped += Number('skipped' in lastNode);
_suiteAttr.failures += Number('failure' in lastNode);
testcase.testcase[0]._attr.time = testcase.testcase[0]._attr.time.toFixed(4);
testcase.testcase[0]._attr.time = testcase.testcase[0]._attr.time.toFixed(3);
});

if (antMode) {
Expand Down Expand Up @@ -470,7 +470,7 @@ MochaJUnitReporter.prototype.getXml = function(testsuites) {
var rootSuite = {
_attr: {
name: this._options.testsuitesTitle,
time: (stats.duration / 1000 || 0).toFixed(4),
time: (stats.duration / 1000 || 0).toFixed(3),
tests: totalTests,
failures: stats.failures
}
Expand Down
20 changes: 10 additions & 10 deletions test/mock-results.js
Expand Up @@ -10,7 +10,7 @@ module.exports = function(stats, options) {
name: "Mocha Tests",
tests: 4,
failures: "2",
time: ((stats.duration || 0) / 1000).toFixed(4)
time: ((stats.duration || 0) / 1000).toFixed(3)
}
},
{
Expand All @@ -21,7 +21,7 @@ module.exports = function(stats, options) {
timestamp: "1970-01-01T00:00:00", // ISO timestamp truncated to the second
tests: "0",
failures: "0",
time: "0.0000"
time: "0.000"
}
}
]
Expand All @@ -34,15 +34,15 @@ module.exports = function(stats, options) {
timestamp: "1970-01-01T00:00:00",
tests: "3",
failures: "2",
time: "100.0010"
time: "100.001"
}
},
{
testcase: {
_attr: {
name: "Foo Bar can weez the juice",
classname: "can weez the juice",
time: "0.1010"
time: "0.101"
}
}
},
Expand All @@ -52,7 +52,7 @@ module.exports = function(stats, options) {
_attr: {
name: "Foo Bar can narfle the garthog",
classname: "can narfle the garthog",
time: "2.0020"
time: "2.002"
}
},
{
Expand All @@ -72,7 +72,7 @@ module.exports = function(stats, options) {
_attr: {
name: "Foo Bar can behave like a flandip",
classname: "can behave like a flandip",
time: "30.0030"
time: "30.003"
}
},
{
Expand All @@ -96,15 +96,15 @@ module.exports = function(stats, options) {
timestamp: "1970-01-01T00:01:40", // new Date(100001).toISOString().slice(0, -5)
tests: "1",
failures: "0",
time: "400.0050"
time: "400.005"
}
},
{
testcase: {
_attr: {
name: "Another suite! works",
classname: "works",
time: "400.0040"
time: "400.004"
}
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ module.exports = function(stats, options) {
tests: "1",
failures: "0",
skipped: "1",
time: "0.0000"
time: "0.000"
}
},
{
Expand All @@ -157,7 +157,7 @@ module.exports = function(stats, options) {
_attr: {
name: "Pending suite! pending",
classname: "pending",
time: "0.0000"
time: "0.000"
}
},
{
Expand Down

0 comments on commit fc3a735

Please sign in to comment.