lib.buildReport.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jasmine-maven-plugin Show documentation
Show all versions of jasmine-maven-plugin Show documentation
A JavaScript unit test plugin that processes JavaScript sources and Jasmine specs, prepares test runner HTML files, executes Jasmine specs headlessly with HtmlUnit, and produces JUnit XML reports
(function() {
var jasmineMavenPlugin = window.jasmineMavenPlugin = window.jasmineMavenPlugin || {};
var reporter,reportedItems,specCount,failureCount,pendingCount;
jasmineMavenPlugin.printReport = function(r, config) {
config = config || {};
reporter = r, reportedItems=[], specCount=0, failureCount=0, pendingCount=0;
var result;
if (config.format === 'progress') {
result = printProgressFormat(jasmine.getEnv().topSuite().children);
} else {
result = buildDocumentationFormatReport(jasmine.getEnv().topSuite().children,0);
}
result += describeFailureSentences(reporter);
result += "\n\nResults: "+specCount+" specs, "+failureCount+" failures, "+pendingCount+" pending\n";
return result;
};
var indent = function(indentLevel) {
var indentStr = '';
for(var i=0;i linesPerRow) {
for (var i=0; i < report.length; i+=linesPerRow) {
result += report.substring(i,i+linesPerRow) + '\n';
};
} else {
result += report;
}
return result;
};
var buildProgressFormatReport = function(items) {
var output = '';
if (items) {
for (var i=0; i < items.length; i++) {
var item = items[i];
if(item instanceof jasmine.Spec) {
specCount++;
var result = resultForSpec(item);
if (result.status == 'failed') {
failureCount++;
output += 'F';
} else if (result.status == 'pending') {
pendingCount++;
} else {
output += '.';
}
}
reportedItems.push(item);
output += buildProgressFormatReport(item.children);
}
}
return output;
};
var buildDocumentationFormatReport = function(items,indentLevel) {
var line = '';
if (items) {
for(var i=0;i 0 && indentLevel === 0 ? '\n' : '')+"\n"+indent(indentLevel)+item.description;
if(item instanceof jasmine.Spec) {
specCount++;
var result = resultForSpec(item);
if(result.status == 'failed') {
failureCount++;
line += describeFailureMessages(result.failedExpectations,indentLevel+1);
} else if (result.status == 'pending') {
pendingCount++;
line += " <<< PENDING";
}
}
reportedItems.push(item);
line += buildDocumentationFormatReport(item.children,indentLevel+1);
}
}
}
return line;
};
var buildFailureSentences = function(components,failures,sentence) {
for (var i=0; i < components.length; i++) {
var component = components[i];
var desc = sentence ? sentence + ' ' : '';
var children = component.children;
if(children && children.length > 0) {
buildFailureSentences(children,failures,desc+component.name);
} else {
var result = resultForSpec(component);
if(result.result == 'failed') {
failures.push(desc + 'it ' + component.name + describeMessages(result.messages,2));
}
}
}
};
var resultForSpec = function(spec){
var specResults = reporter.specs();
for (var i=0; i < specResults.length; i++) {
if (spec.id == specResults[i].id) {
return specResults[i];
}
}
return {};
};
var describeFailureSentences = function() {
var result = '';
var failures = [];
buildFailureSentences(reporter.suites(),failures);
if(failures.length > 0) {
result += '\n\n';
result += failures.length + ' failure' + (failures.length !== 1 ? 's' : '') + ':'
for (var i=0; i < failures.length; i++) {
result += '\n\n ' + (i+1) + '.) ' + failures[i];
};
}
return result;
};
var inArray = function(arr,val) {
var result = false;
for(var i=0;i