Re-refactored Queue to use straightforward callbacks
This commit is contained in:
parent
9475de28b3
commit
0d6c6c2a35
|
@ -479,24 +479,20 @@ describe("jasmine spec running", function () {
|
||||||
var nested = env.describe('suite', function () {
|
var nested = env.describe('suite', function () {
|
||||||
env.describe('nested', function () {
|
env.describe('nested', function () {
|
||||||
env.it('should run nested suites', function () {
|
env.it('should run nested suites', function () {
|
||||||
console.log('first')
|
|
||||||
foo++;
|
foo++;
|
||||||
});
|
});
|
||||||
env.it('should run nested suites', function () {
|
env.it('should run nested suites', function () {
|
||||||
console.log('second')
|
|
||||||
bar++;
|
bar++;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.describe('nested 2', function () {
|
env.describe('nested 2', function () {
|
||||||
env.it('should run suites following nested suites', function () {
|
env.it('should run suites following nested suites', function () {
|
||||||
console.log('third')
|
|
||||||
baz++;
|
baz++;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
env.it('should run tests following nested suites', function () {
|
env.it('should run tests following nested suites', function () {
|
||||||
console.log('fourth')
|
|
||||||
quux++;
|
quux++;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -88,5 +88,5 @@ jasmine.ActionCollection.prototype.waitForDone = function(action) {
|
||||||
self.env.clearInterval(id);
|
self.env.clearInterval(id);
|
||||||
afterExecute();
|
afterExecute();
|
||||||
}
|
}
|
||||||
}, 15000);
|
}, 150);
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,18 +12,14 @@ jasmine.Block = function(env, func, spec) {
|
||||||
this.spec = spec;
|
this.spec = spec;
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Block.prototype._next = function() {
|
jasmine.Block.prototype.execute = function(onComplete) {
|
||||||
this.spec.finish(); // default value is to be done after one function
|
|
||||||
};
|
|
||||||
|
|
||||||
jasmine.Block.prototype.execute = function() {
|
|
||||||
this.env.reporter.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...');
|
this.env.reporter.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...');
|
||||||
try {
|
try {
|
||||||
this.func.apply(this.spec);
|
this.func.apply(this.spec);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.fail(e);
|
this.fail(e);
|
||||||
}
|
}
|
||||||
this._next();
|
onComplete();
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Block.prototype.fail = function(e) {
|
jasmine.Block.prototype.fail = function(e) {
|
||||||
|
|
53
src/Queue.js
53
src/Queue.js
|
@ -1,49 +1,44 @@
|
||||||
jasmine.Queue = function(onComplete) {
|
jasmine.Queue = function() {
|
||||||
this.blocks = [];
|
this.blocks = [];
|
||||||
this.onComplete = function () {
|
this.running = false;
|
||||||
onComplete();
|
|
||||||
};
|
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Queue.prototype.add = function(block) {
|
jasmine.Queue.prototype.add = function(block) {
|
||||||
this.setNextOnLastInQueue(block);
|
|
||||||
this.blocks.push(block);
|
this.blocks.push(block);
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Queue.prototype.start = function() {
|
jasmine.Queue.prototype.start = function(onComplete) {
|
||||||
if (this.blocks[0]) {
|
var self = this;
|
||||||
this.blocks[0].execute();
|
self.onComplete = onComplete;
|
||||||
|
if (self.blocks[0]) {
|
||||||
|
self.blocks[0].execute(function () {
|
||||||
|
self._next();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.onComplete();
|
self.finish();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jasmine.Queue.prototype.isRunning = function () {
|
||||||
|
return this.running;
|
||||||
|
};
|
||||||
|
|
||||||
jasmine.Queue.prototype._next = function () {
|
jasmine.Queue.prototype._next = function () {
|
||||||
this.index++;
|
|
||||||
if (this.index < this.blocks.length) {
|
|
||||||
this.blocks[this.index].execute();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
jasmine.Queue.prototype.setNextOnLastInQueue = function (block) {
|
|
||||||
var self = this;
|
var self = this;
|
||||||
block._next = function () {
|
self.index++;
|
||||||
self.onComplete();
|
if (self.index < self.blocks.length) {
|
||||||
};
|
self.blocks[self.index].execute(function () {self._next();});
|
||||||
if (self.blocks.length > 0) {
|
} else {
|
||||||
var previousBlock = self.blocks[self.blocks.length - 1];
|
self.finish();
|
||||||
previousBlock._next = function() {
|
|
||||||
block.execute();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Queue.prototype.isComplete = function () {
|
jasmine.Queue.prototype.finish = function () {
|
||||||
return this.index >= (this.blocks.length - 1);
|
if (this.onComplete) {
|
||||||
|
this.onComplete();
|
||||||
|
}
|
||||||
|
this.running = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Queue.prototype.getResults = function () {
|
jasmine.Queue.prototype.getResults = function () {
|
||||||
|
|
11
src/Spec.js
11
src/Spec.js
|
@ -90,16 +90,15 @@ jasmine.Spec.prototype.finishCallback = function() {
|
||||||
this.env.reporter.reportSpecResults(this);
|
this.env.reporter.reportSpecResults(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Spec.prototype.finish = function() {
|
jasmine.Spec.prototype.finish = function(onComplete) {
|
||||||
for (var i = 0; i < this.afterCallbacks.length; i++) {
|
for (var i = 0; i < this.afterCallbacks.length; i++) {
|
||||||
this.afterCallbacks[i]();
|
this.afterCallbacks[i]();
|
||||||
}
|
}
|
||||||
this.safeExecuteAfters();
|
this.safeExecuteAfters();
|
||||||
this.removeAllSpies();
|
this.removeAllSpies();
|
||||||
this.finishCallback();
|
this.finishCallback();
|
||||||
this.finished = true;
|
if (onComplete) {
|
||||||
if (this.suite.next) {
|
onComplete();
|
||||||
this.suite.next();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,7 +107,7 @@ jasmine.Spec.prototype.after = function(doAfter) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
jasmine.Spec.prototype.execute = function() {
|
jasmine.Spec.prototype.execute = function(onComplete) {
|
||||||
var spec = this;
|
var spec = this;
|
||||||
if (!spec.env.specFilter(spec)) {
|
if (!spec.env.specFilter(spec)) {
|
||||||
spec.results.skipped = true;
|
spec.results.skipped = true;
|
||||||
|
@ -122,7 +121,7 @@ jasmine.Spec.prototype.execute = function() {
|
||||||
|
|
||||||
spec.safeExecuteBefores();
|
spec.safeExecuteBefores();
|
||||||
|
|
||||||
spec.queue.start();
|
spec.queue.start(function () { spec.finish(onComplete); });
|
||||||
spec.env.currentlyRunningTests = false;
|
spec.env.currentlyRunningTests = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
22
src/Suite.js
22
src/Suite.js
|
@ -27,11 +27,11 @@ jasmine.Suite.prototype.getFullName = function() {
|
||||||
return fullName;
|
return fullName;
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Suite.prototype.finish = function() {
|
jasmine.Suite.prototype.finish = function(onComplete) {
|
||||||
this.env.reporter.reportSuiteResults(this);
|
this.env.reporter.reportSuiteResults(this);
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
if (this.parentSuite) {
|
if (typeof(onComplete) == 'function') {
|
||||||
this.parentSuite.next();
|
onComplete();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,18 +53,8 @@ jasmine.Suite.prototype.add = function(block) {
|
||||||
this.queue.add(block);
|
this.queue.add(block);
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Suite.prototype.execute = function() {
|
jasmine.Suite.prototype.execute = function(onComplete) {
|
||||||
this.queue.start();
|
var self = this;
|
||||||
|
this.queue.start(function () { self.finish(onComplete); });
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Suite.prototype._next = function () {
|
|
||||||
this.next();
|
|
||||||
};
|
|
||||||
|
|
||||||
jasmine.Suite.prototype.next = function() {
|
|
||||||
if (this.queue.isComplete()) {
|
|
||||||
this.finish();
|
|
||||||
} else {
|
|
||||||
this.queue._next();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
|
@ -5,10 +5,9 @@ jasmine.WaitsBlock = function(env, timeout, spec) {
|
||||||
|
|
||||||
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
|
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
|
||||||
|
|
||||||
jasmine.WaitsBlock.prototype.execute = function () {
|
jasmine.WaitsBlock.prototype.execute = function (onComplete) {
|
||||||
var self = this;
|
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
|
||||||
self.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
|
this.env.setTimeout(function () {
|
||||||
self.env.setTimeout(function () {
|
onComplete();
|
||||||
self._next();
|
}, this.timeout);
|
||||||
}, self.timeout);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
|
||||||
|
|
||||||
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
|
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
|
||||||
|
|
||||||
jasmine.WaitsForBlock.prototype.execute = function () {
|
jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
|
self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
|
||||||
var latchFunctionResult;
|
var latchFunctionResult;
|
||||||
|
@ -18,12 +18,12 @@ jasmine.WaitsForBlock.prototype.execute = function () {
|
||||||
latchFunctionResult = self.latchFunction.apply(self.spec);
|
latchFunctionResult = self.latchFunction.apply(self.spec);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
self.fail(e);
|
self.fail(e);
|
||||||
self._next();
|
onComplete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (latchFunctionResult) {
|
if (latchFunctionResult) {
|
||||||
self._next();
|
onComplete();
|
||||||
} else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
|
} else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
|
||||||
var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
|
var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
|
||||||
self.fail({
|
self.fail({
|
||||||
|
@ -33,6 +33,6 @@ jasmine.WaitsForBlock.prototype.execute = function () {
|
||||||
self.spec._next();
|
self.spec._next();
|
||||||
} else {
|
} else {
|
||||||
self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
|
self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
|
||||||
self.env.setTimeout(function () { self.execute(); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
|
self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue