TrivialConsoleReporter now reports the correct number of specs that were executed. TCR is still very heavily mocked instead of using testing an actual Jasmine environment. But now at least the numbers are correct.
This commit is contained in:
parent
1d65d56a92
commit
a445a62e7c
|
@ -6,7 +6,9 @@ var path = require('path');
|
|||
// undefined = "diz be undefined yo";
|
||||
|
||||
var jasmineGlobals = require("../src/base");
|
||||
for(var k in jasmineGlobals) {global[k] = jasmineGlobals[k];}
|
||||
for (var k in jasmineGlobals) {
|
||||
global[k] = jasmineGlobals[k];
|
||||
}
|
||||
|
||||
//load jasmine src files based on the order in runner.html
|
||||
var srcFilesInProperRequireOrder = [];
|
||||
|
@ -34,7 +36,8 @@ global.window = {
|
|||
|
||||
delete global.window;
|
||||
|
||||
function noop(){}
|
||||
function noop() {
|
||||
}
|
||||
|
||||
jasmine.executeSpecs = function(specs, done) {
|
||||
for (var i = 0, len = specs.length; i < len; ++i) {
|
||||
|
@ -43,7 +46,9 @@ jasmine.executeSpecs = function(specs, done){
|
|||
}
|
||||
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.reporter = new jasmine.TrivialConsoleReporter(sys.print, done);
|
||||
var consoleReporter = new jasmine.TrivialConsoleReporter(sys.print, done);
|
||||
|
||||
jasmineEnv.addReporter(consoleReporter);
|
||||
jasmineEnv.execute();
|
||||
};
|
||||
|
||||
|
@ -70,16 +75,6 @@ jasmine.getAllSpecFiles = function(dir, matcher){
|
|||
return specs;
|
||||
};
|
||||
|
||||
jasmine.printRunnerResults = function(runner){
|
||||
var results = runner.results();
|
||||
var suites = runner.suites();
|
||||
var msg = '';
|
||||
msg += suites.length + ' spec' + ((suites.length === 1) ? '' : 's') + ', ';
|
||||
msg += results.totalCount + ' expectation' + ((results.totalCount === 1) ? '' : 's') + ', ';
|
||||
msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n';
|
||||
return msg;
|
||||
};
|
||||
|
||||
function now() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
@ -114,10 +109,6 @@ for ( var key in jasmine) {
|
|||
End jasmine-node runner
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var isVerbose = false;
|
||||
var showColors = true;
|
||||
process.argv.forEach(function(arg) {
|
||||
|
|
|
@ -31,20 +31,37 @@ describe("TrivialConsoleReporter", function() {
|
|||
};
|
||||
}
|
||||
},
|
||||
failingSpec = { results: function() {
|
||||
return {passed: function() {
|
||||
failingSpec = {
|
||||
results: function() {
|
||||
return {
|
||||
passed: function() {
|
||||
return false;
|
||||
}};
|
||||
} },
|
||||
skippedSpec = { results: function() {
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
skippedSpec = {
|
||||
results: function() {
|
||||
return {skipped: true};
|
||||
} },
|
||||
passingRun = { results: function() {
|
||||
}
|
||||
},
|
||||
passingRun = {
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results: function() {
|
||||
return {failedCount: 0, items_: [null, null, null]};
|
||||
} },
|
||||
failingRun = { results: function() {
|
||||
return {failedCount: 7, items_: [null, null, null]};
|
||||
} };
|
||||
}
|
||||
},
|
||||
failingRun = {
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results: function() {
|
||||
return {
|
||||
failedCount: 7, items_: [null, null, null]};
|
||||
}
|
||||
};
|
||||
|
||||
function repeatedlyInvoke(f, times) {
|
||||
for (var i = 0; i < times; i++) f(times + 1);
|
||||
|
@ -102,6 +119,9 @@ describe("TrivialConsoleReporter", function() {
|
|||
repeat(passingSpec, 3),
|
||||
[],
|
||||
{
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {
|
||||
items_: [null, null, null],
|
||||
|
@ -131,6 +151,9 @@ describe("TrivialConsoleReporter", function() {
|
|||
repeat(passingSpec, 57),
|
||||
[],
|
||||
{
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {
|
||||
items_: [null, null, null],
|
||||
|
@ -200,6 +223,9 @@ describe("TrivialConsoleReporter", function() {
|
|||
}}
|
||||
],
|
||||
{
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {
|
||||
items_: [null, null, null],
|
||||
|
@ -407,6 +433,9 @@ describe("TrivialConsoleReporter", function() {
|
|||
describe("when reporting the results summary", function() {
|
||||
it("prints statistics in green if there were no failures", function() {
|
||||
reporter.reportRunnerResults({
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {items_: [null, null, null], totalCount: 7, failedCount: 0};
|
||||
}
|
||||
|
@ -417,6 +446,9 @@ describe("TrivialConsoleReporter", function() {
|
|||
|
||||
it("prints statistics in red if there was a failure", function() {
|
||||
reporter.reportRunnerResults({
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {items_: [null, null, null], totalCount: 7, failedCount: 3};
|
||||
}
|
||||
|
@ -427,6 +459,9 @@ describe("TrivialConsoleReporter", function() {
|
|||
|
||||
it("handles pluralization with 1's ones appropriately", function() {
|
||||
reporter.reportRunnerResults({
|
||||
specs: function() {
|
||||
return [null];
|
||||
},
|
||||
results:function() {
|
||||
return {items_: [null], totalCount: 1, failedCount: 1};
|
||||
}
|
||||
|
@ -440,6 +475,9 @@ describe("TrivialConsoleReporter", function() {
|
|||
it("calls back when done", function() {
|
||||
expect(done).toBeFalsy();
|
||||
reporter.reportRunnerResults({
|
||||
specs: function() {
|
||||
return [null, null, null];
|
||||
},
|
||||
results:function() {
|
||||
return {items_: [null, null, null], totalCount: 7, failedCount: 0};
|
||||
}
|
||||
|
|
|
@ -2,34 +2,71 @@ jasmine.TrivialConsoleReporter = function(print, doneCallback) {
|
|||
//inspired by mhevery's jasmine-node reporter
|
||||
//https://github.com/mhevery/jasmine-node
|
||||
|
||||
doneCallback = doneCallback || function(){};
|
||||
doneCallback = doneCallback || function() {
|
||||
};
|
||||
|
||||
var defaultColumnsPerLine = 50,
|
||||
ansi = { green: '\033[32m', red: '\033[31m', yellow: '\033[33m', none: '\033[0m' },
|
||||
language = { spec:"spec", expectation:"expectation", failure:"failure" };
|
||||
ansi = {
|
||||
green: '\033[32m',
|
||||
red: '\033[31m',
|
||||
yellow: '\033[33m',
|
||||
none: '\033[0m'
|
||||
},
|
||||
language = {
|
||||
spec: "spec",
|
||||
expectation: "expectation",
|
||||
failure: "failure"
|
||||
};
|
||||
|
||||
function coloredStr(color, str) { return ansi[color] + str + ansi.none; }
|
||||
function coloredStr(color, str) {
|
||||
return ansi[color] + str + ansi.none;
|
||||
}
|
||||
|
||||
function greenStr(str) { return coloredStr("green", str); }
|
||||
function redStr(str) { return coloredStr("red", str); }
|
||||
function yellowStr(str) { return coloredStr("yellow", str); }
|
||||
function greenStr(str) {
|
||||
return coloredStr("green", str);
|
||||
}
|
||||
|
||||
function newline() { print("\n"); }
|
||||
function started() { print("Started");
|
||||
newline(); }
|
||||
function redStr(str) {
|
||||
return coloredStr("red", str);
|
||||
}
|
||||
|
||||
function greenDot() { print(greenStr(".")); }
|
||||
function redF() { print(redStr("F")); }
|
||||
function yellowStar() { print(yellowStr("*")); }
|
||||
function yellowStr(str) {
|
||||
return coloredStr("yellow", str);
|
||||
}
|
||||
|
||||
function plural(str, count) { return count == 1 ? str : str + "s"; }
|
||||
function newline() {
|
||||
print("\n");
|
||||
}
|
||||
|
||||
function repeat(thing, times) { var arr = [];
|
||||
function started() {
|
||||
print("Started");
|
||||
newline();
|
||||
}
|
||||
|
||||
function greenDot() {
|
||||
print(greenStr("."));
|
||||
}
|
||||
|
||||
function redF() {
|
||||
print(redStr("F"));
|
||||
}
|
||||
|
||||
function yellowStar() {
|
||||
print(yellowStr("*"));
|
||||
}
|
||||
|
||||
function plural(str, count) {
|
||||
return count == 1 ? str : str + "s";
|
||||
}
|
||||
|
||||
function repeat(thing, times) {
|
||||
var arr = [];
|
||||
for (var i = 0; i < times; i++) arr.push(thing);
|
||||
return arr;
|
||||
}
|
||||
|
||||
function indent(str, spaces) { var lines = (str || '').split("\n");
|
||||
function indent(str, spaces) {
|
||||
var lines = (str || '').split("\n");
|
||||
var newArr = [];
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
newArr.push(repeat(" ", spaces).join("") + lines[i]);
|
||||
|
@ -46,19 +83,28 @@ jasmine.TrivialConsoleReporter = function(print, doneCallback) {
|
|||
newline();
|
||||
}
|
||||
}
|
||||
function finished(elapsed) { newline();
|
||||
print("Finished in " + elapsed/1000 + " seconds"); }
|
||||
function summary(colorF, specs, expectations, failed) { newline();
|
||||
|
||||
function finished(elapsed) {
|
||||
newline();
|
||||
print("Finished in " + elapsed / 1000 + " seconds");
|
||||
}
|
||||
|
||||
function summary(colorF, specs, expectations, failed) {
|
||||
newline();
|
||||
print(colorF(specs + " " + plural(language.spec, specs) + ", " +
|
||||
expectations + " " + plural(language.expectation, expectations) + ", " +
|
||||
failed + " " + plural(language.failure, failed)));
|
||||
newline();
|
||||
newline(); }
|
||||
function greenSummary(specs, expectations, failed){ summary(greenStr, specs, expectations, failed); }
|
||||
function redSummary(specs, expectations, failed){ summary(redStr, specs, expectations, failed); }
|
||||
|
||||
newline();
|
||||
}
|
||||
|
||||
function greenSummary(specs, expectations, failed) {
|
||||
summary(greenStr, specs, expectations, failed);
|
||||
}
|
||||
|
||||
function redSummary(specs, expectations, failed) {
|
||||
summary(redStr, specs, expectations, failed);
|
||||
}
|
||||
|
||||
function lineEnder(columnsPerLine) {
|
||||
var columnsSoFar = 0;
|
||||
|
@ -79,14 +125,17 @@ jasmine.TrivialConsoleReporter = function(print, doneCallback) {
|
|||
|
||||
var startNewLineIfNecessary = lineEnder(defaultColumnsPerLine);
|
||||
|
||||
this.now = function() { return new Date().getTime(); };
|
||||
this.now = function() {
|
||||
return new Date().getTime();
|
||||
};
|
||||
|
||||
this.reportRunnerStarting = function() {
|
||||
this.runnerStartTime = this.now();
|
||||
started();
|
||||
};
|
||||
|
||||
this.reportSpecStarting = function() { /* do nothing */ };
|
||||
this.reportSpecStarting = function() { /* do nothing */
|
||||
};
|
||||
|
||||
this.reportSpecResults = function(spec) {
|
||||
var results = spec.results();
|
||||
|
@ -138,7 +187,7 @@ jasmine.TrivialConsoleReporter = function(print, doneCallback) {
|
|||
|
||||
var results = runner.results();
|
||||
var summaryFunction = results.failedCount === 0 ? greenSummary : redSummary;
|
||||
summaryFunction(results.items_.length, results.totalCount, results.failedCount);
|
||||
summaryFunction(runner.specs().length, results.totalCount, results.failedCount);
|
||||
doneCallback(runner);
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue