2009-03-01 13:34:00 +00:00
|
|
|
var createElement = function(tag, attrs) {
|
|
|
|
var element = document.createElement(tag);
|
|
|
|
for (var attr in attrs) {
|
|
|
|
element[attr] = attrs[attr];
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
};
|
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
// Bootstrap Test Reporter function
|
2009-03-01 13:34:00 +00:00
|
|
|
var Reporter = function () {
|
|
|
|
this.total = 0;
|
|
|
|
this.passes = 0;
|
|
|
|
this.fails = 0;
|
|
|
|
this.start = new Date();
|
|
|
|
};
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
Reporter.prototype.toJSON = function(object) {
|
|
|
|
return JSON.stringify(object);
|
|
|
|
};
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
Reporter.prototype.test = function (result, message) {
|
|
|
|
this.total++;
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2009-03-01 15:38:00 +00:00
|
|
|
if (result) {
|
2009-03-01 13:34:00 +00:00
|
|
|
this.passes++;
|
|
|
|
iconElement = document.getElementById('icons');
|
|
|
|
iconElement.appendChild(createElement('img', {src: '../images/go-16.png'}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.fails++;
|
|
|
|
var fails_report = document.getElementById('fails');
|
|
|
|
fails_report.style.display = "";
|
|
|
|
|
|
|
|
var iconElement = document.getElementById('icons');
|
|
|
|
iconElement.appendChild(createElement('img', {src: '../images/fail-16.png'}));
|
|
|
|
|
|
|
|
var failMessages = document.getElementById('fail_messages');
|
|
|
|
var newFail = createElement('p', {'class': 'fail'});
|
|
|
|
newFail.innerHTML = message;
|
|
|
|
failMessages.appendChild(newFail);
|
|
|
|
}
|
|
|
|
};
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
Reporter.prototype.summary = function () {
|
2009-08-10 22:39:48 +00:00
|
|
|
var el = createElement('p', {'class': ((this.fails > 0) ? 'failInSummary' : '') });
|
2009-03-01 13:34:00 +00:00
|
|
|
el.innerHTML = this.total + ' expectations, ' + this.passes + ' passing, ' + this.fails + ' failed in ' + (new Date().getTime() - this.start.getTime()) + "ms.";
|
2008-12-01 20:26:12 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
var summaryElement = document.getElementById('results_summary');
|
|
|
|
summaryElement.appendChild(el);
|
|
|
|
summaryElement.style.display = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var reporter = new Reporter();
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
function runSuite(filename) {
|
2009-06-16 14:19:15 +00:00
|
|
|
console.log(filename);
|
2009-05-29 03:02:15 +00:00
|
|
|
var suite = jasmine.include(filename);
|
2009-03-01 13:34:00 +00:00
|
|
|
suite.execute();
|
2009-05-29 03:02:15 +00:00
|
|
|
emitSuiteResults(filename, suite);
|
|
|
|
}
|
2009-03-01 13:34:00 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
function emitSpecResults(testName, spec) {
|
|
|
|
var results = spec.results.getItems();
|
|
|
|
reporter.test(results.length > 0, testName + ": should have results, got " + results.length);
|
2009-03-01 13:34:00 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
reporter.test(results[i].passed === true, testName + ':' + spec.getFullName() + ": expectation number " + i + " failed: " + results[i].message);
|
|
|
|
}
|
|
|
|
}
|
2009-03-01 13:34:00 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
function emitSuiteResults(testName, suite) {
|
|
|
|
for (var j = 0; j < suite.specs.length; j++) {
|
|
|
|
var specOrSuite = suite.specs[j];
|
2009-03-01 13:34:00 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
if (specOrSuite instanceof jasmine.Suite) {
|
|
|
|
emitSuiteResults(testName, specOrSuite);
|
|
|
|
} else {
|
|
|
|
emitSpecResults(testName, specOrSuite);
|
2009-03-01 13:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-29 03:02:15 +00:00
|
|
|
}
|
2008-12-02 23:27:07 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
var testExplodes = function () {
|
|
|
|
var suite = describe('exploding', function () {
|
|
|
|
it('should throw an exception when this.explodes is called inside a spec', function() {
|
|
|
|
var exceptionMessage = false;
|
2008-12-02 23:27:07 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
try {
|
|
|
|
this.explodes();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
exceptionMessage = e;
|
|
|
|
}
|
|
|
|
expect(exceptionMessage).toEqual('explodes function should not have been called');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
suite.execute();
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
emitSuiteResults('testExplodes', suite);
|
2009-03-01 13:34:00 +00:00
|
|
|
};
|
2008-12-02 01:57:21 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
function newJasmineEnv() {
|
|
|
|
return new jasmine.Env();
|
|
|
|
}
|
2008-12-02 19:08:12 +00:00
|
|
|
|
|
|
|
var testRunner = function() {
|
2009-03-01 13:34:00 +00:00
|
|
|
};
|
2008-12-02 19:08:12 +00:00
|
|
|
|
2008-12-04 17:37:36 +00:00
|
|
|
var testRunnerFinishCallback = function () {
|
2009-05-29 03:02:15 +00:00
|
|
|
var env = newJasmineEnv();
|
2008-12-04 17:37:36 +00:00
|
|
|
var foo = 0;
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.currentRunner.finish();
|
2008-12-04 17:37:36 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((env.currentRunner.finished === true),
|
2008-12-04 20:54:54 +00:00
|
|
|
"Runner finished flag was not set.");
|
2008-12-04 17:37:36 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.currentRunner.finishCallback = function () {
|
2008-12-04 17:37:36 +00:00
|
|
|
foo++;
|
2009-03-01 13:34:00 +00:00
|
|
|
};
|
2008-12-04 17:37:36 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.currentRunner.finish();
|
2008-12-04 17:37:36 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((env.currentRunner.finished === true),
|
2008-12-04 20:54:54 +00:00
|
|
|
"Runner finished flag was not set.");
|
2008-12-04 17:37:36 +00:00
|
|
|
reporter.test((foo === 1),
|
2008-12-04 20:54:54 +00:00
|
|
|
"Runner finish callback was not called");
|
2009-03-01 13:34:00 +00:00
|
|
|
};
|
2008-12-04 17:37:36 +00:00
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
var runTests = function () {
|
2009-03-01 13:34:00 +00:00
|
|
|
document.getElementById('spinner').style.display = "";
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2009-06-16 14:19:15 +00:00
|
|
|
runSuite('suites/PrettyPrintTest.js');
|
|
|
|
runSuite('suites/MatchersTest.js');
|
|
|
|
runSuite('suites/SpecRunningTest.js');
|
|
|
|
runSuite('suites/NestedResultsTest.js');
|
|
|
|
runSuite('suites/ReporterTest.js');
|
|
|
|
runSuite('suites/RunnerTest.js');
|
|
|
|
runSuite('suites/SpyTest.js');
|
|
|
|
runSuite('suites/ExceptionsTest.js');
|
2009-06-15 20:47:05 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
reporter.summary();
|
|
|
|
document.getElementById('spinner').style.display = "none";
|
2009-06-15 06:34:29 +00:00
|
|
|
};
|