Extracted results state management out of the HTML reporter
[#153891435]
This commit is contained in:
@@ -34,6 +34,45 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
elapsed: function() { return 0; }
|
elapsed: function() { return 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function ResultsStateBuilder() {
|
||||||
|
this.topResults = new j$.ResultsNode({}, '', null);
|
||||||
|
this.currentParent = this.topResults;
|
||||||
|
this.specsExecuted = 0;
|
||||||
|
this.failureCount = 0;
|
||||||
|
this.pendingSpecCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultsStateBuilder.prototype.suiteStarted = function(result) {
|
||||||
|
this.currentParent.addChild(result, 'suite');
|
||||||
|
this.currentParent = this.currentParent.last();
|
||||||
|
};
|
||||||
|
|
||||||
|
ResultsStateBuilder.prototype.suiteDone = function(result) {
|
||||||
|
if (this.currentParent !== this.topResults) {
|
||||||
|
this.currentParent = this.currentParent.parent;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ResultsStateBuilder.prototype.specStarted = function(result) {
|
||||||
|
this.currentParent.addChild(result, 'spec');
|
||||||
|
};
|
||||||
|
|
||||||
|
ResultsStateBuilder.prototype.specDone = function(result) {
|
||||||
|
if (result.status !== 'disabled') {
|
||||||
|
this.specsExecuted++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status === 'failed') {
|
||||||
|
this.failureCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status == 'pending') {
|
||||||
|
this.pendingSpecCount++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function HtmlReporter(options) {
|
function HtmlReporter(options) {
|
||||||
var env = options.env || {},
|
var env = options.env || {},
|
||||||
getContainer = options.getContainer,
|
getContainer = options.getContainer,
|
||||||
@@ -46,9 +85,6 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
filterSpecs = options.filterSpecs,
|
filterSpecs = options.filterSpecs,
|
||||||
timer = options.timer || noopTimer,
|
timer = options.timer || noopTimer,
|
||||||
results = [],
|
results = [],
|
||||||
specsExecuted = 0,
|
|
||||||
failureCount = 0,
|
|
||||||
pendingSpecCount = 0,
|
|
||||||
htmlReporterMain,
|
htmlReporterMain,
|
||||||
symbols,
|
symbols,
|
||||||
failedSuites = [];
|
failedSuites = [];
|
||||||
@@ -77,12 +113,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
var summary = createDom('div', {className: 'jasmine-summary'});
|
var summary = createDom('div', {className: 'jasmine-summary'});
|
||||||
|
|
||||||
var topResults = new j$.ResultsNode({}, '', null),
|
var stateBuilder = new ResultsStateBuilder();
|
||||||
currentParent = topResults;
|
|
||||||
|
|
||||||
this.suiteStarted = function(result) {
|
this.suiteStarted = function(result) {
|
||||||
currentParent.addChild(result, 'suite');
|
stateBuilder.suiteStarted(result);
|
||||||
currentParent = currentParent.last();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.suiteDone = function(result) {
|
this.suiteDone = function(result) {
|
||||||
@@ -90,27 +124,21 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
failedSuites.push(result);
|
failedSuites.push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentParent == topResults) {
|
stateBuilder.suiteDone(result);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentParent = currentParent.parent;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.specStarted = function(result) {
|
this.specStarted = function(result) {
|
||||||
currentParent.addChild(result, 'spec');
|
stateBuilder.specStarted(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
var failures = [];
|
var failures = [];
|
||||||
this.specDone = function(result) {
|
this.specDone = function(result) {
|
||||||
|
stateBuilder.specDone(result);
|
||||||
|
|
||||||
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
|
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
|
||||||
console.error('Spec \'' + result.fullName + '\' has no expectations.');
|
console.error('Spec \'' + result.fullName + '\' has no expectations.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.status != 'disabled') {
|
|
||||||
specsExecuted++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!symbols){
|
if (!symbols){
|
||||||
symbols = find('.jasmine-symbol-summary');
|
symbols = find('.jasmine-symbol-summary');
|
||||||
}
|
}
|
||||||
@@ -123,8 +151,6 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
));
|
));
|
||||||
|
|
||||||
if (result.status == 'failed') {
|
if (result.status == 'failed') {
|
||||||
failureCount++;
|
|
||||||
|
|
||||||
var failure =
|
var failure =
|
||||||
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
|
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
|
||||||
createDom('div', {className: 'jasmine-description'},
|
createDom('div', {className: 'jasmine-description'},
|
||||||
@@ -142,10 +168,6 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
failures.push(failure);
|
failures.push(failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.status == 'pending') {
|
|
||||||
pendingSpecCount++;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.jasmineDone = function(doneResult) {
|
this.jasmineDone = function(doneResult) {
|
||||||
@@ -208,8 +230,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (specsExecuted < totalSpecsDefined) {
|
if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
||||||
var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
|
var skippedMessage = 'Ran ' + stateBuilder.specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
|
||||||
var skippedLink = addToExistingQueryString('spec', '');
|
var skippedLink = addToExistingQueryString('spec', '');
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
|
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
|
||||||
@@ -221,9 +243,9 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
var statusBarClassName = 'jasmine-bar ';
|
var statusBarClassName = 'jasmine-bar ';
|
||||||
|
|
||||||
if (totalSpecsDefined > 0) {
|
if (totalSpecsDefined > 0) {
|
||||||
statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
|
statusBarMessage += pluralize('spec', stateBuilder.specsExecuted) + ', ' + pluralize('failure', stateBuilder.failureCount);
|
||||||
if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
|
if (stateBuilder.pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', stateBuilder.pendingSpecCount); }
|
||||||
statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
|
statusBarClassName += (stateBuilder.failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
|
||||||
} else {
|
} else {
|
||||||
statusBarClassName += 'jasmine-skipped';
|
statusBarClassName += 'jasmine-skipped';
|
||||||
statusBarMessage += 'No specs found';
|
statusBarMessage += 'No specs found';
|
||||||
@@ -258,7 +280,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
var results = find('.jasmine-results');
|
var results = find('.jasmine-results');
|
||||||
results.appendChild(summary);
|
results.appendChild(summary);
|
||||||
|
|
||||||
summaryList(topResults, summary);
|
summaryList(stateBuilder.topResults, summary);
|
||||||
|
|
||||||
function summaryList(resultsTree, domParent) {
|
function summaryList(resultsTree, domParent) {
|
||||||
var specListNode;
|
var specListNode;
|
||||||
|
|||||||
+51
-29
@@ -5,6 +5,45 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
elapsed: function() { return 0; }
|
elapsed: function() { return 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function ResultsStateBuilder() {
|
||||||
|
this.topResults = new j$.ResultsNode({}, '', null);
|
||||||
|
this.currentParent = this.topResults;
|
||||||
|
this.specsExecuted = 0;
|
||||||
|
this.failureCount = 0;
|
||||||
|
this.pendingSpecCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultsStateBuilder.prototype.suiteStarted = function(result) {
|
||||||
|
this.currentParent.addChild(result, 'suite');
|
||||||
|
this.currentParent = this.currentParent.last();
|
||||||
|
};
|
||||||
|
|
||||||
|
ResultsStateBuilder.prototype.suiteDone = function(result) {
|
||||||
|
if (this.currentParent !== this.topResults) {
|
||||||
|
this.currentParent = this.currentParent.parent;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ResultsStateBuilder.prototype.specStarted = function(result) {
|
||||||
|
this.currentParent.addChild(result, 'spec');
|
||||||
|
};
|
||||||
|
|
||||||
|
ResultsStateBuilder.prototype.specDone = function(result) {
|
||||||
|
if (result.status !== 'disabled') {
|
||||||
|
this.specsExecuted++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status === 'failed') {
|
||||||
|
this.failureCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status == 'pending') {
|
||||||
|
this.pendingSpecCount++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function HtmlReporter(options) {
|
function HtmlReporter(options) {
|
||||||
var env = options.env || {},
|
var env = options.env || {},
|
||||||
getContainer = options.getContainer,
|
getContainer = options.getContainer,
|
||||||
@@ -17,9 +56,6 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
filterSpecs = options.filterSpecs,
|
filterSpecs = options.filterSpecs,
|
||||||
timer = options.timer || noopTimer,
|
timer = options.timer || noopTimer,
|
||||||
results = [],
|
results = [],
|
||||||
specsExecuted = 0,
|
|
||||||
failureCount = 0,
|
|
||||||
pendingSpecCount = 0,
|
|
||||||
htmlReporterMain,
|
htmlReporterMain,
|
||||||
symbols,
|
symbols,
|
||||||
failedSuites = [];
|
failedSuites = [];
|
||||||
@@ -48,12 +84,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
var summary = createDom('div', {className: 'jasmine-summary'});
|
var summary = createDom('div', {className: 'jasmine-summary'});
|
||||||
|
|
||||||
var topResults = new j$.ResultsNode({}, '', null),
|
var stateBuilder = new ResultsStateBuilder();
|
||||||
currentParent = topResults;
|
|
||||||
|
|
||||||
this.suiteStarted = function(result) {
|
this.suiteStarted = function(result) {
|
||||||
currentParent.addChild(result, 'suite');
|
stateBuilder.suiteStarted(result);
|
||||||
currentParent = currentParent.last();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.suiteDone = function(result) {
|
this.suiteDone = function(result) {
|
||||||
@@ -61,27 +95,21 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
failedSuites.push(result);
|
failedSuites.push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentParent == topResults) {
|
stateBuilder.suiteDone(result);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentParent = currentParent.parent;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.specStarted = function(result) {
|
this.specStarted = function(result) {
|
||||||
currentParent.addChild(result, 'spec');
|
stateBuilder.specStarted(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
var failures = [];
|
var failures = [];
|
||||||
this.specDone = function(result) {
|
this.specDone = function(result) {
|
||||||
|
stateBuilder.specDone(result);
|
||||||
|
|
||||||
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
|
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
|
||||||
console.error('Spec \'' + result.fullName + '\' has no expectations.');
|
console.error('Spec \'' + result.fullName + '\' has no expectations.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.status != 'disabled') {
|
|
||||||
specsExecuted++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!symbols){
|
if (!symbols){
|
||||||
symbols = find('.jasmine-symbol-summary');
|
symbols = find('.jasmine-symbol-summary');
|
||||||
}
|
}
|
||||||
@@ -94,8 +122,6 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
));
|
));
|
||||||
|
|
||||||
if (result.status == 'failed') {
|
if (result.status == 'failed') {
|
||||||
failureCount++;
|
|
||||||
|
|
||||||
var failure =
|
var failure =
|
||||||
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
|
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
|
||||||
createDom('div', {className: 'jasmine-description'},
|
createDom('div', {className: 'jasmine-description'},
|
||||||
@@ -113,10 +139,6 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
|
|
||||||
failures.push(failure);
|
failures.push(failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.status == 'pending') {
|
|
||||||
pendingSpecCount++;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.jasmineDone = function(doneResult) {
|
this.jasmineDone = function(doneResult) {
|
||||||
@@ -179,8 +201,8 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (specsExecuted < totalSpecsDefined) {
|
if (stateBuilder.specsExecuted < totalSpecsDefined) {
|
||||||
var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
|
var skippedMessage = 'Ran ' + stateBuilder.specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
|
||||||
var skippedLink = addToExistingQueryString('spec', '');
|
var skippedLink = addToExistingQueryString('spec', '');
|
||||||
alert.appendChild(
|
alert.appendChild(
|
||||||
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
|
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
|
||||||
@@ -192,9 +214,9 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
var statusBarClassName = 'jasmine-bar ';
|
var statusBarClassName = 'jasmine-bar ';
|
||||||
|
|
||||||
if (totalSpecsDefined > 0) {
|
if (totalSpecsDefined > 0) {
|
||||||
statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
|
statusBarMessage += pluralize('spec', stateBuilder.specsExecuted) + ', ' + pluralize('failure', stateBuilder.failureCount);
|
||||||
if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
|
if (stateBuilder.pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', stateBuilder.pendingSpecCount); }
|
||||||
statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
|
statusBarClassName += (stateBuilder.failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
|
||||||
} else {
|
} else {
|
||||||
statusBarClassName += 'jasmine-skipped';
|
statusBarClassName += 'jasmine-skipped';
|
||||||
statusBarMessage += 'No specs found';
|
statusBarMessage += 'No specs found';
|
||||||
@@ -229,7 +251,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
var results = find('.jasmine-results');
|
var results = find('.jasmine-results');
|
||||||
results.appendChild(summary);
|
results.appendChild(summary);
|
||||||
|
|
||||||
summaryList(topResults, summary);
|
summaryList(stateBuilder.topResults, summary);
|
||||||
|
|
||||||
function summaryList(resultsTree, domParent) {
|
function summaryList(resultsTree, domParent) {
|
||||||
var specListNode;
|
var specListNode;
|
||||||
|
|||||||
Reference in New Issue
Block a user