beginning of trivial node reporter, based on jasmine-node. jshint rules exclude bad escapements WRT ansi colors, beacuse that's ok.

This commit is contained in:
Steve Conover 2011-02-28 13:35:53 -08:00
parent 9a12b32a3a
commit 528b5abeda
3 changed files with 117 additions and 0 deletions

View File

@ -29,6 +29,7 @@
<script type="text/javascript" src="../src/WaitsForBlock.js"></script>
<script type="text/javascript" src="../src/html/TrivialReporter.js"></script>
<script type="text/javascript" src="../src/node/TrivialNodeReporter.js"></script>
@ -50,6 +51,7 @@
<script type="text/javascript" src="suites/SpySpec.js"></script>
<script type="text/javascript" src="suites/SuiteSpec.js"></script>
<script type="text/javascript" src="suites/TrivialReporterSpec.js"></script>
<script type="text/javascript" src="suites/TrivialNodeReporterSpec.js"></script>
<script type="text/javascript" src="suites/WaitsForBlockSpec.js"></script>

View File

@ -0,0 +1,70 @@
describe("TrivialNodeReporter", function() {
var green = function(str) {
return '\033[32m' + str + '\033[0m'; //keep these literal. otherwise the test loses value as a test.
};
var red = function(str) {
return '\033[31m' + str + '\033[0m';
};
var newline = "\n";
beforeEach(function() {
this.fakeSys = (function(){
var output = "";
return {
puts:function(str) {output += str + "\n";},
print:function(str) {output += str;},
getOutput:function(){return output;}
};
})();
this.env = new jasmine.Env();
this.env.updateInterval = 0;
this.reporter = new jasmine.TrivialNodeReporter(this.fakeSys);
});
// reportSpecResults: function(spec) {
// var result = spec.results();
// var msg = '';
// if (result.passed())
// {
// msg = (colors) ? (ansi.green + '.' + ansi.none) : '.';
// // } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec?
// // msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*';
// } else {
// msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F';
// }
// sys.print(msg);
// if (columnCounter++ < 50) return;
// columnCounter = 0;
// sys.print('\n');
// },
describe('A Test Run', function(){
describe('A spec runs', function(){
it("prints a green dot if the spec passes", function(){
var passingSpec = {
results: function(){
return {passed:function(){return true;}};
}
};
this.reporter.reportSpecResults(passingSpec);
expect(this.fakeSys.getOutput()).toEqual(
green(".")
);
});
});
});
});

View File

@ -0,0 +1,45 @@
jasmine.TrivialNodeReporter = function(sys) {
this.sys = sys;
this.ansi = {
green: '\033[32m',
red: '\033[31m',
yellow: '\033[33m',
none: '\033[0m'
};
};
// reportSpecResults: function(spec) {
// var result = spec.results();
// var msg = '';
// if (result.passed())
// {
// msg = (colors) ? (ansi.green + '.' + ansi.none) : '.';
// // } else if (result.skipped) { TODO: Research why "result.skipped" returns false when "xit" is called on a spec?
// // msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*';
// } else {
// msg = (colors) ? (ansi.red + 'F' + ansi.none) : 'F';
// }
// sys.print(msg);
// if (columnCounter++ < 50) return;
// columnCounter = 0;
// sys.print('\n');
// },
jasmine.TrivialNodeReporter.prototype._coloredStr = function(color, str) {
return this.ansi[color] + str + this.ansi.none;
};
jasmine.TrivialNodeReporter.prototype._greenStr = function(str) { return this._coloredStr("green", str); };
jasmine.TrivialNodeReporter.prototype._redStr = function(str) { return this._coloredStr("red", str); };
jasmine.TrivialNodeReporter.prototype._yellowStr = function(str) { return this._coloredStr("yellow", str); };
jasmine.TrivialNodeReporter.prototype._greenDot = function(str) { return this.sys.print(this._greenStr(".")); };
jasmine.TrivialNodeReporter.prototype._newLine = function(str) { return this.sys.print("\n"); };
jasmine.TrivialNodeReporter.prototype.reportSpecResults = function(spec) {
if (spec.results().passed()) this._greenDot();
};