Skip to content

Commit bcfc7a4

Browse files
committed
Ensure that test time attribute is capped at 4 digits after the decimal
1 parent 19eee3e commit bcfc7a4

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,20 @@ MochaJUnitReporter.prototype.getXml = function(testsuites) {
388388
var _cases = suite.testsuite.slice(_casesIndex);
389389
var missingProps;
390390

391-
_suiteAttr.failures = 0;
392391
_suiteAttr.time = 0;
392+
_suiteAttr.failures = 0;
393393
_suiteAttr.skipped = 0;
394394

395+
var suiteTime = 0;
395396
_cases.forEach(function(testcase) {
396397
var lastNode = testcase.testcase[testcase.testcase.length - 1];
397398

398399
_suiteAttr.skipped += Number('skipped' in lastNode);
399400
_suiteAttr.failures += Number('failure' in lastNode);
400-
_suiteAttr.time += testcase.testcase[0]._attr.time;
401+
suiteTime += testcase.testcase[0]._attr.time;
402+
testcase.testcase[0]._attr.time = testcase.testcase[0]._attr.time.toFixed(4);
401403
});
404+
_suiteAttr.time = suiteTime.toFixed(4);
402405

403406
if (antMode) {
404407
missingProps = ['system-out', 'system-err'];
@@ -417,8 +420,8 @@ MochaJUnitReporter.prototype.getXml = function(testsuites) {
417420
if (!_suiteAttr.skipped) {
418421
delete _suiteAttr.skipped;
419422
}
420-
421-
totalSuitesTime += _suiteAttr.time;
423+
424+
totalSuitesTime += suiteTime;
422425
totalTests += _suiteAttr.tests;
423426
});
424427

@@ -427,7 +430,7 @@ MochaJUnitReporter.prototype.getXml = function(testsuites) {
427430
var rootSuite = {
428431
_attr: {
429432
name: this._options.testsuitesTitle,
430-
time: totalSuitesTime,
433+
time: totalSuitesTime.toFixed(4),
431434
tests: totalTests,
432435
failures: stats.failures
433436
}

test/mocha-junit-reporter-spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ describe('mocha-junit-reporter', function() {
3838
});
3939

4040
if (!options.skipPassedTests) {
41-
runner.pass(new Test('Foo can weez the juice', 'can weez the juice', 1));
41+
runner.pass(new Test('Foo can weez the juice', 'can weez the juice', 101));
4242
}
4343

44-
runner.fail(new Test('Bar can narfle the garthog', 'can narfle the garthog', 1), {
44+
runner.fail(new Test('Bar can narfle the garthog', 'can narfle the garthog', 2002), {
4545
stack: options.invalidChar + 'expected garthog to be dead' + options.invalidChar
4646
});
4747

48-
runner.fail(new Test('Baz can behave like a flandip', 'can behave like a flandip', 1), {
48+
runner.fail(new Test('Baz can behave like a flandip', 'can behave like a flandip', 30003), {
4949
name: 'BazError',
5050
message: 'expected baz to be masher, a hustler, an uninvited grasper of cone'
5151
});
@@ -54,7 +54,7 @@ describe('mocha-junit-reporter', function() {
5454
title: 'Another suite!',
5555
tests: [1]
5656
});
57-
runner.pass(new Test('Another suite', 'works', 4));
57+
runner.pass(new Test('Another suite', 'works', 400004));
5858

5959
if (options && options.includePending) {
6060
runner.startSuite({

test/mock-results.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function(stats, options) {
88
name: "Mocha Tests",
99
tests: 3,
1010
failures: "2",
11-
time: "0.007"
11+
time: "432.1100"
1212
}
1313
},
1414
{
@@ -19,15 +19,15 @@ module.exports = function(stats, options) {
1919
timestamp: stats.start.toISOString().substr(0,stats.start.toISOString().indexOf('.')),
2020
tests: "2",
2121
failures: "2",
22-
time: "0.003"
22+
time: "32.1060"
2323
}
2424
},
2525
{
2626
testcase: {
2727
_attr: {
2828
name: "Foo can weez the juice",
2929
classname: "can weez the juice",
30-
time: "0.001"
30+
time: "0.1010"
3131
}
3232
}
3333
},
@@ -37,7 +37,7 @@ module.exports = function(stats, options) {
3737
_attr: {
3838
name: "Bar can narfle the garthog",
3939
classname: "can narfle the garthog",
40-
time: "0.001"
40+
time: "2.0020"
4141
}
4242
},
4343
{
@@ -57,7 +57,7 @@ module.exports = function(stats, options) {
5757
_attr: {
5858
name: "Baz can behave like a flandip",
5959
classname: "can behave like a flandip",
60-
time: "0.001"
60+
time: "30.0030"
6161
}
6262
},
6363
{
@@ -81,15 +81,15 @@ module.exports = function(stats, options) {
8181
timestamp: stats.start.toISOString().substr(0,stats.start.toISOString().indexOf('.')),
8282
tests: "1",
8383
failures: "0",
84-
time: "0.004"
84+
time: "400.0040"
8585
}
8686
},
8787
{
8888
testcase: {
8989
_attr: {
9090
name: "Another suite",
9191
classname: "works",
92-
time: "0.004"
92+
time: "400.0040"
9393
}
9494
}
9595
}
@@ -99,8 +99,8 @@ module.exports = function(stats, options) {
9999
};
100100

101101
if (options && options.skipPassedTests) {
102-
data.testsuites[0]._attr.time = "0.006";
103-
data.testsuites[1].testsuite[0]._attr.time = "0.002";
102+
data.testsuites[0]._attr.time = "432.0090";
103+
data.testsuites[1].testsuite[0]._attr.time = "32.0050";
104104
data.testsuites[1].testsuite.splice(1, 1);
105105
}
106106

@@ -137,7 +137,7 @@ module.exports = function(stats, options) {
137137
tests: "1",
138138
failures: "0",
139139
skipped: "1",
140-
time: "0"
140+
time: "0.0000"
141141
}
142142
},
143143
{
@@ -146,7 +146,7 @@ module.exports = function(stats, options) {
146146
_attr: {
147147
name: "Pending suite",
148148
classname: "pending",
149-
time: "0"
149+
time: "0.0000"
150150
}
151151
},
152152
{

0 commit comments

Comments
 (0)