From fc3a27130271df3f7858fbda4972062eff6c9ecd Mon Sep 17 00:00:00 2001 From: Hugo Sena Ribeiro Date: Fri, 28 Nov 2014 16:47:33 +0000 Subject: [PATCH 1/2] Add time attribute in Junit Reporter #275 - Convert curModule.testcases from array to dictionary; - Set 'start' end 'end' at suites and testcases; --- lib/reporters/junit.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/reporters/junit.js b/lib/reporters/junit.js index 5400526fd..a5419c7e1 100644 --- a/lib/reporters/junit.js +++ b/lib/reporters/junit.js @@ -97,7 +97,7 @@ exports.run = function (files, opts, callback) { return path.resolve(p); }); - var modules = {} + var modules = {}; var curModule; nodeunit.runFiles(paths, { @@ -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 Date: Fri, 28 Nov 2014 16:49:32 +0000 Subject: [PATCH 2/2] Add time attribute in Junit Reporter #275 - Using suites as dictionary; - Using start, end to print time attributes in testsuite and testcase. --- share/junit.xml.ejs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/share/junit.xml.ejs b/share/junit.xml.ejs index c1db5bbec..f36ddffce 100644 --- a/share/junit.xml.ejs +++ b/share/junit.xml.ejs @@ -4,10 +4,12 @@ - <% for (var j=0; j < suite.testcases.length; j++) { %> - <% var testcase=suites[i].testcases[j]; %> - + tests="<%= suite.tests %>" + time="<%= (suite.end - suite.start)/1000 %>" + > + <% for (var testCaseName in suite.testcases) { %> + <% var testcase=suite.testcases[testCaseName]; %> + <% if (testcase.failure) { %> <% if (testcase.failure.backtrace) { %><%= testcase.failure.backtrace %><% } %>