Merge branch 'loop-dont-recurse' of git://github.com/Xian/jasmine into xian_jasmine

This commit is contained in:
Rajan Agaskar & Ryan Dy 2009-10-13 14:12:35 -07:00
commit 31bb686fd5
3 changed files with 151 additions and 37 deletions

76
spec/runner.html Normal file
View File

@ -0,0 +1,76 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<script type="text/javascript" src="../src/base.js"></script>
<script type="text/javascript" src="../src/util.js"></script>
<script type="text/javascript" src="../src/Env.js"></script>
<script type="text/javascript" src="../src/Reporter.js"></script>
<script type="text/javascript" src="../src/Block.js"></script>
<script type="text/javascript" src="../src/JsApiReporter.js"></script>
<script type="text/javascript" src="../src/Matchers.js"></script>
<script type="text/javascript" src="../src/mock-timeout.js"></script>
<script type="text/javascript" src="../src/MultiReporter.js"></script>
<script type="text/javascript" src="../src/NestedResults.js"></script>
<script type="text/javascript" src="../src/PrettyPrinter.js"></script>
<script type="text/javascript" src="../src/Queue.js"></script>
<script type="text/javascript" src="../src/Reporters.js"></script>
<script type="text/javascript" src="../src/Runner.js"></script>
<script type="text/javascript" src="../src/Spec.js"></script>
<script type="text/javascript" src="../src/Suite.js"></script>
<script type="text/javascript" src="../src/version.json"></script>
<script type="text/javascript" src="../src/WaitsBlock.js"></script>
<script type="text/javascript" src="../src/WaitsForBlock.js"></script>
<script type="text/javascript" src="../lib/TrivialReporter.js"></script>
<script type="text/javascript">
(function () {
var suites = [
'suites/SpySpec.js',
'suites/JsApiReporterSpec.js',
'suites/RunnerSpec.js',
'suites/EnvSpec.js',
'suites/NestedResultsSpec.js',
'suites/ExceptionsSpec.js',
'suites/TrivialReporterSpec.js',
'suites/MatchersSpec.js',
'suites/QueueSpec.js',
'suites/ReporterSpec.js',
'suites/MultiReporterSpec.js',
'suites/PrettyPrintSpec.js',
'suites/SpecSpec.js',
'suites/SuiteSpec.js',
'suites/SpecRunningSpec.js',
];
for (var i = 0; i < suites.length; i++) {
jasmine.include(suites[i], true);
}
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var trivialReporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.specFilter = function(spec) {
return trivialReporter.specFilter(spec);
};
window.onload = function() {
jasmineEnv.execute();
};
})();
</script>
<link href="../lib/jasmine.css" rel="stylesheet"/>
</head>
<body>
</body>
</html>

23
spec/suites/QueueSpec.js Normal file
View File

@ -0,0 +1,23 @@
describe("jasmine.Queue", function() {
it("should not call itself recursively, so we don't get stack overflow errors", function() {
var queue = new jasmine.Queue(new jasmine.Env());
queue.add(new jasmine.Block(null, function() {}));
queue.add(new jasmine.Block(null, function() {}));
queue.add(new jasmine.Block(null, function() {}));
queue.add(new jasmine.Block(null, function() {}));
var nestCount = 0;
var maxNestCount = 0;
var nextCallCount = 0;
queue.next_ = function() {
nestCount++;
if (nestCount > maxNestCount) maxNestCount = nestCount;
jasmine.Queue.prototype.next_.apply(queue, arguments);
nestCount--;
};
queue.start();
expect(maxNestCount).toEqual(1);
});
});

View File

@ -6,7 +6,7 @@ jasmine.Queue = function(env) {
this.offset = 0;
};
jasmine.Queue.prototype.addBefore = function (block) {
jasmine.Queue.prototype.addBefore = function(block) {
this.blocks.unshift(block);
};
@ -14,59 +14,74 @@ jasmine.Queue.prototype.add = function(block) {
this.blocks.push(block);
};
jasmine.Queue.prototype.insertNext = function (block) {
jasmine.Queue.prototype.insertNext = function(block) {
this.blocks.splice((this.index + this.offset + 1), 0, block);
this.offset++;
};
jasmine.Queue.prototype.start = function(onComplete) {
var self = this;
self.running = true;
self.onComplete = onComplete;
if (self.blocks[0]) {
self.blocks[0].execute(function () {
self._next();
});
} else {
self.finish();
}
this.running = true;
this.onComplete = onComplete;
this.next_();
};
jasmine.Queue.prototype.isRunning = function () {
jasmine.Queue.prototype.isRunning = function() {
return this.running;
};
jasmine.Queue.prototype._next = function () {
jasmine.Queue.LOOP_DONT_RECURSE = true;
jasmine.Queue.prototype.next_ = function() {
var self = this;
var doNext = function () {
self.offset = 0;
self.index++;
var goAgain = true;
while (goAgain) {
goAgain = false;
if (self.index < self.blocks.length) {
self.blocks[self.index].execute(function () {
self._next();
});
var calledSynchronously = true;
var completedSynchronously = false;
var onComplete = function () {
if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) {
completedSynchronously = true;
return;
}
self.offset = 0;
self.index++;
var now = new Date().getTime();
if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
self.env.lastUpdate = now;
self.env.setTimeout(function() {
self.next_();
}, 0);
} else {
if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
goAgain = true;
} else {
self.next_();
}
}
};
self.blocks[self.index].execute(onComplete);
calledSynchronously = false;
if (completedSynchronously) {
onComplete();
}
} else {
self.finish();
self.running = false;
if (self.onComplete) {
self.onComplete();
}
}
};
var now = new Date().getTime();
if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) {
this.env.lastUpdate = now;
this.env.setTimeout(doNext, 0);
} else {
doNext();
}
};
jasmine.Queue.prototype.finish = function () {
this.running = false;
if (this.onComplete) {
this.onComplete();
}
};
jasmine.Queue.prototype.results = function () {
jasmine.Queue.prototype.results = function() {
var results = new jasmine.NestedResults();
for (var i = 0; i < this.blocks.length; i++) {
if (this.blocks[i].results) {