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

@ -20,49 +20,64 @@ jasmine.Queue.prototype.insertNext = function (block) {
}; };
jasmine.Queue.prototype.start = function(onComplete) { jasmine.Queue.prototype.start = function(onComplete) {
var self = this; this.running = true;
self.running = true; this.onComplete = onComplete;
self.onComplete = onComplete; this.next_();
if (self.blocks[0]) {
self.blocks[0].execute(function () {
self._next();
});
} else {
self.finish();
}
}; };
jasmine.Queue.prototype.isRunning = function() { jasmine.Queue.prototype.isRunning = function() {
return this.running; return this.running;
}; };
jasmine.Queue.prototype._next = function () { jasmine.Queue.LOOP_DONT_RECURSE = true;
jasmine.Queue.prototype.next_ = function() {
var self = this; var self = this;
var doNext = function () { var goAgain = true;
while (goAgain) {
goAgain = false;
if (self.index < self.blocks.length) {
var calledSynchronously = true;
var completedSynchronously = false;
var onComplete = function () {
if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) {
completedSynchronously = true;
return;
}
self.offset = 0; self.offset = 0;
self.index++; self.index++;
if (self.index < self.blocks.length) {
self.blocks[self.index].execute(function () {
self._next();
});
} else {
self.finish();
}
};
var now = new Date().getTime(); var now = new Date().getTime();
if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
this.env.lastUpdate = now; self.env.lastUpdate = now;
this.env.setTimeout(doNext, 0); self.env.setTimeout(function() {
self.next_();
}, 0);
} else { } else {
doNext(); 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.running = false;
jasmine.Queue.prototype.finish = function () { if (self.onComplete) {
this.running = false; self.onComplete();
if (this.onComplete) { }
this.onComplete(); }
} }
}; };