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 () {
|
|
|
|
var el = createElement('p', {'class': ((this.fails > 0) ? 'fail_in_summary' : '') });
|
|
|
|
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) {
|
|
|
|
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-12-10 18:30:01 +00:00
|
|
|
var testHandlesBlankSpecs = function () {
|
2009-05-29 03:02:15 +00:00
|
|
|
var env = newJasmineEnv();
|
|
|
|
env.describe('Suite for handles blank specs', function () {
|
|
|
|
env.it('should be a test with a blank runs block', function() {
|
|
|
|
this.runs(function () {
|
2009-01-15 20:40:00 +00:00
|
|
|
});
|
|
|
|
});
|
2009-05-29 03:02:15 +00:00
|
|
|
env.it('should be a blank (empty function) test', function() {
|
2008-12-10 19:20:33 +00:00
|
|
|
});
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2008-12-10 19:20:33 +00:00
|
|
|
});
|
2009-05-29 03:02:15 +00:00
|
|
|
var runner = env.currentRunner;
|
2008-12-10 19:20:33 +00:00
|
|
|
runner.execute();
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((runner.suites[0].results.getItems().length === 2),
|
|
|
|
'Should have found 2 spec results, got ' + runner.suites[0].results.getItems().length);
|
2009-03-01 13:34:00 +00:00
|
|
|
reporter.test((runner.suites[0].results.passedCount === 2),
|
|
|
|
'Should have found 2 passing specs, got ' + runner.suites[0].results.passedCount);
|
|
|
|
};
|
2008-12-10 19:20:33 +00:00
|
|
|
|
2009-01-15 20:40:00 +00:00
|
|
|
var testFormatsExceptionMessages = function () {
|
|
|
|
|
|
|
|
var sampleFirefoxException = {
|
|
|
|
fileName: 'foo.js',
|
|
|
|
line: '1978',
|
|
|
|
message: 'you got your foo in my bar',
|
|
|
|
name: 'A Classic Mistake'
|
2009-03-01 13:34:00 +00:00
|
|
|
};
|
2009-01-15 20:40:00 +00:00
|
|
|
|
|
|
|
var sampleWebkitException = {
|
|
|
|
sourceURL: 'foo.js',
|
|
|
|
lineNumber: '1978',
|
|
|
|
message: 'you got your foo in my bar',
|
|
|
|
name: 'A Classic Mistake'
|
2009-03-01 13:34:00 +00:00
|
|
|
};
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)';
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((jasmine.util.formatException(sampleFirefoxException) === expected),
|
|
|
|
'Should have got ' + expected + ' but got: ' + jasmine.util.formatException(sampleFirefoxException));
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((jasmine.util.formatException(sampleWebkitException) === expected),
|
|
|
|
'Should have got ' + expected + ' but got: ' + jasmine.util.formatException(sampleWebkitException));
|
2009-01-15 20:40:00 +00:00
|
|
|
};
|
|
|
|
|
2008-12-10 19:20:33 +00:00
|
|
|
var testHandlesExceptions = function () {
|
2009-05-29 03:02:15 +00:00
|
|
|
var env = newJasmineEnv();
|
2009-03-01 13:34:00 +00:00
|
|
|
|
2009-01-15 20:40:00 +00:00
|
|
|
//we run two exception tests to make sure we continue after throwing an exception
|
2009-05-29 03:02:15 +00:00
|
|
|
var suite = env.describe('Suite for handles exceptions', function () {
|
|
|
|
env.it('should be a test that fails because it throws an exception', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
throw new Error('fake error 1');
|
2008-12-10 18:30:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.it('should be another test that fails because it throws an exception', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
throw new Error('fake error 2');
|
2008-12-10 19:20:33 +00:00
|
|
|
});
|
2009-05-29 03:02:15 +00:00
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(true);
|
2008-12-10 19:20:33 +00:00
|
|
|
});
|
2008-12-10 18:30:01 +00:00
|
|
|
});
|
2008-12-10 19:20:33 +00:00
|
|
|
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.it('should be a passing test that runs after exceptions are thrown', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(true);
|
2008-12-10 19:20:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.it('should be another test that fails because it throws an exception after a wait', function() {
|
|
|
|
this.runs(function () {
|
2009-01-15 22:27:39 +00:00
|
|
|
var foo = 'foo';
|
|
|
|
});
|
2009-05-29 03:02:15 +00:00
|
|
|
this.waits(250);
|
|
|
|
this.runs(function () {
|
|
|
|
throw new Error('fake error 3');
|
2009-01-15 22:27:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.it('should be a passing test that runs after exceptions are thrown from a async test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(true);
|
2009-01-15 22:27:39 +00:00
|
|
|
});
|
|
|
|
});
|
2009-05-29 03:02:15 +00:00
|
|
|
});
|
2009-01-15 20:40:00 +00:00
|
|
|
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
var runner = env.currentRunner;
|
2008-12-10 18:30:01 +00:00
|
|
|
runner.execute();
|
2009-03-01 13:34:00 +00:00
|
|
|
Clock.tick(400); //TODO: setting this to a large number causes failures, but shouldn't
|
2008-12-10 18:30:01 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
var resultsForSpec0 = suite.specs[0].getResults();
|
|
|
|
var resultsForSpec1 = suite.specs[1].getResults();
|
|
|
|
var resultsForSpec2 = suite.specs[2].getResults();
|
|
|
|
var resultsForSpec3 = suite.specs[3].getResults();
|
2008-12-10 19:20:33 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((suite.getResults().totalCount == 6),
|
|
|
|
'Should have found 5 spec results, got ' + suite.getResults().totalCount);
|
2008-12-10 19:20:33 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((resultsForSpec0.getItems()[0].passed === false),
|
|
|
|
'Spec1 test, expectation 0 should have failed, got passed');
|
2008-12-10 19:20:33 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((resultsForSpec0.getItems()[0].message.match(/fake error 1/)),
|
|
|
|
'Spec1 test, expectation 0 should have a message that contained /fake error 1/, got ' + resultsForSpec0.getItems()[0].message);
|
2008-12-10 19:20:33 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((resultsForSpec1.getItems()[0].passed === false),
|
|
|
|
'Spec2 test, expectation 0 should have failed, got passed');
|
2008-12-10 19:20:33 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((resultsForSpec1.getItems()[0].message.match(/fake error 2/)),
|
|
|
|
'Spec2 test, expectation 0 should have a message that contained /fake error 2/, got ' + resultsForSpec1.getItems()[0].message);
|
2008-12-10 19:20:33 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((resultsForSpec1.getItems()[1].passed === true),
|
|
|
|
'Spec2 test should have had a passing 2nd expectation');
|
2009-01-15 22:27:39 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((resultsForSpec2.getItems()[0].passed === true),
|
|
|
|
'Spec3 test should have passed, got failed');
|
2009-01-15 22:27:39 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
reporter.test((resultsForSpec3.getItems()[0].passed === false),
|
|
|
|
'Spec3 test should have a failing first expectation, got passed');
|
|
|
|
|
|
|
|
reporter.test((resultsForSpec3.getItems()[0].message.match(/fake error 3/)),
|
|
|
|
'Spec3 test should have an error message that contained /fake error 3/, got ' + resultsForSpec3.getItems()[0].message);
|
2009-03-01 13:34:00 +00:00
|
|
|
};
|
2008-12-10 18:30:01 +00:00
|
|
|
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2008-12-10 18:30:01 +00:00
|
|
|
var testResultsAliasing = function () {
|
2009-05-29 03:02:15 +00:00
|
|
|
var env = newJasmineEnv();
|
2008-12-10 18:30:01 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.describe('Suite for result aliasing test', function () {
|
2008-12-10 18:30:01 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
env.it('should be a test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(true);
|
2008-12-10 18:30:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
};
|
2008-12-10 18:30:01 +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-05-29 03:02:15 +00:00
|
|
|
runSuite('PrettyPrintTest.js');
|
|
|
|
runSuite('MatchersTest.js');
|
|
|
|
runSuite('SpecRunningTest.js');
|
2008-12-04 17:37:36 +00:00
|
|
|
testRunnerFinishCallback();
|
2009-05-29 03:02:15 +00:00
|
|
|
runSuite('NestedResultsTest.js');
|
2009-01-15 20:40:00 +00:00
|
|
|
testFormatsExceptionMessages();
|
2008-12-10 19:20:33 +00:00
|
|
|
testHandlesExceptions();
|
|
|
|
testResultsAliasing();
|
2009-05-29 03:02:15 +00:00
|
|
|
runSuite('ReporterTest.js');
|
|
|
|
runSuite('RunnerTest.js');
|
|
|
|
runSuite('JsonReporterTest.js');
|
|
|
|
runSuite('SpyTest.js');
|
2009-03-01 13:34:00 +00:00
|
|
|
testExplodes();
|
2008-12-08 19:35:10 +00:00
|
|
|
|
2008-12-10 19:20:33 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
// handle blank specs will work later.
|
|
|
|
// testHandlesBlankSpecs();
|
2008-12-02 00:32:14 +00:00
|
|
|
|
2008-12-01 20:26:12 +00:00
|
|
|
|
2009-03-01 13:34:00 +00:00
|
|
|
reporter.summary();
|
|
|
|
document.getElementById('spinner').style.display = "none";
|
|
|
|
|
|
|
|
};
|
2008-12-01 20:26:12 +00:00
|
|
|
|