2009-05-29 03:02:15 +00:00
|
|
|
describe('RunnerTest', function() {
|
2009-08-13 05:12:28 +00:00
|
|
|
var fakeTimer;
|
2009-05-29 03:02:15 +00:00
|
|
|
var env;
|
2009-08-13 05:12:28 +00:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2009-05-29 03:02:15 +00:00
|
|
|
env = new jasmine.Env();
|
2009-10-06 05:36:10 +00:00
|
|
|
env.updateInterval = 0;
|
2009-05-29 03:02:15 +00:00
|
|
|
|
2009-08-13 05:12:28 +00:00
|
|
|
fakeTimer = new jasmine.FakeTimer();
|
|
|
|
env.setTimeout = fakeTimer.setTimeout;
|
|
|
|
env.clearTimeout = fakeTimer.clearTimeout;
|
|
|
|
env.setInterval = fakeTimer.setInterval;
|
|
|
|
env.clearInterval = fakeTimer.clearInterval;
|
2009-05-29 03:02:15 +00:00
|
|
|
});
|
|
|
|
|
2009-09-28 23:23:21 +00:00
|
|
|
describe('beforeEach', function() {
|
|
|
|
it('should run before each spec for all suites', function () {
|
|
|
|
var foo;
|
|
|
|
env.beforeEach(function () {
|
|
|
|
foo = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('suite 1', function () {
|
|
|
|
env.it('test 1-1', function() {
|
|
|
|
foo++;
|
|
|
|
this.expect(foo).toEqual(1);
|
|
|
|
});
|
|
|
|
env.it('test 1-2', function() {
|
|
|
|
foo++;
|
|
|
|
this.expect(foo).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('suite 2', function () {
|
|
|
|
env.it('test 2-1', function() {
|
2009-10-16 01:58:52 +00:00
|
|
|
foo++;
|
|
|
|
this.expect(foo).toEqual(1);
|
2009-09-28 23:23:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.currentRunner().execute();
|
|
|
|
|
|
|
|
var runnerResults = env.currentRunner().results();
|
|
|
|
expect(runnerResults.totalCount).toEqual(3);
|
|
|
|
expect(runnerResults.passedCount).toEqual(3);
|
|
|
|
});
|
2009-10-16 01:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
it('should provide all specs', function () {
|
|
|
|
var foo;
|
|
|
|
env.beforeEach(function () {
|
|
|
|
foo = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('suite 1', function () {
|
|
|
|
env.it('test 1-1', function() {
|
|
|
|
foo++;
|
|
|
|
this.expect(foo).toEqual(1);
|
|
|
|
});
|
|
|
|
env.it('test 1-2', function() {
|
|
|
|
foo++;
|
|
|
|
this.expect(foo).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('suite 2', function () {
|
|
|
|
env.it('test 2-1', function() {
|
|
|
|
foo++;
|
|
|
|
this.expect(foo).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.currentRunner().execute();
|
|
|
|
|
|
|
|
|
|
|
|
expect(env.currentRunner().specs().length).toEqual(3);
|
|
|
|
});
|
2009-09-28 23:23:21 +00:00
|
|
|
});
|
|
|
|
|
2009-10-16 01:58:52 +00:00
|
|
|
describe('afterEach', function() {
|
2009-09-28 23:23:21 +00:00
|
|
|
it('should run after each spec for all suites', function () {
|
|
|
|
var foo = 3;
|
|
|
|
env.afterEach(function () {
|
|
|
|
foo = foo - 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('suite 1', function () {
|
|
|
|
env.it('test 1-1', function() {
|
|
|
|
this.expect(foo).toEqual(3);
|
|
|
|
});
|
|
|
|
env.it('test 1-2', function() {
|
|
|
|
this.expect(foo).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('suite 2', function () {
|
|
|
|
env.it('test 2-1', function() {
|
2009-10-16 01:58:52 +00:00
|
|
|
this.expect(foo).toEqual(1);
|
2009-09-28 23:23:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.currentRunner().execute();
|
|
|
|
|
|
|
|
var runnerResults = env.currentRunner().results();
|
|
|
|
expect(runnerResults.totalCount).toEqual(3);
|
|
|
|
expect(runnerResults.passedCount).toEqual(3);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
it('should run child suites and specs and generate results when execute is called', function() {
|
|
|
|
env.describe('one suite description', function () {
|
|
|
|
env.it('should be a test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('another suite description', function () {
|
|
|
|
env.it('should be another test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-09-28 23:23:21 +00:00
|
|
|
env.currentRunner().execute();
|
2009-05-29 03:02:15 +00:00
|
|
|
|
2009-09-28 23:23:21 +00:00
|
|
|
var runnerResults = env.currentRunner().results();
|
2009-08-08 15:53:15 +00:00
|
|
|
expect(runnerResults.totalCount).toEqual(2);
|
|
|
|
expect(runnerResults.passedCount).toEqual(1);
|
|
|
|
expect(runnerResults.failedCount).toEqual(1);
|
2009-05-29 03:02:15 +00:00
|
|
|
});
|
|
|
|
|
2009-08-08 15:53:15 +00:00
|
|
|
|
2009-05-29 03:02:15 +00:00
|
|
|
it('should ignore suites that have been x\'d', function() {
|
|
|
|
env.xdescribe('one suite description', function () {
|
|
|
|
env.it('should be a test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('another suite description', function () {
|
|
|
|
env.it('should be another test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-09-28 23:23:21 +00:00
|
|
|
env.currentRunner().execute();
|
2009-09-04 17:57:08 +00:00
|
|
|
|
2009-09-28 23:23:21 +00:00
|
|
|
var runnerResults = env.currentRunner().results();
|
2009-08-13 05:12:28 +00:00
|
|
|
expect(runnerResults.totalCount).toEqual(1);
|
|
|
|
expect(runnerResults.passedCount).toEqual(0);
|
|
|
|
expect(runnerResults.failedCount).toEqual(1);
|
2009-05-29 03:02:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should roll up results from all specs', function() {
|
|
|
|
env.describe('one suite description', function () {
|
|
|
|
env.it('should be a test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
env.describe('another suite description', function () {
|
|
|
|
env.it('should be another test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-09-28 23:23:21 +00:00
|
|
|
env.currentRunner().execute();
|
|
|
|
|
|
|
|
var results = env.currentRunner().results();
|
2009-05-29 03:02:15 +00:00
|
|
|
expect(results.totalCount).toEqual(2);
|
|
|
|
expect(results.passedCount).toEqual(1);
|
|
|
|
expect(results.failedCount).toEqual(1);
|
|
|
|
});
|
|
|
|
|
2009-08-13 05:12:28 +00:00
|
|
|
describe('reporting', function () {
|
|
|
|
var fakeReporter;
|
|
|
|
beforeEach(function () {
|
|
|
|
fakeReporter = jasmine.createSpyObj("fakeReporter", ["log", "reportRunnerStarting", "reportRunnerResults"]);
|
|
|
|
env.addReporter(fakeReporter);
|
|
|
|
});
|
2009-06-15 15:14:55 +00:00
|
|
|
|
2009-08-13 05:12:28 +00:00
|
|
|
it('should report runner results when the runner has completed running', function() {
|
|
|
|
env.describe('one suite description', function () {
|
|
|
|
env.it('should be a test', function() {
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2009-06-15 15:14:55 +00:00
|
|
|
|
2009-08-13 05:12:28 +00:00
|
|
|
env.describe('another suite description', function () {
|
|
|
|
env.it('should be another test', function() {
|
|
|
|
this.waits(200);
|
|
|
|
this.runs(function () {
|
|
|
|
this.expect(true).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2009-06-15 15:14:55 +00:00
|
|
|
|
2009-09-28 23:23:21 +00:00
|
|
|
env.currentRunner().execute();
|
2010-06-24 17:34:03 +00:00
|
|
|
expect(fakeReporter.reportRunnerResults).not.toHaveBeenCalled();
|
2009-08-13 05:12:28 +00:00
|
|
|
fakeTimer.tick(200);
|
2009-08-27 05:13:30 +00:00
|
|
|
//This blows up the JSApiReporter.
|
2010-06-24 17:34:03 +00:00
|
|
|
//expect(fakeReporter.reportRunnerResults).toHaveBeenCalledWith(env.currentRunner);
|
|
|
|
expect(fakeReporter.reportRunnerResults).toHaveBeenCalled();
|
2009-09-28 23:23:21 +00:00
|
|
|
expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner().results());
|
2009-08-13 05:12:28 +00:00
|
|
|
});
|
2009-06-15 15:14:55 +00:00
|
|
|
});
|
|
|
|
|
2009-07-09 01:33:15 +00:00
|
|
|
it("should report when the tests start running", function() {
|
|
|
|
var fakeReporter = jasmine.createSpyObj("fakeReporter", ["log", "reportRunnerStarting"]);
|
|
|
|
env.addReporter(fakeReporter);
|
|
|
|
|
2009-08-19 14:42:47 +00:00
|
|
|
|
2009-07-09 01:33:15 +00:00
|
|
|
var runner = new jasmine.Runner(env);
|
2009-08-27 05:13:30 +00:00
|
|
|
runner.arbitraryVariable = 'foo';
|
2009-08-19 14:42:47 +00:00
|
|
|
spyOn(runner.queue, 'start');
|
2010-06-24 17:34:03 +00:00
|
|
|
expect(fakeReporter.reportRunnerStarting).not.toHaveBeenCalled();
|
2009-07-09 01:33:15 +00:00
|
|
|
runner.execute();
|
2010-06-24 17:34:03 +00:00
|
|
|
expect(fakeReporter.reportRunnerStarting).toHaveBeenCalled();
|
2009-08-27 05:13:30 +00:00
|
|
|
var reportedRunner = fakeReporter.reportRunnerStarting.mostRecentCall.args[0];
|
|
|
|
expect(reportedRunner.arbitraryVariable).toEqual('foo');
|
2010-06-24 17:34:03 +00:00
|
|
|
expect(runner.queue.start).toHaveBeenCalled();
|
2009-07-09 01:33:15 +00:00
|
|
|
});
|
|
|
|
|
2010-06-22 17:18:22 +00:00
|
|
|
describe("when suites are nested", function() {
|
|
|
|
var suite1, suite2, suite3;
|
|
|
|
|
|
|
|
function suiteNames(suites) {
|
|
|
|
var suiteDescriptions = [];
|
|
|
|
for (var i = 0; i < suites.length; i++) {
|
|
|
|
suiteDescriptions.push(suites[i].getFullName());
|
|
|
|
}
|
|
|
|
return suiteDescriptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
suite1 = env.describe("suite 1", function() {
|
|
|
|
suite2 = env.describe("suite 2", function() {
|
|
|
|
});
|
2009-09-28 23:23:21 +00:00
|
|
|
});
|
2010-06-22 17:18:22 +00:00
|
|
|
suite3 = env.describe("suite 3", function() {});
|
2009-08-13 05:12:28 +00:00
|
|
|
});
|
2009-07-09 01:33:15 +00:00
|
|
|
|
2010-06-22 17:18:22 +00:00
|
|
|
it("#suites should return a flat array of all suites, including nested suites", function() {
|
|
|
|
var suites = env.currentRunner().suites();
|
|
|
|
expect(suiteNames(suites)).toEqual([suite1.getFullName(), suite2.getFullName(), suite3.getFullName()]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("#topLevelSuites should return a flat array of all top-level suites only", function() {
|
|
|
|
var suites = env.currentRunner().topLevelSuites();
|
|
|
|
expect(suiteNames(suites)).toEqual([suite1.getFullName(), suite3.getFullName()]);
|
|
|
|
});
|
2009-07-09 01:33:15 +00:00
|
|
|
});
|
2011-06-07 14:01:48 +00:00
|
|
|
});
|