Skip to content

Commit

Permalink
Add Suite#timeElapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Sep 5, 2014
1 parent 8494eed commit d278328
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
17 changes: 12 additions & 5 deletions lib/Suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ define([
afterEach: null,
teardown: null,
error: null,
timeElapsed: null,
_grep: null,
_remote: null,

Expand Down Expand Up @@ -266,6 +267,7 @@ define([
function finishRun(error) {
if (started) {
if (self.publishAfterSetup) {
self.timeElapsed = Date.now() - startTime;
topic.publish('/suite/end', self);
}

Expand All @@ -276,6 +278,7 @@ define([
}

if (!self.publishAfterSetup) {
self.timeElapsed = Date.now() - startTime;
topic.publish('/suite/end', self);
}

Expand All @@ -287,21 +290,24 @@ define([
}
}

var started = false,
dfd = new Deferred(),
self = this,
tests = this.tests,
i = 0;
var startTime;
var started = false;
var dfd = new Deferred();
var self = this;
var tests = this.tests;
var i = 0;

if (!self.publishAfterSetup) {
topic.publish('/suite/start', self);
started = true;
startTime = Date.now();
}

call('setup').then(function () {
if (self.publishAfterSetup) {
started = true;
topic.publish('/suite/start', self);
startTime = Date.now();
}
}).then(runNextTest, handleFatalError);

Expand All @@ -314,6 +320,7 @@ define([
sessionId: this.sessionId,
hasParent: !!this.parent,
tests: this.tests.map(function (test) { return test.toJSON(); }),
timeElapsed: this.timeElapsed,
numTests: this.numTests,
numFailedTests: this.numFailedTests,
numSkippedTests: this.numSkippedTests,
Expand Down
18 changes: 5 additions & 13 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ define([
// Accumulator for total number of failed tests
var failCount = 0;

// Clock tick for start of reporter's 'start' method
var startTick = 0;

var failedFilter = null;

var fragment = document.createDocumentFragment();
Expand Down Expand Up @@ -66,12 +63,12 @@ define([
return formattedValue;
}

function generateSummary() {
function generateSummary(suite) {
if (summaryNodes.length === 0) {
return;
}

var duration = (new Date()).getTime() - startTick;
var duration = suite.timeElapsed;
var percentPassed = Math.round((1 - (failCount / testCount || 0)) * 10000) / 100;
var rowInfo = [
suiteCount,
Expand Down Expand Up @@ -207,8 +204,6 @@ define([
reportNode = document.createElement('tbody');
tableNode.appendChild(reportNode);
reportContainer.appendChild(tableNode);

startTick = (new Date()).getTime();
},

'/suite/start': function (suite) {
Expand Down Expand Up @@ -243,13 +238,13 @@ define([
rowNode.className += ' indent';
}

runningSuites[suite.id] = { node: rowNode, startDate: new Date() };
runningSuites[suite.id] = { node: rowNode };
++indentLevel;
},

'/suite/end': function (suite) {
if (!suite.parent) {
generateSummary();
generateSummary(suite);

injectCSS();

Expand All @@ -270,9 +265,6 @@ define([
return;
}

// Get end date early so we are not including the time spent generating reports in our calculation
var endDate = new Date();

var rowNode = runningSuites[suite.id].node;
var numTests = suite.numTests;
var numFailedTests = suite.numFailedTests;
Expand Down Expand Up @@ -317,7 +309,7 @@ define([
// Duration cell
cellNode = document.createElement('td');
cellNode.className = 'numeric duration';
cellNode.appendChild(document.createTextNode(formatDuration(endDate - runningSuites[suite.id].startDate)));
cellNode.appendChild(document.createTextNode(formatDuration(suite.timeElapsed)));
rowNode.appendChild(cellNode);

--indentLevel;
Expand Down

0 comments on commit d278328

Please sign in to comment.