merge in fixes to TrivialConsoleReporter: correct # of specs, no longer limited by column length

This commit is contained in:
Davis W. Frank 2011-05-25 08:14:18 -07:00
commit 7ead5388c2
22 changed files with 980 additions and 518 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
site/ site/
.bundle/ .bundle/
.pairs .pairs
.rvmrc

1
.rvmrc
View File

@ -1 +0,0 @@
rvm use default@jasmine

View File

@ -33,7 +33,7 @@ task :spec => ["spec:node", "spec:browser", "jasmine:hint"]
namespace :spec do namespace :spec do
desc 'Run specs in Node.js' desc 'Run specs in Node.js'
task :node do task :node do
system("node spec/node_suite.js") raise "Node is required to run all jasmine specs" unless system("node spec/node_suite.js")
end end
desc "Run specs in the default browser (MacOS only)" desc "Run specs in the default browser (MacOS only)"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 759 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

BIN
images/jasmine_favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 905 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 768 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1,14 +1,24 @@
body { body {
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
margin: 0;
background-color: #f0f0f0;
} }
a {
.jasmine_reporter a:visited, .jasmine_reporter a { text-decoration: none;
color: #303; color: #777;
} }
.jasmine_reporter a:hover, .jasmine_reporter a:active { a:hover {
color: blue; text-decoration: underline;
}
.description {
display: block;
padding: .4em 0 .4em 1.5em;
font-size: .8em;
min-height: 1.2em;
line-height: 1.2em;
} }
.run_spec { .run_spec {
@ -16,111 +26,240 @@ body {
padding-right: 5px; padding-right: 5px;
font-size: .8em; font-size: .8em;
text-decoration: none; text-decoration: none;
display: none;
} }
.jasmine_reporter { .jasmine_reporter {
margin: 0 5px; margin: 0;
} }
.banner { .banner {
color: #303; color: #303;
background-color: #fef; padding: 0 1.5em;
padding: 5px; height: 1.2em;
line-height: 1.2em;
} }
.logo { .logo {
float: left; float: left;
font-size: 1.1em; font-size: .8em;
padding-left: 5px; padding-left: 5px;
font-weight: 700;
} }
.logo .version { .logo .version {
font-size: .6em; font-size: .8em;
padding-left: 1em; padding-left: .5em;
color: gray;
font-weight: 400;
} }
.runner.running {
background-color: yellow;
}
.options { .options {
text-align: right; text-align: right;
font-size: .8em; font-size: .6em;
} }
.suite { .suite {
border: 1px outset gray; position: relative;
margin: 5px 0; margin: 10px 1.5em;
padding-left: 1em; padding-bottom: 3px;
-moz-border-radius: 6px;
border-radius: 6px;
-moz-box-shadow: 0px 1px 4px #200;
-webkit-box-shadow: 0px 1px 4px #200;
box-shadow: 0px 1px 4px #200;
background-color: #ddd;
} }
.suite .suite { .suite .suite {
margin: 5px; -moz-border-radius: 3px;
border-radius: 3px;
}
.suite > .description {
padding-left: 1.2em;
border-bottom: 1px solid gray;
-moz-border-radius-topleft: 6px;
-moz-border-radius-topright: 6px;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(186,186,186)),
color-stop(0.9, rgb(240,240,240))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(186,186,186) 10%,
rgb(240,240,240) 90%
);
}
.suite .suite>.description {
-moz-border-radius-topleft: 3px;
-moz-border-radius-topright: 3px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
} }
.suite.passed { .suite.passed {
background-color: #dfd; border-color: #bbb;
} }
.suite.failed { .suite.failed {
background-color: #fdd; border-color: #fcc;
}
.suite > .description {
font-weight: 700;
font-size: 1em;
text-shadow: 0px 1px 0px #eee;
color: #777;
}
.suite.passed > .description {
color: rgb(94,125,0);
text-shadow: 0px 1px 0px #ddd;
}
.suite.failed > .description {
color: rgb(176,57,17);
} }
.spec { .spec {
margin: 5px; margin: 0;
padding-left: 1em;
clear: both; clear: both;
position: relative;
padding-bottom: 0;
border-bottom: 1px solid gray;
} }
.spec.failed, .spec.passed, .spec.skipped { .spec.failed, .spec.passed, .spec.skipped {
padding-bottom: 5px;
border: 1px solid gray; }
.spec.failed:first-child, .spec.passed:first-child, .spec.skipped:first-child {
} }
.spec.failed { .spec.failed {
background-color: #fbb; background-color: white;
border-color: red; }
.spec > .description {
color: #666;
font-weight: 700;
}
.spec.failed > .description {
color: white;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(176,57,17)),
color-stop(0.94, rgb(237,87,0))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(176,57,17) 10%,
rgb(237,87,0) 94%
);
}
.spec.failed > .description:before {
display: block;
position: absolute;
left: 5px;
top: 8px;
width: 8px;
height: 8px;
content: ".";
color: transparent;
border: 1px solid #ffffff;
-moz-border-radius: 5px;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(176,57,17)),
color-stop(0.94, rgb(237,87,0))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(176,57,17) 10%,
rgb(237,87,0) 94%
);
} }
.spec.passed { .spec.passed {
background-color: #bfb; background-color: white;
border-color: green; border-color: #bbb;
} }
.spec.passed>.description {
background-color: #ddd;
}
.spec.passed>.description:before {
display: block;
position: absolute;
left: 6px;
top: 9px;
width: 8px;
height: 8px;
content: ".";
color: transparent;
-moz-border-radius: 4px;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(94,125,0)),
color-stop(0.9, rgb(167,212,21))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(94,125,0) 10%,
rgb(167,212,21) 90%
);
}
.spec.skipped { .spec.skipped {
background-color: #bbb; background-color: #bbb;
} }
.messages { .messages {
border-left: 1px dashed gray; font-size: .8em;
padding-left: 1em; padding: 5px 1.5em 0 1.5em;
padding-right: 1em; line-height: 1.2em;
} }
.passed { .passed {
background-color: #cfc;
display: none; display: none;
} }
.failed { .failed {
background-color: #fbb;
} }
.skipped { .skipped {
color: #777;
background-color: #eee;
display: none; display: none;
} }
/*.resultMessage {*/
/*white-space: pre;*/
/*}*/
.resultMessage span.result { .resultMessage span.result {
display: block; display: block;
line-height: 2em; line-height: 2em;
@ -132,14 +271,22 @@ body {
} }
.stackTrace { .stackTrace {
white-space: pre; padding: 5px 1em;
font-size: .8em; margin: 5px 0;
margin-left: 10px;
max-height: 5em; max-height: 5em;
overflow: auto; overflow: hidden;
border: 1px inset red;
padding: 1em; border: 1px solid #baa;
background: #eef; background: #eef;
white-space: pre;
font-size: 1.2em;
line-height: 1.5em;
font-family: monospace;
}
.stackTrace:hover {
overflow: auto;
} }
.finished-at { .finished-at {
@ -152,15 +299,64 @@ body {
display: block; display: block;
} }
#jasmine_content { #jasmine_content {
position:fixed; position: fixed;
right: 100%; right: 100%;
} }
.runner { .runner {
border: 1px solid gray;
display: block; display: block;
margin: 5px 0; margin: 5px 0 10px 0;
padding: 2px 0 2px 10px; padding: 2px 0 2px 1.5em;
border-top: 1px solid gray;
-moz-box-shadow: 0px 1px 4px #000;
-webkit-box-shadow: 0px 1px 4px #000;
box-shadow: 0px 1px 4px #000;
font-size: .8em;
}
.runner.failed {
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(176,57,17)),
color-stop(0.94, rgb(237,87,0))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(176,57,17) 10%,
rgb(237,87,0) 94%
);
}
.runner.passed {
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(94,125,0)),
color-stop(0.9, rgb(167,212,21))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(94,125,0) 10%,
rgb(167,212,21) 90%
);
}
.runner .description {
padding-left: .8em;
color: white;
}
.runner.running {
background-color: yellow;
}
.runner>.description {
height: 1em;
} }

