run result - passed green, failed red

This commit is contained in:
Steve Conover 2011-02-28 15:13:46 -08:00
parent e6a080039f
commit e8c8a0bdfd
2 changed files with 43 additions and 6 deletions

View File

@ -6,11 +6,16 @@ describe("TrivialNodeReporter", function() {
function red(str) { return '\033[31m' + str + '\033[0m'; } function red(str) { return '\033[31m' + str + '\033[0m'; }
function yellow(str) { return '\033[33m' + str + '\033[0m'; } function yellow(str) { return '\033[33m' + str + '\033[0m'; }
function prefixGreen(str) { return '\033[32m' + str; }
function prefixRed(str) { return '\033[31m' + str; }
var newline = "\n"; var newline = "\n";
var passingSpec = { results: function(){ return {passed:function(){return true;}}; } }, var passingSpec = { results: function(){ return {passed:function(){return true;}}; } },
failingSpec = { results: function(){ return {passed:function(){return false;}}; } }, failingSpec = { results: function(){ return {passed:function(){return false;}}; } },
skippedSpec = { results: function(){ return {skipped:true}; } }; skippedSpec = { results: function(){ return {skipped:true}; } },
passingRun = { results: function(){ return {failedCount: 0}; } },
failingRun = { results: function(){ return {failedCount: 7}; } };
function repeatedlyInvoke(f, times) { for(var i=0; i<times; i++) f(times+1); } function repeatedlyInvoke(f, times) { for(var i=0; i<times; i++) f(times+1); }
@ -100,6 +105,25 @@ describe("TrivialNodeReporter", function() {
}); });
}); });
describe('Finishes', function(){
it("prints Finished in green if the test run succeeded", function(){
this.reporter.reportRunnerResults(passingRun);
expect(this.fakeSys.getOutput()).toContain(
newline + prefixGreen("Finished")
);
});
it("prints Finished in red if the test run failed", function(){
this.reporter.reportRunnerResults(failingRun);
expect(this.fakeSys.getOutput()).toContain(
newline + prefixRed("Finished")
);
});
});
}); });
}); });

View File

@ -17,10 +17,15 @@ jasmine.TrivialNodeReporter = function(sys) {
function newline() { sys.print("\n"); } function newline() { sys.print("\n"); }
function started() { sys.print("Started"); newline(); } function started() { sys.print("Started"); newline(); }
function greenDot() { sys.print(greenStr(".")); } function greenDot() { sys.print(greenStr(".")); }
function redF() { sys.print(redStr("F")); } function redF() { sys.print(redStr("F")); }
function yellowStar() { sys.print(yellowStr("*")); } function yellowStar() { sys.print(yellowStr("*")); }
function finished(colorF) { newline(); sys.print(colorF("Finished")); }
function greenFinished() { finished(greenStr); }
function redFinished() { finished(redStr); }
@ -52,4 +57,12 @@ jasmine.TrivialNodeReporter = function(sys) {
} }
startNewLineIfNecessary(); startNewLineIfNecessary();
}; };
this.reportRunnerResults = function(runner) {
if (runner.results().failedCount === 0) {
greenFinished();
} else {
redFinished();
}
};
}; };