Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit reporter does not output time #275 #283

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugosenari sorry this took so long. Why converting from array to dictionary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because is more easy to find them again later at testDone

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