View File

@ -22,6 +22,12 @@ jasmine.unimplementedMethod_ = function() {
*/ */
jasmine.undefined = jasmine.___undefined___; jasmine.undefined = jasmine.___undefined___;
/**
* Show diagnostic messages in the console if set to true
*
*/
jasmine.VERBOSE = false;
/** /**
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed. * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
* *
@ -773,14 +779,14 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) {
declarationError = e; declarationError = e;
} }
this.currentSuite = parentSuite;
if (declarationError) { if (declarationError) {
this.it("encountered a declaration exception", function() { this.it("encountered a declaration exception", function() {
throw declarationError; throw declarationError;
}); });
} }
this.currentSuite = parentSuite;
return suite; return suite;
}; };
@ -1379,6 +1385,23 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
return this.actual > expected; return this.actual > expected;
}; };
/**
* Matcher that checks that the expected item is equal to the actual item
* up to a given level of decimal precision (default 2).
*
* @param {Number} expected
* @param {Number} precision
*/
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
if (!(precision === 0)) {
precision = precision || 2;
}
var multiplier = Math.pow(10, precision);
var actual = Math.round(this.actual * multiplier);
expected = Math.round(expected * multiplier);
return expected == actual;
};
/** /**
* Matcher that checks that the expected exception was thrown by the actual. * Matcher that checks that the expected exception was thrown by the actual.
* *
@ -2186,7 +2209,9 @@ jasmine.WaitsBlock = function(env, timeout, spec) {
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
jasmine.WaitsBlock.prototype.execute = function (onComplete) { jasmine.WaitsBlock.prototype.execute = function (onComplete) {
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); if (jasmine.VERBOSE) {
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
}
this.env.setTimeout(function () { this.env.setTimeout(function () {
onComplete(); onComplete();
}, this.timeout); }, this.timeout);
@ -2214,7 +2239,9 @@ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10; jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
jasmine.WaitsForBlock.prototype.execute = function(onComplete) { jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen')); if (jasmine.VERBOSE) {
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
}
var latchFunctionResult; var latchFunctionResult;
try { try {
latchFunctionResult = this.latchFunction.apply(this.spec); latchFunctionResult = this.latchFunction.apply(this.spec);
@ -2431,5 +2458,5 @@ jasmine.version_= {
"major": 1, "major": 1,
"minor": 1, "minor": 1,
"build": 0, "build": 0,
"revision": 1299963843 "revision": 1306336386
}; };

View File

@ -8,7 +8,7 @@
// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw] // yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
undefined = "diz be undefined yo"; undefined = "diz be undefined yo";
</script> </script>
<link rel="shortcut icon" type="image/png" href="../images/jasmine_favicon.png">
<script type="text/javascript" src="../src/base.js"></script> <script type="text/javascript" src="../src/base.js"></script>
<script type="text/javascript" src="../src/util.js"></script> <script type="text/javascript" src="../src/util.js"></script>
<script type="text/javascript" src="../src/Env.js"></script> <script type="text/javascript" src="../src/Env.js"></script>

View File

@ -1,429 +1,431 @@
describe("TrivialConsoleReporter", function() { if (jasmine.TrivialConsoleReporter) {
describe("TrivialConsoleReporter", function() {
//keep these literal. otherwise the test loses value as a test. //keep these literal. otherwise the test loses value as a test.
function green(str) { return '\033[32m' + str + '\033[0m'; } function green(str) { return '\033[32m' + str + '\033[0m'; }
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 prefixGreen(str) { return '\033[32m' + str; }
function prefixRed(str) { return '\033[31m' + 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, items_: [null, null, null]}; } }, passingRun = { results: function(){ return {failedCount: 0, items_: [null, null, null]}; } },
failingRun = { results: function(){ return {failedCount: 7, items_: [null, null, null]}; } }; failingRun = { results: function(){ return {failedCount: 7, items_: [null, null, null]}; } };
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); }
function repeat(thing, times) { function repeat(thing, times) {
var arr = []; var arr = [];
for(var i=0; i<times; i++) arr.push(thing); for(var i=0; i<times; i++) arr.push(thing);
return arr; return arr;
} }
var fiftyRedFs = repeat(red("F"), 50).join(""), var fiftyRedFs = repeat(red("F"), 50).join(""),
fiftyGreenDots = repeat(green("."), 50).join(""); fiftyGreenDots = repeat(green("."), 50).join("");
function simulateRun(reporter, specResults, suiteResults, finalRunner, startTime, endTime) { function simulateRun(reporter, specResults, suiteResults, finalRunner, startTime, endTime) {
reporter.reportRunnerStarting(); reporter.reportRunnerStarting();
for(var i=0; i<specResults.length; i++) reporter.reportSpecResults(specResults[i]); for(var i=0; i<specResults.length; i++) reporter.reportSpecResults(specResults[i]);
for(i=0; i<suiteResults.length; i++) reporter.reportSuiteResults(suiteResults[i]); for(i=0; i<suiteResults.length; i++) reporter.reportSuiteResults(suiteResults[i]);
reporter.runnerStartTime = startTime; reporter.runnerStartTime = startTime;
reporter.now = function(){return endTime;}; reporter.now = function(){return endTime;};
reporter.reportRunnerResults(finalRunner); reporter.reportRunnerResults(finalRunner);
} }
beforeEach(function() { beforeEach(function() {
this.out = (function(){ this.out = (function(){
var output = ""; var output = "";
return { return {
print:function(str) {output += str;}, print:function(str) {output += str;},
getOutput:function(){return output;}, getOutput:function(){return output;},
clear: function(){output = "";} clear: function(){output = "";}
}; };
})(); })();
this.done = false this.done = false
var self = this var self = this
this.reporter = new jasmine.TrivialConsoleReporter(this.out.print, function(runner){ this.reporter = new jasmine.TrivialConsoleReporter(this.out.print, function(runner){
self.done = true self.done = true
}); });
});
describe('Integration', function(){
it("prints the proper output under a pass scenario. small numbers.", function(){
simulateRun(this.reporter,
repeat(passingSpec, 3),
[],
{
results:function(){
return {
items_: [null, null, null],
totalCount: 7,
failedCount: 0
};
}
},
1000,
1777);
expect(this.out.getOutput()).toEqual(
[
"Started",
green(".") + green(".") + green("."),
"",
"Finished in 0.777 seconds",
green("3 specs, 7 expectations, 0 failures"),
""
].join("\n") + "\n"
);
});
it("prints the proper output under a pass scenario. large numbers.", function(){
simulateRun(this.reporter,
repeat(passingSpec, 57),
[],
{
results:function(){
return {
items_: [null, null, null],
totalCount: 7,
failedCount: 0
};
}
},
1000,
1777);
expect(this.out.getOutput()).toEqual(
[
"Started",
green(".") + green(".") + green(".") + green(".") + green(".") + //50 green dots
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") + newline +
green(".") + green(".") + green(".") + green(".") + green(".") + //7 green dots
green(".") + green("."),
"",
"Finished in 0.777 seconds",
green("3 specs, 7 expectations, 0 failures"),
""
].join("\n") + "\n"
);
}); });
it("prints the proper output under a failure scenario.", function(){ describe('Integration', function(){
simulateRun(this.reporter, it("prints the proper output under a pass scenario. small numbers.", function(){
[failingSpec, passingSpec, failingSpec], simulateRun(this.reporter,
[{description:"The oven", repeat(passingSpec, 3),
results:function(){ [],
return { {
items_:[ results:function(){
{failedCount:2, return {
description:"heats up", items_: [null, null, null],
totalCount: 7,
failedCount: 0
};
}
},
1000,
1777);
expect(this.out.getOutput()).toEqual(
[
"Started",
green(".") + green(".") + green("."),
"",
"Finished in 0.777 seconds",
green("3 specs, 7 expectations, 0 failures"),
""
].join("\n") + "\n"
);
});
it("prints the proper output under a pass scenario. large numbers.", function(){
simulateRun(this.reporter,
repeat(passingSpec, 57),
[],
{
results:function(){
return {
items_: [null, null, null],
totalCount: 7,
failedCount: 0
};
}
},
1000,
1777);
expect(this.out.getOutput()).toEqual(
[
"Started",
green(".") + green(".") + green(".") + green(".") + green(".") + //50 green dots
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") +
green(".") + green(".") + green(".") + green(".") + green(".") + newline +
green(".") + green(".") + green(".") + green(".") + green(".") + //7 green dots
green(".") + green("."),
"",
"Finished in 0.777 seconds",
green("3 specs, 7 expectations, 0 failures"),
""
].join("\n") + "\n"
);
});
it("prints the proper output under a failure scenario.", function(){
simulateRun(this.reporter,
[failingSpec, passingSpec, failingSpec],
[{description:"The oven",
results:function(){
return {
items_:[
{failedCount:2,
description:"heats up",
items_:[
{trace:{stack:"stack trace one\n second line"}},
{trace:{stack:"stack trace two"}}
]}
]
};
}},
{description:"The washing machine",
results:function(){
return {
items_:[ items_:[
{trace:{stack:"stack trace one\n second line"}}, {failedCount:2,
{trace:{stack:"stack trace two"}} description:"washes clothes",
]} items_:[
] {trace:{stack:"stack trace one"}}
}; ]}
}}, ]
{description:"The washing machine", };
results:function(){ }}
return { ],
items_:[ {
{failedCount:2, results:function(){
description:"washes clothes", return {
items_:[ items_: [null, null, null],
{trace:{stack:"stack trace one"}} totalCount: 7,
]} failedCount: 2
] };
}; }
}} },
], 1000,
{ 1777);
results:function(){
return {
items_: [null, null, null],
totalCount: 7,
failedCount: 2
};
}
},
1000,
1777);
expect(this.out.getOutput()).toEqual(
[
"Started",
red("F") + green(".") + red("F"),
"",
"The oven heats up",
" stack trace one",
" second line",
" stack trace two",
"",
"The washing machine washes clothes",
" stack trace one",
"",
"Finished in 0.777 seconds",
red("3 specs, 7 expectations, 2 failures"),
""
].join("\n") + "\n"
);
});
});
describe('A Test Run', function(){
describe('Starts', function(){
it("prints Started", function(){
this.reporter.reportRunnerStarting();
expect(this.out.getOutput()).toEqual( expect(this.out.getOutput()).toEqual(
"Started" + newline [
); "Started",
}); red("F") + green(".") + red("F"),
}); "",
"The oven heats up",
describe('A spec runs', function(){ " stack trace one",
it("prints a green dot if the spec passes", function(){ " second line",
this.reporter.reportSpecResults(passingSpec); " stack trace two",
"",
expect(this.out.getOutput()).toEqual( "The washing machine washes clothes",
green(".") " stack trace one",
"",
"Finished in 0.777 seconds",
red("3 specs, 7 expectations, 2 failures"),
""
].join("\n") + "\n"
); );
}); });
it("prints a red dot if the spec fails", function(){
this.reporter.reportSpecResults(failingSpec);
expect(this.out.getOutput()).toEqual(
red("F")
);
});
it("prints a yellow star if the spec was skipped", function(){
this.reporter.reportSpecResults(skippedSpec);
expect(this.out.getOutput()).toEqual(
yellow("*")
);
});
});
describe('Many specs run', function(){
it("starts a new line every 50 specs", function(){
var self = this;
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 49);
expect(this.out.getOutput()).
toEqual(repeat(red("F"), 49).join(""));
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 3);
expect(this.out.getOutput()).
toEqual(fiftyRedFs + newline +
red("F") + red("F"));
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 48);
repeatedlyInvoke(function(){self.reporter.reportSpecResults(passingSpec);}, 2);
expect(this.out.getOutput()).
toEqual(fiftyRedFs + newline +
fiftyRedFs + newline +
green(".") + green("."));
});
});
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});
var self = this;
var descriptions = [];
for(var i=0; i<self.reporter.suiteResults.length; i++)
descriptions.push(self.reporter.suiteResults[i].description);
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});
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(){
this.reporter.reportSuiteResults({description:"Oven",
results:function(){
return {
items_:[
{failedCount:0, description:"specOne"},
{failedCount:99, description:"specTwo"},
{failedCount:0, description:"specThree"},
{failedCount:88, description:"specFour"},
{failedCount:3}
]
};
}});
expect(this.reporter.suiteResults[0].failedSpecResults).
toEqual([
{failedCount:99, description:"specTwo"},
{failedCount:88, description:"specFour"}
]);
});
}); });
describe('Finishes', function(){ describe('A Test Run', function(){
describe('Spec failure information', function(){ describe('Starts', function(){
it("prints Started", function(){
it("prints suite and spec descriptions together as a sentence", function(){
this.reporter.suiteResults = [
{description:"The oven", failedSpecResults:[
{description:"heats up", items_:[]},
{description:"cleans itself", items_:[]}
]},
{description:"The mixer", failedSpecResults:[
{description:"blends things together", items_:[]}
]}
];
this.reporter.reportRunnerResults(failingRun);
expect(this.out.getOutput()).toContain("The oven heats up");
expect(this.out.getOutput()).toContain("The oven cleans itself");
expect(this.out.getOutput()).toContain("The mixer blends things together");
});
it("prints stack trace of spec failure", function(){
this.reporter.suiteResults = [
{description:"The oven", failedSpecResults:[
{description:"heats up",
items_:[
{trace:{stack:"stack trace one"}},
{trace:{stack:"stack trace two"}}
]}
]}
];
this.reporter.reportRunnerResults(failingRun);
expect(this.out.getOutput()).toContain("The oven heats up");
expect(this.out.getOutput()).toContain("stack trace one");
expect(this.out.getOutput()).toContain("stack trace two");
});
});
describe('Finished line', function(){
it("prints the elapsed time in the summary message", function(){
this.reporter.now = function(){return 1000;};
this.reporter.reportRunnerStarting(); this.reporter.reportRunnerStarting();
this.reporter.now = function(){return 1777;};
this.reporter.reportRunnerResults(passingRun); expect(this.out.getOutput()).toEqual(
expect(this.out.getOutput()).toContain("0.777 seconds"); "Started" + newline
);
});
});
describe('A spec runs', function(){
it("prints a green dot if the spec passes", function(){
this.reporter.reportSpecResults(passingSpec);
expect(this.out.getOutput()).toEqual(
green(".")
);
}); });
it("prints round time numbers correctly", function(){ it("prints a red dot if the spec fails", function(){
this.reporter.reportSpecResults(failingSpec);
expect(this.out.getOutput()).toEqual(
red("F")
);
});
it("prints a yellow star if the spec was skipped", function(){
this.reporter.reportSpecResults(skippedSpec);
expect(this.out.getOutput()).toEqual(
yellow("*")
);
});
});
describe('Many specs run', function(){
it("starts a new line every 50 specs", function(){
var self = this; var self = this;
function run(startTime, endTime) { repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 49);
self.out.clear();
self.reporter.runnerStartTime = startTime;
self.reporter.now = function(){return endTime;};
self.reporter.reportRunnerResults(passingRun);
}
run(1000, 11000); expect(this.out.getOutput()).
expect(this.out.getOutput()).toContain("10 seconds"); toEqual(repeat(red("F"), 49).join(""));
run(1000, 2000); repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 3);
expect(this.out.getOutput()).toContain("1 seconds");
run(1000, 1100); expect(this.out.getOutput()).
expect(this.out.getOutput()).toContain("0.1 seconds"); toEqual(fiftyRedFs + newline +
red("F") + red("F"));
run(1000, 1010); repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 48);
expect(this.out.getOutput()).toContain("0.01 seconds"); repeatedlyInvoke(function(){self.reporter.reportSpecResults(passingSpec);}, 2);
run(1000, 1001); expect(this.out.getOutput()).
expect(this.out.getOutput()).toContain("0.001 seconds"); toEqual(fiftyRedFs + newline +
}); fiftyRedFs + newline +
green(".") + green("."));
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.out.getOutput()).toContain("Finished in 0.777 seconds");
}); });
}); });
describe("specs/expectations/failures summary", function(){ describe('A suite runs', function(){
it("prints statistics in green if there were no failures", function() { it("remembers suite results", function(){
this.reporter.reportRunnerResults({ var emptyResults = function(){return {items_:[]};};
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 0};} this.reporter.reportSuiteResults({description:"Oven", results:emptyResults});
}); this.reporter.reportSuiteResults({description:"Mixer", results:emptyResults});
expect(this.out.getOutput()).
toContain("3 specs, 7 expectations, 0 failures"); var self = this;
var descriptions = [];
for(var i=0; i<self.reporter.suiteResults.length; i++)
descriptions.push(self.reporter.suiteResults[i].description);
expect(descriptions).toEqual(["Oven", "Mixer"]);
}); });
it("prints statistics in red if there was a failure", function() { it("creates a description out of the current suite and any parent suites", function(){
this.reporter.reportRunnerResults({ var emptyResults = function(){return {items_:[]};};
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 3};} var grandparentSuite = {description:"My house", results:emptyResults};
}); var parentSuite = {description:"kitchen", parentSuite: grandparentSuite, results:emptyResults};
expect(this.out.getOutput()). this.reporter.reportSuiteResults({description:"oven", parentSuite: parentSuite, results:emptyResults});
toContain("3 specs, 7 expectations, 3 failures");
expect(this.reporter.suiteResults[0].description).toEqual("My house kitchen oven");
}); });
it("handles pluralization with 1's ones appropriately", function() { it("gathers failing spec results from the suite. the spec must have a description.", function(){
this.reporter.reportRunnerResults({ this.reporter.reportSuiteResults({description:"Oven",
results:function(){return {items_: [null], totalCount: 1, failedCount: 1};} results:function(){
}); return {
expect(this.out.getOutput()). items_:[
toContain("1 spec, 1 expectation, 1 failure"); {failedCount:0, description:"specOne"},
{failedCount:99, description:"specTwo"},
{failedCount:0, description:"specThree"},
{failedCount:88, description:"specFour"},
{failedCount:3}
]
};
}});
expect(this.reporter.suiteResults[0].failedSpecResults).
toEqual([
{failedCount:99, description:"specTwo"},
{failedCount:88, description:"specFour"}
]);
}); });
}); });
describe("done callback", function(){ describe('Finishes', function(){
it("calls back when done", function() {
expect(this.done).toBeFalsy(); describe('Spec failure information', function(){
this.reporter.reportRunnerResults({
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 0};} it("prints suite and spec descriptions together as a sentence", function(){
this.reporter.suiteResults = [
{description:"The oven", failedSpecResults:[
{description:"heats up", items_:[]},
{description:"cleans itself", items_:[]}
]},
{description:"The mixer", failedSpecResults:[
{description:"blends things together", items_:[]}
]}
];
this.reporter.reportRunnerResults(failingRun);
expect(this.out.getOutput()).toContain("The oven heats up");
expect(this.out.getOutput()).toContain("The oven cleans itself");
expect(this.out.getOutput()).toContain("The mixer blends things together");
}); });
expect(this.done).toBeTruthy();
it("prints stack trace of spec failure", function(){
this.reporter.suiteResults = [
{description:"The oven", failedSpecResults:[
{description:"heats up",
items_:[
{trace:{stack:"stack trace one"}},
{trace:{stack:"stack trace two"}}
]}
]}
];
this.reporter.reportRunnerResults(failingRun);
expect(this.out.getOutput()).toContain("The oven heats up");
expect(this.out.getOutput()).toContain("stack trace one");
expect(this.out.getOutput()).toContain("stack trace two");
});
}); });
describe('Finished line', function(){
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.out.getOutput()).toContain("0.777 seconds");
});
it("prints round time numbers correctly", function(){
var self = this;
function run(startTime, endTime) {
self.out.clear();
self.reporter.runnerStartTime = startTime;
self.reporter.now = function(){return endTime;};
self.reporter.reportRunnerResults(passingRun);
}
run(1000, 11000);
expect(this.out.getOutput()).toContain("10 seconds");
run(1000, 2000);
expect(this.out.getOutput()).toContain("1 seconds");
run(1000, 1100);
expect(this.out.getOutput()).toContain("0.1 seconds");
run(1000, 1010);
expect(this.out.getOutput()).toContain("0.01 seconds");
run(1000, 1001);
expect(this.out.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.out.getOutput()).toContain("Finished in 0.777 seconds");
});
});
describe("specs/expectations/failures summary", function(){
it("prints statistics in green if there were no failures", function() {
this.reporter.reportRunnerResults({
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 0};}
});
expect(this.out.getOutput()).
toContain("3 specs, 7 expectations, 0 failures");
});
it("prints statistics in red if there was a failure", function() {
this.reporter.reportRunnerResults({
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 3};}
});
expect(this.out.getOutput()).
toContain("3 specs, 7 expectations, 3 failures");
});
it("handles pluralization with 1's ones appropriately", function() {
this.reporter.reportRunnerResults({
results:function(){return {items_: [null], totalCount: 1, failedCount: 1};}
});
expect(this.out.getOutput()).
toContain("1 spec, 1 expectation, 1 failure");
});
});
describe("done callback", function(){
it("calls back when done", function() {
expect(this.done).toBeFalsy();
this.reporter.reportRunnerResults({
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 0};}
});
expect(this.done).toBeTruthy();
});
});
}); });
}); });
}); });
}
});

View File

@ -10,6 +10,37 @@ describe('WaitsForBlock', function () {
onComplete = jasmine.createSpy("onComplete"); onComplete = jasmine.createSpy("onComplete");
}); });
describe("jasmine.VERBOSE", function() {
var jasmineVerboseOriginal;
beforeEach(function() {
jasmineVerboseOriginal = jasmine.VERBOSE;
spyOn(env.reporter, 'log');
});
it('do not show information if jasmine.VERBOSE is set to false', function () {
jasmine.VERBOSE = false;
var latchFunction = function() {
return true;
};
var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
expect(env.reporter.log).not.toHaveBeenCalled();
block.execute(onComplete);
expect(env.reporter.log).not.toHaveBeenCalled();
jasmine.VERBOSE = jasmineVerboseOriginal;
});
it('show information if jasmine.VERBOSE is set to true', function () {
jasmine.VERBOSE = true;
var latchFunction = function() {
return true;
};
var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec);
expect(env.reporter.log).not.toHaveBeenCalled();
block.execute(onComplete);
expect(env.reporter.log).toHaveBeenCalled();
jasmine.VERBOSE = jasmineVerboseOriginal;
});
});
it('onComplete should be called if the latchFunction returns true', function () { it('onComplete should be called if the latchFunction returns true', function () {
var latchFunction = function() { var latchFunction = function() {
return true; return true;

View File

@ -6,7 +6,9 @@ jasmine.WaitsBlock = function(env, timeout, spec) {
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
jasmine.WaitsBlock.prototype.execute = function (onComplete) { jasmine.WaitsBlock.prototype.execute = function (onComplete) {
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); if (jasmine.VERBOSE) {
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
}
this.env.setTimeout(function () { this.env.setTimeout(function () {
onComplete(); onComplete();
}, this.timeout); }, this.timeout);

View File

@ -21,7 +21,9 @@ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10; jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
jasmine.WaitsForBlock.prototype.execute = function(onComplete) { jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen')); if (jasmine.VERBOSE) {
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
}
var latchFunctionResult; var latchFunctionResult;
try { try {
latchFunctionResult = this.latchFunction.apply(this.spec); latchFunctionResult = this.latchFunction.apply(this.spec);

View File

@ -22,6 +22,12 @@ jasmine.unimplementedMethod_ = function() {
*/ */
jasmine.undefined = jasmine.___undefined___; jasmine.undefined = jasmine.___undefined___;
/**
* Show diagnostic messages in the console if set to true
*
*/
jasmine.VERBOSE = false;
/** /**
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed. * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
* *

View File

@ -1,14 +1,24 @@
body { body {
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
margin: 0;
background-color: #f0f0f0;
} }
a {
.jasmine_reporter a:visited, .jasmine_reporter a { text-decoration: none;
color: #303; color: #777;
} }
.jasmine_reporter a:hover, .jasmine_reporter a:active { a:hover {
color: blue; text-decoration: underline;
}
.description {
display: block;
padding: .4em 0 .4em 1.5em;
font-size: .8em;
min-height: 1.2em;
line-height: 1.2em;
} }
.run_spec { .run_spec {
@ -16,111 +26,240 @@ body {
padding-right: 5px; padding-right: 5px;
font-size: .8em; font-size: .8em;
text-decoration: none; text-decoration: none;
display: none;
} }
.jasmine_reporter { .jasmine_reporter {
margin: 0 5px; margin: 0;
} }
.banner { .banner {
color: #303; color: #303;
background-color: #fef; padding: 0 1.5em;
padding: 5px; height: 1.2em;
line-height: 1.2em;
} }
.logo { .logo {
float: left; float: left;
font-size: 1.1em; font-size: .8em;
padding-left: 5px; padding-left: 5px;
font-weight: 700;
} }
.logo .version { .logo .version {
font-size: .6em; font-size: .8em;
padding-left: 1em; padding-left: .5em;
color: gray;
font-weight: 400;
} }
.runner.running {
background-color: yellow;
}
.options { .options {
text-align: right; text-align: right;
font-size: .8em; font-size: .6em;
} }
.suite { .suite {
border: 1px outset gray; position: relative;
margin: 5px 0; margin: 10px 1.5em;
padding-left: 1em; padding-bottom: 3px;
-moz-border-radius: 6px;
border-radius: 6px;
-moz-box-shadow: 0px 1px 4px #200;
-webkit-box-shadow: 0px 1px 4px #200;
box-shadow: 0px 1px 4px #200;
background-color: #ddd;
} }
.suite .suite { .suite .suite {
margin: 5px; -moz-border-radius: 3px;
border-radius: 3px;
}
.suite > .description {
padding-left: 1.2em;
border-bottom: 1px solid gray;
-moz-border-radius-topleft: 6px;
-moz-border-radius-topright: 6px;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(186,186,186)),
color-stop(0.9, rgb(240,240,240))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(186,186,186) 10%,
rgb(240,240,240) 90%
);
}
.suite .suite>.description {
-moz-border-radius-topleft: 3px;
-moz-border-radius-topright: 3px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
} }
.suite.passed { .suite.passed {
background-color: #dfd; border-color: #bbb;
} }
.suite.failed { .suite.failed {
background-color: #fdd; border-color: #fcc;
}
.suite > .description {
font-weight: 700;
font-size: 1em;
text-shadow: 0px 1px 0px #eee;
color: #777;
}
.suite.passed > .description {
color: rgb(94,125,0);
text-shadow: 0px 1px 0px #ddd;
}
.suite.failed > .description {
color: rgb(176,57,17);
} }
.spec { .spec {
margin: 5px; margin: 0;
padding-left: 1em;
clear: both; clear: both;
position: relative;
padding-bottom: 0;
border-bottom: 1px solid gray;
} }
.spec.failed, .spec.passed, .spec.skipped { .spec.failed, .spec.passed, .spec.skipped {
padding-bottom: 5px;
border: 1px solid gray; }
.spec.failed:first-child, .spec.passed:first-child, .spec.skipped:first-child {
} }
.spec.failed { .spec.failed {
background-color: #fbb; background-color: white;
border-color: red; }
.spec > .description {
color: #666;
font-weight: 700;
}
.spec.failed > .description {
color: white;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(176,57,17)),
color-stop(0.94, rgb(237,87,0))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(176,57,17) 10%,
rgb(237,87,0) 94%
);
}
.spec.failed > .description:before {
display: block;
position: absolute;
left: 5px;
top: 8px;
width: 8px;
height: 8px;
content: ".";
color: transparent;
border: 1px solid #ffffff;
-moz-border-radius: 5px;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(176,57,17)),
color-stop(0.94, rgb(237,87,0))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(176,57,17) 10%,
rgb(237,87,0) 94%
);
} }
.spec.passed { .spec.passed {
background-color: #bfb; background-color: white;
border-color: green; border-color: #bbb;
} }
.spec.passed>.description {
background-color: #ddd;
}
.spec.passed>.description:before {
display: block;
position: absolute;
left: 6px;
top: 9px;
width: 8px;
height: 8px;
content: ".";
color: transparent;
-moz-border-radius: 4px;
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(94,125,0)),
color-stop(0.9, rgb(167,212,21))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(94,125,0) 10%,
rgb(167,212,21) 90%
);
}
.spec.skipped { .spec.skipped {
background-color: #bbb; background-color: #bbb;
} }
.messages { .messages {
border-left: 1px dashed gray; font-size: .8em;
padding-left: 1em; padding: 5px 1.5em 0 1.5em;
padding-right: 1em; line-height: 1.2em;
} }
.passed { .passed {
background-color: #cfc;
display: none; display: none;
} }
.failed { .failed {
background-color: #fbb;
} }
.skipped { .skipped {
color: #777;
background-color: #eee;
display: none; display: none;
} }
/*.resultMessage {*/
/*white-space: pre;*/
/*}*/
.resultMessage span.result { .resultMessage span.result {
display: block; display: block;
line-height: 2em; line-height: 2em;
@ -132,14 +271,22 @@ body {
} }
.stackTrace { .stackTrace {
white-space: pre; padding: 5px 1em;
font-size: .8em; margin: 5px 0;
margin-left: 10px;
max-height: 5em; max-height: 5em;
overflow: auto; overflow: hidden;
border: 1px inset red;
padding: 1em; border: 1px solid #baa;
background: #eef; background: #eef;
white-space: pre;
font-size: 1.2em;
line-height: 1.5em;
font-family: monospace;
}
.stackTrace:hover {
overflow: auto;
} }
.finished-at { .finished-at {
@ -152,15 +299,64 @@ body {
display: block; display: block;
} }
#jasmine_content { #jasmine_content {
position:fixed; position: fixed;
right: 100%; right: 100%;
} }
.runner { .runner {
border: 1px solid gray;
display: block; display: block;
margin: 5px 0; margin: 5px 0 10px 0;
padding: 2px 0 2px 10px; padding: 2px 0 2px 1.5em;
border-top: 1px solid gray;
-moz-box-shadow: 0px 1px 4px #000;
-webkit-box-shadow: 0px 1px 4px #000;
box-shadow: 0px 1px 4px #000;
font-size: .8em;
}
.runner.failed {
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(176,57,17)),
color-stop(0.94, rgb(237,87,0))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(176,57,17) 10%,
rgb(237,87,0) 94%
);
}
.runner.passed {
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.1, rgb(94,125,0)),
color-stop(0.9, rgb(167,212,21))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(94,125,0) 10%,
rgb(167,212,21) 90%
);
}
.runner .description {
padding-left: .8em;
color: white;
}
.runner.running {
background-color: yellow;
}
.runner>.description {
height: 1em;
} }