Skip to content

Commit

Permalink
Merge pull request #283 from hugosenari/junit-report-time
Browse files Browse the repository at this point in the history
JUnit reporter does not output time #275
  • Loading branch information
mreinstein authored Oct 23, 2017
2 parents 62388a3 + 39f493d commit 72e6563
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 13 additions & 5 deletions lib/reporters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ exports.run = function (files, opts, callback) {
return path.resolve(p);
});

var modules = {}
var modules = {};
var curModule;

nodeunit.runFiles(paths, {
Expand All @@ -108,13 +108,21 @@ exports.run = function (files, opts, callback) {
errorCount: 0,
failureCount: 0,
tests: 0,
testcases: [],
name: name
testcases: {},
name: name,
start: new Date().getTime()
};
modules[name] = curModule;
},
testStart: function(name) {
curModule.testcases[name] = {name: name, start : new Date().getTime()};
},
moduleDone: function(name) {
curModule.end = new Date().getTime();
},
testDone: function (name, assertions) {
var testcase = {name: name};
var testcase = curModule.testcases[name];
testcase.end = new Date().getTime();
for (var i=0; i<assertions.length; i++) {
var a = assertions[i];
if (a.failed()) {
Expand All @@ -134,7 +142,7 @@ exports.run = function (files, opts, callback) {
}
}
curModule.tests++;
curModule.testcases.push(testcase);
curModule.testcases[name] = testcase;;
},
done: function (assertions) {
var end = new Date().getTime();
Expand Down
10 changes: 6 additions & 4 deletions share/junit.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<testsuite name="<%= suite.name %>"
errors="<%= suite.errorCount %>"
failures="<%= suite.failureCount %>"
tests="<%= suite.tests %>">
<% for (var j=0; j < suite.testcases.length; j++) { %>
<% var testcase=suites[i].testcases[j]; %>
<testcase name="<%= testcase.name %>">
tests="<%= suite.tests %>"
time="<%= (suite.end - suite.start)/1000 %>"
>
<% for (var testCaseName in suite.testcases) { %>
<% var testcase=suite.testcases[testCaseName]; %>
<testcase name="<%= testcase.name %>" time="<%= (testcase.end - testcase.start)/1000 %>">
<% if (testcase.failure) { %>
<failure message="<%= testcase.failure.message %>">
<% if (testcase.failure.backtrace) { %><%= testcase.failure.backtrace %><% } %>
Expand Down

0 comments on commit 72e6563

Please sign in to comment.