specs/assertions/failures
This commit is contained in:
parent
7d2b900b48
commit
882c287191
@ -11,11 +11,11 @@ describe("TrivialNodeReporter", function() {
|
||||
|
||||
var newline = "\n";
|
||||
|
||||
var passingSpec = { results: function(){ return {passed:function(){return true;}}; } },
|
||||
failingSpec = { results: function(){ return {passed:function(){return false;}}; } },
|
||||
skippedSpec = { results: function(){ return {skipped:true}; } },
|
||||
passingRun = { results: function(){ return {failedCount: 0}; } },
|
||||
failingRun = { results: function(){ return {failedCount: 7}; } };
|
||||
var passingSpec = { results: function(){ return {passed: function(){return true;}}; } },
|
||||
failingSpec = { results: function(){ return {passed: function(){return false;}}; } },
|
||||
skippedSpec = { results: function(){ return {skipped: true}; } },
|
||||
passingRun = { results: function(){ return {failedCount: 0, specs: function(){return [null, null, null];}}; } },
|
||||
failingRun = { results: function(){ return {failedCount: 7, specs: function(){return [null, null, null];}}; } };
|
||||
|
||||
function repeatedlyInvoke(f, times) { for(var i=0; i<times; i++) f(times+1); }
|
||||
|
||||
@ -109,24 +109,24 @@ describe("TrivialNodeReporter", function() {
|
||||
describe('A suite runs', function(){
|
||||
it("remembers suite results", function(){
|
||||
var emptyResults = function(){return {items_:[]};};
|
||||
this.reporter.reportSuiteResults({description:"Oven", results:emptyResults})
|
||||
this.reporter.reportSuiteResults({description:"Mixer", results:emptyResults})
|
||||
this.reporter.reportSuiteResults({description:"Oven", results:emptyResults});
|
||||
this.reporter.reportSuiteResults({description:"Mixer", results:emptyResults});
|
||||
|
||||
var self = this
|
||||
var descriptions = []
|
||||
var self = this;
|
||||
var descriptions = [];
|
||||
for(var i=0; i<self.reporter.suiteResults.length; i++)
|
||||
descriptions.push(self.reporter.suiteResults[i].description)
|
||||
descriptions.push(self.reporter.suiteResults[i].description);
|
||||
|
||||
expect(descriptions).toEqual(["Oven", "Mixer"])
|
||||
expect(descriptions).toEqual(["Oven", "Mixer"]);
|
||||
});
|
||||
|
||||
it("creates a description out of the current suite and any parent suites", function(){
|
||||
var emptyResults = function(){return {items_:[]};};
|
||||
var grandparentSuite = {description:"My house", results:emptyResults}
|
||||
var parentSuite = {description:"kitchen", parentSuite: grandparentSuite, results:emptyResults}
|
||||
this.reporter.reportSuiteResults({description:"oven", parentSuite: parentSuite, results:emptyResults})
|
||||
var grandparentSuite = {description:"My house", results:emptyResults};
|
||||
var parentSuite = {description:"kitchen", parentSuite: grandparentSuite, results:emptyResults};
|
||||
this.reporter.reportSuiteResults({description:"oven", parentSuite: parentSuite, results:emptyResults});
|
||||
|
||||
expect(this.reporter.suiteResults[0].description).toEqual("My house kitchen oven")
|
||||
expect(this.reporter.suiteResults[0].description).toEqual("My house kitchen oven");
|
||||
});
|
||||
|
||||
it("gathers failing spec results from the suite. the spec must have a description.", function(){
|
||||
@ -140,74 +140,87 @@ describe("TrivialNodeReporter", function() {
|
||||
{failedCount:88, description:"specFour"},
|
||||
{failedCount:3}
|
||||
]
|
||||
}
|
||||
}})
|
||||
};
|
||||
}});
|
||||
|
||||
expect(this.reporter.suiteResults[0].failedSpecResults).
|
||||
toEqual([
|
||||
{failedCount:99, description:"specTwo"},
|
||||
{failedCount:88, description:"specFour"}
|
||||
])
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Finishes', function(){
|
||||
it("prints Finished in green if the test run succeeded", function(){
|
||||
this.reporter.reportRunnerResults(passingRun);
|
||||
describe('Finished line', function(){
|
||||
|
||||
expect(this.fakeSys.getOutput()).toContain(
|
||||
newline + prefixGreen("Finished")
|
||||
);
|
||||
it("prints the elapsed time in the summary message", function(){
|
||||
this.reporter.now = function(){return 1000;};
|
||||
this.reporter.reportRunnerStarting();
|
||||
this.reporter.now = function(){return 1777;};
|
||||
this.reporter.reportRunnerResults(passingRun);
|
||||
expect(this.fakeSys.getOutput()).toContain("0.777 seconds");
|
||||
});
|
||||
|
||||
it("prints round time numbers correctly", function(){
|
||||
var self = this;
|
||||
function run(startTime, endTime) {
|
||||
self.fakeSys.clear();
|
||||
self.reporter.runnerStartTime = startTime;
|
||||
self.reporter.now = function(){return endTime;};
|
||||
self.reporter.reportRunnerResults(passingRun);
|
||||
}
|
||||
|
||||
run(1000, 11000);
|
||||
expect(this.fakeSys.getOutput()).toContain("10 seconds");
|
||||
|
||||
run(1000, 2000);
|
||||
expect(this.fakeSys.getOutput()).toContain("1 seconds");
|
||||
|
||||
run(1000, 1100);
|
||||
expect(this.fakeSys.getOutput()).toContain("0.1 seconds");
|
||||
|
||||
run(1000, 1010);
|
||||
expect(this.fakeSys.getOutput()).toContain("0.01 seconds");
|
||||
|
||||
run(1000, 1001);
|
||||
expect(this.fakeSys.getOutput()).toContain("0.001 seconds");
|
||||
});
|
||||
|
||||
it("prints the full finished message", function(){
|
||||
this.reporter.now = function(){return 1000;};
|
||||
this.reporter.reportRunnerStarting();
|
||||
this.reporter.now = function(){return 1777;};
|
||||
this.reporter.reportRunnerResults(failingRun);
|
||||
expect(this.fakeSys.getOutput()).toContain("Finished in 0.777 seconds");
|
||||
});
|
||||
});
|
||||
|
||||
it("prints Finished in red if the test run failed", function(){
|
||||
this.reporter.reportRunnerResults(failingRun);
|
||||
describe("specs/assertions/failures summary", function(){
|
||||
it("prints statistics in green if there were no failures", function() {
|
||||
this.reporter.reportRunnerResults({
|
||||
results:function(){return {specs: function(){return [null, null, null];}, totalCount: 7, failedCount: 0};}
|
||||
});
|
||||
expect(this.fakeSys.getOutput()).
|
||||
toContain("3 specs, 7 assertions, 0 failures");
|
||||
});
|
||||
|
||||
expect(this.fakeSys.getOutput()).toContain(
|
||||
newline + prefixRed("Finished")
|
||||
);
|
||||
});
|
||||
it("prints statistics in red if there was a failure", function() {
|
||||
this.reporter.reportRunnerResults({
|
||||
results:function(){return {specs: function(){return [null, null, null];}, totalCount: 7, failedCount: 3};}
|
||||
});
|
||||
expect(this.fakeSys.getOutput()).
|
||||
toContain("3 specs, 7 assertions, 3 failures");
|
||||
});
|
||||
|
||||
it("prints the elapsed time in the summary message", function(){
|
||||
this.reporter.now = function(){return 1000;};
|
||||
this.reporter.reportRunnerStarting();
|
||||
this.reporter.now = function(){return 1777;};
|
||||
this.reporter.reportRunnerResults(passingRun);
|
||||
expect(this.fakeSys.getOutput()).toContain("0.777 seconds");
|
||||
});
|
||||
|
||||
it("prints round time numbers correctly", function(){
|
||||
var self = this;
|
||||
function run(startTime, endTime) {
|
||||
self.fakeSys.clear();
|
||||
self.reporter.runnerStartTime = startTime;
|
||||
self.reporter.now = function(){return endTime;};
|
||||
self.reporter.reportRunnerResults(passingRun);
|
||||
}
|
||||
|
||||
run(1000, 11000);
|
||||
expect(this.fakeSys.getOutput()).toContain("10 seconds");
|
||||
|
||||
run(1000, 2000);
|
||||
expect(this.fakeSys.getOutput()).toContain("1 seconds");
|
||||
|
||||
run(1000, 1100);
|
||||
expect(this.fakeSys.getOutput()).toContain("0.1 seconds");
|
||||
|
||||
run(1000, 1010);
|
||||
expect(this.fakeSys.getOutput()).toContain("0.01 seconds");
|
||||
|
||||
run(1000, 1001);
|
||||
expect(this.fakeSys.getOutput()).toContain("0.001 seconds");
|
||||
});
|
||||
|
||||
it("altogether now", function(){
|
||||
this.reporter.now = function(){return 1000;};
|
||||
this.reporter.reportRunnerStarting();
|
||||
this.reporter.now = function(){return 1777;};
|
||||
this.reporter.reportRunnerResults(failingRun);
|
||||
expect(this.fakeSys.getOutput()).toContain(red("Finished in 0.777 seconds"));
|
||||
it("handles pluralization with 1's ones appropriately", function() {
|
||||
this.reporter.reportRunnerResults({
|
||||
results:function(){return {specs: function(){return [null];}, totalCount: 1, failedCount: 1};}
|
||||
});
|
||||
expect(this.fakeSys.getOutput()).
|
||||
toContain("1 spec, 1 assertion, 1 failure");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -22,9 +22,15 @@ jasmine.TrivialNodeReporter = function(sys) {
|
||||
function redF() { sys.print(redStr("F")); }
|
||||
function yellowStar() { sys.print(yellowStr("*")); }
|
||||
|
||||
function finished(colorF, elapsed) { newline(); sys.print(colorF("Finished in " + elapsed/1000 + " seconds")); }
|
||||
function greenFinished(elapsed) { finished(greenStr, elapsed); }
|
||||
function redFinished(elapsed) { finished(redStr, elapsed); }
|
||||
function plural(str, count) { return count == 1 ? str : str + "s"; }
|
||||
|
||||
function finished(elapsed) { newline(); sys.print("Finished in " + elapsed/1000 + " seconds"); }
|
||||
function summary(colorF, specs, assertions, failed) { newline();
|
||||
colorF(sys.print(specs + " " + plural("spec", specs) + ", " +
|
||||
assertions + " " + plural("assertion", assertions) + ", " +
|
||||
failed + " " + plural("failure", failed))); }
|
||||
function greenSummary(specs, assertions, failed){ summary(greenStr, specs, assertions, failed); }
|
||||
function redSummary(specs, assertions, failed){ summary(redStr, specs, assertions, failed); }
|
||||
|
||||
|
||||
|
||||
@ -41,9 +47,9 @@ jasmine.TrivialNodeReporter = function(sys) {
|
||||
}
|
||||
|
||||
function fullSuiteDescription(suite) {
|
||||
var fullDescription = suite.description
|
||||
if (suite.parentSuite) fullDescription = fullSuiteDescription(suite.parentSuite) + " " + fullDescription
|
||||
return fullDescription
|
||||
var fullDescription = suite.description;
|
||||
if (suite.parentSuite) fullDescription = fullSuiteDescription(suite.parentSuite) + " " + fullDescription ;
|
||||
return fullDescription;
|
||||
}
|
||||
|
||||
var startNewLineIfNecessary = lineEnder(defaultColumnsPerLine);
|
||||
@ -76,19 +82,20 @@ jasmine.TrivialNodeReporter = function(sys) {
|
||||
};
|
||||
|
||||
suite.results().items_.forEach(function(spec){
|
||||
if (spec.failedCount > 0 && spec.description) suiteResult.failedSpecResults.push(spec)
|
||||
if (spec.failedCount > 0 && spec.description) suiteResult.failedSpecResults.push(spec);
|
||||
});
|
||||
|
||||
this.suiteResults.push(suiteResult)
|
||||
this.suiteResults.push(suiteResult);
|
||||
};
|
||||
|
||||
this.reportRunnerResults = function(runner) {
|
||||
var elapsed = this.now() - this.runnerStartTime;
|
||||
finished(this.now() - this.runnerStartTime);
|
||||
|
||||
if (runner.results().failedCount === 0) {
|
||||
greenFinished(elapsed);
|
||||
var results = runner.results();
|
||||
if (results.failedCount === 0) {
|
||||
greenSummary(results.specs().length, results.totalCount, results.failedCount);
|
||||
} else {
|
||||
redFinished(elapsed);
|
||||
redSummary(results.specs().length, results.totalCount, results.failedCount);
|
||||
}
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user