Merge branch 'master' of git@github.com:emi/jasmine into htmlreporter
Conflicts: lib/TrivialReporter.js spec/bootstrap.js spec/runner.html
This commit is contained in:
commit
ab65914233
|
@ -10,13 +10,25 @@
|
|||
<script type="text/javascript"></script>
|
||||
<link href="/jasmine/lib/jasmine.css" rel="stylesheet"/>
|
||||
<script type="text/javascript">
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
var jsApiReporter = new jasmine.JsApiReporter();
|
||||
jasmineEnv.addReporter(jsApiReporter);
|
||||
jasmineEnv.addReporter(new jasmine.TrivialReporter());
|
||||
window.onload = function() {
|
||||
jasmineEnv.execute();
|
||||
};
|
||||
var jsApiReporter;
|
||||
(function() {
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.updateInterval = 1000;
|
||||
|
||||
jsApiReporter = new jasmine.JsApiReporter();
|
||||
var trivialReporter = new jasmine.TrivialReporter();
|
||||
|
||||
jasmineEnv.addReporter(jsApiReporter);
|
||||
jasmineEnv.addReporter(trivialReporter);
|
||||
|
||||
jasmineEnv.specFilter = function(spec) {
|
||||
return trivialReporter.specFilter(spec);
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
jasmineEnv.execute();
|
||||
};
|
||||
})();
|
||||
</script>
|
||||
|
||||
<% spec_files.each do |spec_file| %>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
jasmine.TrivialReporter = function() {
|
||||
jasmine.TrivialReporter = function(doc) {
|
||||
this.document = doc || document;
|
||||
this.suiteDivs = {};
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
|
||||
|
@ -25,20 +27,56 @@ jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarA
|
|||
return el;
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
var suites = runner.getAllSuites();
|
||||
|
||||
this.runnerDiv = this.createDom('div', { className: 'runner running' }, "Running...");
|
||||
this.document.body.appendChild(this.runnerDiv);
|
||||
|
||||
for (var i = 0; i < suites.length; i++) {
|
||||
var suite = suites[i];
|
||||
var suiteDiv = this.createDom('div', { className: 'suite' },
|
||||
this.createDom('a', { className: 'runSpec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
|
||||
suite.description);
|
||||
console.log(suite);
|
||||
console.log(suite.getFullName());
|
||||
this.suiteDivs[suite.getFullName()] = suiteDiv;
|
||||
var parentDiv = this.document.body;
|
||||
if (suite.parentSuite) {
|
||||
parentDiv = this.suiteDivs[suite.parentSuite.getFullName()];
|
||||
}
|
||||
parentDiv.appendChild(suiteDiv);
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
||||
console.log(runner);
|
||||
var results = runner.getResults();
|
||||
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
|
||||
this.runnerDiv.setAttribute("class", className);
|
||||
var message = results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
|
||||
this.runnerDiv.replaceChild(this.document.createTextNode(message), this.runnerDiv.firstChild);
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
||||
console.log(suite);
|
||||
var results = suite.getResults();
|
||||
var status = results.passed() ? 'passed' : 'failed';
|
||||
if (results.totalCount == 0) { // todo: change this to check results.skipped
|
||||
status = 'skipped';
|
||||
}
|
||||
this.suiteDivs[suite.getFullName()].className += " " + status;
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
||||
var specDiv = this.createDom('div', {
|
||||
className: spec.getResults().passed ? 'spec passed' : 'spec failed'
|
||||
}, spec.getFullName());
|
||||
var results = spec.getResults();
|
||||
var status = results.passed() ? 'passed' : 'failed';
|
||||
if (results.skipped) {
|
||||
status = 'skipped';
|
||||
}
|
||||
var specDiv = this.createDom('div', { className: 'spec ' + status },
|
||||
this.createDom('a', { className: 'runSpec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
|
||||
spec.getFullName());
|
||||
|
||||
var resultItems = spec.getResults().getItems();
|
||||
var resultItems = results.getItems();
|
||||
for (var i = 0; i < resultItems.length; i++) {
|
||||
var result = resultItems[i];
|
||||
if (!result.passed) {
|
||||
|
@ -49,13 +87,29 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
|||
}
|
||||
}
|
||||
|
||||
document.body.appendChild(specDiv);
|
||||
this.suiteDivs[spec.suite.getFullName()].appendChild(specDiv);
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.log = function() {
|
||||
console.log.apply(console, arguments);
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.getLocation = function() {
|
||||
return this.document.location;
|
||||
};
|
||||
|
||||
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
||||
var paramMap = {};
|
||||
var params = this.getLocation().search.substring(1).split('&');
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var p = params[i].split('=');
|
||||
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
||||
}
|
||||
|
||||
if (!paramMap["spec"]) return true;
|
||||
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
||||
};
|
||||
|
||||
//protect against console.log incidents
|
||||
if (!("console" in window) || !("firebug" in console)) {
|
||||
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
body {
|
||||
font: 14px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
|
||||
padding-left: 40px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
|
@ -20,12 +19,37 @@ p {
|
|||
color: red;
|
||||
}
|
||||
|
||||
.fail_in_summary {
|
||||
.failInSummary {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.runner {
|
||||
border: 1px outset gray;
|
||||
margin: 5px;
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.runner.running {
|
||||
background-color: yellow;
|
||||
}
|
||||
|
||||
.suite {
|
||||
border: 1px outset gray;
|
||||
margin: 5px;
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.suite.passed {
|
||||
background-color: #cfc;
|
||||
}
|
||||
|
||||
.suite.failed {
|
||||
background-color: #fdd;
|
||||
}
|
||||
|
||||
.spec {
|
||||
margin: 5px;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.passed {
|
||||
|
@ -36,6 +60,11 @@ p {
|
|||
background-color: pink;
|
||||
}
|
||||
|
||||
.skipped {
|
||||
color: #777;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.resultMessage {
|
||||
white-space: pre;
|
||||
}
|
||||
|
@ -46,6 +75,12 @@ p {
|
|||
margin-left: 10px;
|
||||
height: 5em;
|
||||
overflow: auto;
|
||||
border-left: 1px solid red;
|
||||
padding-left: 5em;
|
||||
border: 1px inset red;
|
||||
padding: 1em;
|
||||
background: #eef;
|
||||
}
|
||||
|
||||
.runSpec {
|
||||
margin-left: 5px;
|
||||
float: right;
|
||||
}
|
|
@ -1149,6 +1149,16 @@ jasmine.Matchers.prototype.toNotContain = function(item) {
|
|||
'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.');
|
||||
};
|
||||
|
||||
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
|
||||
return this.report(this.actual < expected,
|
||||
'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.');
|
||||
};
|
||||
|
||||
jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
|
||||
return this.report(this.actual > expected,
|
||||
'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher that checks that the expected exception was thrown by the actual.
|
||||
*
|
||||
|
@ -1730,6 +1740,28 @@ jasmine.Runner.prototype.finishCallback = function() {
|
|||
this.env.reporter.reportRunnerResults(this);
|
||||
};
|
||||
|
||||
jasmine.Runner.prototype.getAllSuites = function() {
|
||||
var suitesToReturn = [];
|
||||
|
||||
function addSuite(suite) {
|
||||
suitesToReturn.push(suite);
|
||||
|
||||
for (var j = 0; j < suite.specs.length; j++) {
|
||||
var spec = suite.specs[j];
|
||||
if (spec instanceof jasmine.Suite) {
|
||||
addSuite(spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.suites.length; i++) {
|
||||
var suite = this.suites[i];
|
||||
addSuite(suite);
|
||||
}
|
||||
|
||||
return suitesToReturn;
|
||||
};
|
||||
|
||||
jasmine.Runner.prototype.getResults = function() {
|
||||
var results = new jasmine.NestedResults();
|
||||
for (var i = 0; i < this.suites.length; i++) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Jasmine Test Runner</title>
|
||||
|
||||
<script type="text/javascript" src="../src/base.js"></script>
|
||||
<script type="text/javascript" src="../src/util.js"></script>
|
||||
<script type="text/javascript" src="../src/Env.js"></script>
|
||||
|
@ -19,9 +20,6 @@
|
|||
<script type="text/javascript" src="../src/Suite.js"></script>
|
||||
<script type="text/javascript" src="../src/mock-timeout.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../lib/TrivialReporter.js"></script>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
jasmine.include('suites/EnvTest.js', true);
|
||||
jasmine.include('suites/ExceptionsTest.js', true);
|
||||
|
@ -35,31 +33,9 @@
|
|||
jasmine.include('suites/SpyTest.js', true);
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
.spec {
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.passed {
|
||||
background-color: lightgreen;
|
||||
}
|
||||
|
||||
.failed {
|
||||
background-color: pink;
|
||||
}
|
||||
|
||||
.resultMessage {
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.stackTrace {
|
||||
white-space: pre;
|
||||
font-size: .8em;
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
||||
<link href="../lib/jasmine.css" rel="stylesheet"/>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -167,6 +167,18 @@ describe("jasmine.Matchers", function() {
|
|||
});
|
||||
});
|
||||
|
||||
it("toBeLessThan should pass if actual is less than expected", function() {
|
||||
expect(match(37).toBeLessThan(42)).toEqual(true);
|
||||
expect(match(37).toBeLessThan(-42)).toEqual(false);
|
||||
expect(match(37).toBeLessThan(37)).toEqual(false);
|
||||
});
|
||||
|
||||
it("toBeGreaterThan should pass if actual is greater than expected", function() {
|
||||
expect(match(37).toBeGreaterThan(42)).toEqual(false);
|
||||
expect(match(37).toBeGreaterThan(-42)).toEqual(true);
|
||||
expect(match(37).toBeGreaterThan(37)).toEqual(false);
|
||||
});
|
||||
|
||||
it("toThrow", function() {
|
||||
var expected = new jasmine.Matchers(env, function() {
|
||||
throw new Error("Fake Error");
|
||||
|
|
|
@ -123,4 +123,17 @@ describe('RunnerTest', function() {
|
|||
expect(fakeReporter.reportRunnerStarting).wasCalledWith(env.currentRunner);
|
||||
});
|
||||
|
||||
it("should return a flat array of all suites, including nested suites", function() {
|
||||
var suite1, suite2;
|
||||
suite1 = env.describe("spec 1", function() {
|
||||
suite2 = env.describe("nested spec", function() {});
|
||||
});
|
||||
|
||||
console.log("runner:", env.currentRunner);
|
||||
document.runner = env.currentRunner;
|
||||
|
||||
var suites = env.currentRunner.getAllSuites();
|
||||
expect(suites).toEqual([suite1, suite2]);
|
||||
});
|
||||
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
describe("TrivialReporter", function() {
|
||||
var trivialReporter;
|
||||
var body;
|
||||
|
||||
beforeEach(function() {
|
||||
body = document.createElement("body");
|
||||
});
|
||||
|
||||
function fakeSpec(name) {
|
||||
return {
|
||||
getFullName: function() { return name; }
|
||||
};
|
||||
}
|
||||
|
||||
it("should run only specs beginning with spec parameter", function() {
|
||||
trivialReporter = new jasmine.TrivialReporter({ location: {search: "?spec=run%20this"} });
|
||||
expect(trivialReporter.specFilter(fakeSpec("run this"))).toBeTruthy();
|
||||
expect(trivialReporter.specFilter(fakeSpec("not the right spec"))).toBeFalsy();
|
||||
expect(trivialReporter.specFilter(fakeSpec("not run this"))).toBeFalsy();
|
||||
});
|
||||
|
||||
it("should display empty divs for every suite when the runner is starting", function() {
|
||||
trivialReporter = new jasmine.TrivialReporter({ body: body });
|
||||
trivialReporter.reportRunnerStarting({
|
||||
getAllSuites: function() {
|
||||
return [ new jasmine.Suite(null, "suite 1", null, null) ];
|
||||
}
|
||||
});
|
||||
|
||||
var divs = body.getElementsByTagName("div");
|
||||
expect(divs.length).toEqual(2);
|
||||
expect(divs[1].innerHTML).toContain("suite 1");
|
||||
});
|
||||
});
|
|
@ -216,6 +216,16 @@ jasmine.Matchers.prototype.toNotContain = function(item) {
|
|||
'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.');
|
||||
};
|
||||
|
||||
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
|
||||
return this.report(this.actual < expected,
|
||||
'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.');
|
||||
};
|
||||
|
||||
jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
|
||||
return this.report(this.actual > expected,
|
||||
'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Matcher that checks that the expected exception was thrown by the actual.
|
||||
*
|
||||
|
|
|
@ -22,6 +22,28 @@ jasmine.Runner.prototype.finishCallback = function() {
|
|||
this.env.reporter.reportRunnerResults(this);
|
||||
};
|
||||
|
||||
jasmine.Runner.prototype.getAllSuites = function() {
|
||||
var suitesToReturn = [];
|
||||
|
||||
function addSuite(suite) {
|
||||
suitesToReturn.push(suite);
|
||||
|
||||
for (var j = 0; j < suite.specs.length; j++) {
|
||||
var spec = suite.specs[j];
|
||||
if (spec instanceof jasmine.Suite) {
|
||||
addSuite(spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.suites.length; i++) {
|
||||
var suite = this.suites[i];
|
||||
addSuite(suite);
|
||||
}
|
||||
|
||||
return suitesToReturn;
|
||||
};
|
||||
|
||||
jasmine.Runner.prototype.getResults = function() {
|
||||
var results = new jasmine.NestedResults();
|
||||
for (var i = 0; i < this.suites.length; i++) {
|
||||
|
|
Loading…
Reference in New Issue