dwf/rva: refactoring Suite (describe function) & Runner to use shared parent actionCollection
This commit is contained in:
parent
2c1d809e62
commit
42eeab1cdb
16
jasmine.iws
16
jasmine.iws
|
@ -89,10 +89,10 @@
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
|
<file leaf-file-name="bootstrap.js" pinned="false" current="false" current-in-tab="false">
|
||||||
<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="465" column="7" selection-start="12461" selection-end="12461" vertical-scroll-proportion="0.9632495">
|
<state line="333" column="14" selection-start="9162" selection-end="9162" vertical-scroll-proportion="1.0473888">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -107,10 +107,10 @@
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
|
<file leaf-file-name="jasmine.js" pinned="false" current="true" current-in-tab="true">
|
||||||
<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="238" column="9" selection-start="4765" selection-end="4765" vertical-scroll-proportion="0.5599194">
|
<state line="230" column="0" selection-start="4905" selection-end="4938" vertical-scroll-proportion="0.7703928">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -449,16 +449,16 @@
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/lib/jasmine.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="238" column="9" selection-start="4765" selection-end="4765" vertical-scroll-proportion="0.5599194">
|
<state line="333" column="14" selection-start="9162" selection-end="9162" vertical-scroll-proportion="1.0473888">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/test/bootstrap.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="465" column="7" selection-start="12461" selection-end="12461" vertical-scroll-proportion="0.9632495">
|
<state line="230" column="0" selection-start="4905" selection-end="4938" vertical-scroll-proportion="0.7703928">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
143
lib/jasmine.js
143
lib/jasmine.js
|
@ -18,6 +18,46 @@ if (typeof Function.method !== 'function') {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var actionCollection = function () {
|
||||||
|
var that = {
|
||||||
|
actions: [],
|
||||||
|
index: 0,
|
||||||
|
finished: false,
|
||||||
|
|
||||||
|
execute: function () {
|
||||||
|
if (that.actions.length > 0) {
|
||||||
|
that.next();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getCurrentAction: function () {
|
||||||
|
return that.actions[that.index];
|
||||||
|
},
|
||||||
|
|
||||||
|
next: function() {
|
||||||
|
if (that.index < that.actions.length) {
|
||||||
|
var currentAction = that.getCurrentAction();
|
||||||
|
currentAction.execute();
|
||||||
|
that.waitForDone(currentAction);
|
||||||
|
} else {
|
||||||
|
that.finished = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
waitForDone: function(action) {
|
||||||
|
var id = setInterval(function () {
|
||||||
|
if (action.finished) {
|
||||||
|
clearInterval(id);
|
||||||
|
that.index++;
|
||||||
|
that.next();
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return that;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Jasmine
|
* Jasmine
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
@ -150,106 +190,24 @@ var waits = function (timeout) {
|
||||||
|
|
||||||
var then = runs;
|
var then = runs;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var describe = function (description, spec_definitions) {
|
var describe = function (description, spec_definitions) {
|
||||||
var that = {
|
var that = actionCollection();
|
||||||
description: description,
|
|
||||||
specs: [],
|
|
||||||
specIndex: 0,
|
|
||||||
finished: false,
|
|
||||||
|
|
||||||
execute: function () {
|
that.description = description;
|
||||||
if (that.specs.length > 0) {
|
that.specs = that.actions;
|
||||||
that.next();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
getCurrentSpec: function () {
|
|
||||||
return that.specs[that.specIndex];
|
|
||||||
},
|
|
||||||
|
|
||||||
next: function() {
|
|
||||||
if (that.specIndex < that.specs.length) {
|
|
||||||
var currentSpec = that.getCurrentSpec();
|
|
||||||
currentSpec.execute();
|
|
||||||
that.waitForDone(currentSpec);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
that.finished = true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
waitForDone: function(spec) {
|
|
||||||
var id = setInterval(function () {
|
|
||||||
if (spec.finished) {
|
|
||||||
clearInterval(id);
|
|
||||||
that.specIndex++;
|
|
||||||
that.next();
|
|
||||||
}
|
|
||||||
}, 150);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentSuite = that;
|
currentSuite = that;
|
||||||
currentRunner.suites.push(that);
|
currentRunner.suites.push(that);
|
||||||
spec_definitions();
|
|
||||||
|
|
||||||
|
spec_definitions();
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Jasmine = function () {
|
||||||
|
var that = actionCollection();
|
||||||
|
|
||||||
/*
|
that.suites = that.actions;
|
||||||
* Jasmine constructor
|
|
||||||
*/
|
|
||||||
//var jasmine_init = function () {
|
|
||||||
// return {
|
|
||||||
// results: []
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Jasmine instance
|
|
||||||
*/
|
|
||||||
//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;
|
currentRunner = that;
|
||||||
return that;
|
return that;
|
||||||
}
|
}
|
||||||
|
@ -259,7 +217,6 @@ var currentSuite = describe('default current suite', function() {});
|
||||||
|
|
||||||
var currentSpec;
|
var currentSpec;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - add spec or description to results
|
* - add spec or description to results
|
||||||
|
@ -272,8 +229,8 @@ var currentSpec;
|
||||||
* - Suite supports after_each
|
* - Suite supports after_each
|
||||||
* - Suite rolls up spec results
|
* - Suite rolls up spec results
|
||||||
//* - Suite supports asynch
|
//* - 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
|
||||||
* - Shows pass/fail progress (just like bootstrap reporter)
|
* - Shows pass/fail progress (just like bootstrap reporter)
|
||||||
* - Lists a Summary: total # specs, # of passed, # of failed
|
* - Lists a Summary: total # specs, # of passed, # of failed
|
||||||
|
|
Loading…
Reference in New Issue