Extracted results state management out of the HTML reporter

[#153891435]
This commit is contained in:
Steve Gravrock
2017-12-23 11:09:15 -08:00
parent c79ce125c0
commit b439e2fb37
2 changed files with 102 additions and 58 deletions

View File

@@ -5,6 +5,45 @@ jasmineRequire.HtmlReporter = function(j$) {
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) {
var env = options.env || {},
getContainer = options.getContainer,
@@ -17,9 +56,6 @@ jasmineRequire.HtmlReporter = function(j$) {
filterSpecs = options.filterSpecs,
timer = options.timer || noopTimer,
results = [],
specsExecuted = 0,
failureCount = 0,
pendingSpecCount = 0,
htmlReporterMain,
symbols,
failedSuites = [];
@@ -48,12 +84,10 @@ jasmineRequire.HtmlReporter = function(j$) {
var summary = createDom('div', {className: 'jasmine-summary'});
var topResults = new j$.ResultsNode({}, '', null),
currentParent = topResults;
var stateBuilder = new ResultsStateBuilder();
this.suiteStarted = function(result) {
currentParent.addChild(result, 'suite');
currentParent = currentParent.last();
stateBuilder.suiteStarted(result);
};
this.suiteDone = function(result) {
@@ -61,27 +95,21 @@ jasmineRequire.HtmlReporter = function(j$) {
failedSuites.push(result);
}
if (currentParent == topResults) {
return;
}
currentParent = currentParent.parent;
stateBuilder.suiteDone(result);
};
this.specStarted = function(result) {
currentParent.addChild(result, 'spec');
stateBuilder.specStarted(result);
};
var failures = [];
this.specDone = function(result) {
stateBuilder.specDone(result);
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
console.error('Spec \'' + result.fullName + '\' has no expectations.');
}
if (result.status != 'disabled') {
specsExecuted++;
}
if (!symbols){
symbols = find('.jasmine-symbol-summary');
}
@@ -94,8 +122,6 @@ jasmineRequire.HtmlReporter = function(j$) {
));
if (result.status == 'failed') {
failureCount++;
var failure =
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
createDom('div', {className: 'jasmine-description'},
@@ -113,10 +139,6 @@ jasmineRequire.HtmlReporter = function(j$) {
failures.push(failure);
}
if (result.status == 'pending') {
pendingSpecCount++;
}
};
this.jasmineDone = function(doneResult) {
@@ -179,8 +201,8 @@ jasmineRequire.HtmlReporter = function(j$) {
}
};
if (specsExecuted < totalSpecsDefined) {
var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
if (stateBuilder.specsExecuted < totalSpecsDefined) {
var skippedMessage = 'Ran ' + stateBuilder.specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
var skippedLink = addToExistingQueryString('spec', '');
alert.appendChild(
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
@@ -192,9 +214,9 @@ jasmineRequire.HtmlReporter = function(j$) {
var statusBarClassName = 'jasmine-bar ';
if (totalSpecsDefined > 0) {
statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
statusBarMessage += pluralize('spec', stateBuilder.specsExecuted) + ', ' + pluralize('failure', stateBuilder.failureCount);
if (stateBuilder.pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', stateBuilder.pendingSpecCount); }
statusBarClassName += (stateBuilder.failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
} else {
statusBarClassName += 'jasmine-skipped';
statusBarMessage += 'No specs found';
@@ -229,7 +251,7 @@ jasmineRequire.HtmlReporter = function(j$) {
var results = find('.jasmine-results');
results.appendChild(summary);
summaryList(topResults, summary);
summaryList(stateBuilder.topResults, summary);
function summaryList(resultsTree, domParent) {
var specListNode;