From 2c1d809e62fcad745e11782ec066240dbca4dd77 Mon Sep 17 00:00:00 2001 From: pivotal Date: Tue, 2 Dec 2008 11:08:12 -0800 Subject: [PATCH] dwf/rva: runner that can execute multiple suites. --- jasmine.iws | 8 +++--- lib/jasmine.js | 69 ++++++++++++++++++++++++++++++++++++++++------- test/bootstrap.js | 62 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 119 insertions(+), 20 deletions(-) diff --git a/jasmine.iws b/jasmine.iws index b4e965d..cf9e1f9 100644 --- a/jasmine.iws +++ b/jasmine.iws @@ -92,7 +92,7 @@ - + @@ -110,7 +110,7 @@ - + @@ -451,14 +451,14 @@ - + - + diff --git a/lib/jasmine.js b/lib/jasmine.js index d9fe1a5..bba075b 100755 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -159,6 +159,7 @@ var describe = function (description, spec_definitions) { description: description, specs: [], specIndex: 0, + finished: false, execute: function () { if (that.specs.length > 0) { @@ -176,6 +177,9 @@ var describe = function (description, spec_definitions) { currentSpec.execute(); that.waitForDone(currentSpec); } + else { + that.finished = true; + } }, waitForDone: function(spec) { @@ -190,39 +194,84 @@ var describe = function (description, spec_definitions) { } currentSuite = that; + currentRunner.suites.push(that); spec_definitions(); return that; } -var currentSuite = describe('default current suite', function() {}); -var currentSpec; /* * Jasmine constructor */ -var jasmine_init = function () { - return { - results: [] - } -} +//var jasmine_init = function () { +// return { +// results: [] +// } +//} /* * Jasmine instance */ -var Jasmine = jasmine_init(); +//var Jasmine = jasmine_init(); + + +var Jasmine = function() { + var that = { + suites: [], + suiteIndex: 0, + + execute: function () { + if (that.suites.length > 0) { + that.next(); + } + }, + + getCurrentSuite: function () { + return that.suites[that.suiteIndex]; + }, + + next: function() { + if (that.suiteIndex < that.suites.length) { + var currentSuite = that.getCurrentSuite(); + currentSuite.execute(); + that.waitForDone(currentSuite); + } + }, + + waitForDone: function(suite) { + var id = setInterval(function () { + if (suite.finished) { + clearInterval(id); + that.suiteIndex++; + that.next(); + } + }, 150); + } + } + + currentRunner = that; + return that; +} + +var currentRunner = Jasmine(); +var currentSuite = describe('default current suite', function() {}); + +var currentSpec; + /* * TODO: * - add spec or description to results //* - spec.execute needs to wait until the spec is done //* - an async test will be killed after X ms if not done and then listed as failed with an "async fail" message of some sort - * - Suite to run tests in order, constructed with a function called describe + //* - Suite to run tests in order, constructed with a function called describe * - Suite supports before * - Suite supports after * - Suite supports before_each * - Suite supports after_each - * - Suite supports asynch + * - Suite rolls up spec results + //* - Suite supports asynch * - Runner that runs suites in order * - Runner supports async * - HTML reporter diff --git a/test/bootstrap.js b/test/bootstrap.js index 2324b85..93f0439 100755 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -399,16 +399,66 @@ var testSpecScope = function () { }, 1000); } + +var testRunner = function() { + + var runner = Jasmine(); + describe('one suite description', function () { + it('should be a test'); + }); + reporter.test((runner.suites.length === 1), + "Runner expected one suite"); + + runner = Jasmine(); + describe('one suite description', function () { + it('should be a test'); + }); + describe('another suite description', function () { + it('should be a test'); + }); + reporter.test((runner.suites.length === 2), + "Runner expected two suites"); + + runner = Jasmine(); + describe('one suite description', function () { + it('should be a test', function() { + runs(function () { + this.expects_that(true).should_equal(true); + }); + }); + }); + + describe('another suite description', function () { + it('should be another test', function() { + runs(function () { + this.expects_that(true).should_equal(false); + }); + }); + }); + + runner.execute(); + + setTimeout(function () { + reporter.test((runner.suites.length === 2), + "Runner expected two suites"); + reporter.test((runner.suites[0].specs[0].results[0].passed === true), + "Runner should have run specs in first suite"); + reporter.test((runner.suites[1].specs[0].results[0].passed === false), + "Runner should have run specs in second suite"); + }, 1000); +} + var runTests = function () { $('spinner').show(); testMatchersComparisons(); - testMatchersReporting(); - testSpecs(); - testAsyncSpecs(); - testAsyncSpecsWithMockSuite(); - testSuites(); - testSpecScope(); + testMatchersReporting(); + testSpecs(); + testAsyncSpecs(); + testAsyncSpecsWithMockSuite(); + testSuites(); + testSpecScope(); + testRunner(); setTimeout(function() { $('spinner').hide();