dwf/rva: runner that can execute multiple suites.

This commit is contained in:
pivotal 2008-12-02 11:08:12 -08:00
parent f43ba0a51c
commit 2c1d809e62
3 changed files with 119 additions and 20 deletions

View File

@ -92,7 +92,7 @@
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true"> <file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js"> <entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="411" column="0" selection-start="11018" selection-end="11018" vertical-scroll-proportion="0.7427466"> <state line="465" column="7" selection-start="12461" selection-end="12461" vertical-scroll-proportion="0.9632495">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -110,7 +110,7 @@
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false"> <file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js"> <entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="199" column="0" selection-start="4076" selection-end="4076" vertical-scroll-proportion="1.8949951"> <state line="238" column="9" selection-start="4765" selection-end="4765" vertical-scroll-proportion="0.5599194">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -451,14 +451,14 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js"> <entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="199" column="0" selection-start="4076" selection-end="4076" vertical-scroll-proportion="1.8949951"> <state line="238" column="9" selection-start="4765" selection-end="4765" vertical-scroll-proportion="0.5599194">
<folding /> <folding />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js"> <entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="411" column="0" selection-start="11018" selection-end="11018" vertical-scroll-proportion="0.7427466"> <state line="465" column="7" selection-start="12461" selection-end="12461" vertical-scroll-proportion="0.9632495">
<folding /> <folding />
</state> </state>
</provider> </provider>

View File

@ -159,6 +159,7 @@ var describe = function (description, spec_definitions) {
description: description, description: description,
specs: [], specs: [],
specIndex: 0, specIndex: 0,
finished: false,
execute: function () { execute: function () {
if (that.specs.length > 0) { if (that.specs.length > 0) {
@ -176,6 +177,9 @@ var describe = function (description, spec_definitions) {
currentSpec.execute(); currentSpec.execute();
that.waitForDone(currentSpec); that.waitForDone(currentSpec);
} }
else {
that.finished = true;
}
}, },
waitForDone: function(spec) { waitForDone: function(spec) {
@ -190,39 +194,84 @@ var describe = function (description, spec_definitions) {
} }
currentSuite = that; currentSuite = that;
currentRunner.suites.push(that);
spec_definitions(); spec_definitions();
return that; return that;
} }
var currentSuite = describe('default current suite', function() {});
var currentSpec;
/* /*
* Jasmine constructor * Jasmine constructor
*/ */
var jasmine_init = function () { //var jasmine_init = function () {
return { // return {
results: [] // results: []
} // }
} //}
/* /*
* Jasmine instance * 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: * TODO:
* - add spec or description to results * - add spec or description to results
//* - spec.execute needs to wait until the spec is done //* - 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 //* - 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 before
* - Suite supports after * - Suite supports after
* - Suite supports before_each * - Suite supports before_each
* - Suite supports after_each * - Suite supports after_each
* - Suite supports asynch * - Suite rolls up spec results
//* - Suite supports asynch
* - Runner that runs suites in order * - Runner that runs suites in order
* - Runner supports async * - Runner supports async
* - HTML reporter * - HTML reporter

62
test/bootstrap.js vendored
View File

@ -399,16 +399,66 @@ var testSpecScope = function () {
}, 1000); }, 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 () { var runTests = function () {
$('spinner').show(); $('spinner').show();
testMatchersComparisons(); testMatchersComparisons();
testMatchersReporting(); testMatchersReporting();
testSpecs(); testSpecs();
testAsyncSpecs(); testAsyncSpecs();
testAsyncSpecsWithMockSuite(); testAsyncSpecsWithMockSuite();
testSuites(); testSuites();
testSpecScope(); testSpecScope();
testRunner();
setTimeout(function() { setTimeout(function() {
$('spinner').hide(); $('spinner').hide();