add setTimeout to Queue so reporters get periodic updates

This commit is contained in:
ragaskar 2009-08-13 07:52:44 -07:00
parent 7b63960db0
commit 454d453207
7 changed files with 61 additions and 17 deletions

View File

@ -1,8 +1,16 @@
describe('jasmine.Reporter', function() { describe('jasmine.Reporter', function() {
var env; var env;
var fakeTimer;
beforeEach(function() { beforeEach(function() {
env = new jasmine.Env(); env = new jasmine.Env();
fakeTimer = new jasmine.FakeTimer();
env.setTimeout = fakeTimer.setTimeout;
env.clearTimeout = fakeTimer.clearTimeout;
env.setInterval = fakeTimer.setInterval;
env.clearInterval = fakeTimer.clearInterval;
}); });
it('should get called from the test runner', function() { it('should get called from the test runner', function() {
@ -49,6 +57,7 @@ describe('jasmine.Reporter', function() {
var runner = env.currentRunner; var runner = env.currentRunner;
runner.execute(); runner.execute();
fakeTimer.tick(0);
expect(foo).toEqual(3); // 'foo was expected to be 3, was ' + foo); expect(foo).toEqual(3); // 'foo was expected to be 3, was ' + foo);
expect(bar).toEqual(2); // 'bar was expected to be 2, was ' + bar); expect(bar).toEqual(2); // 'bar was expected to be 2, was ' + bar);

View File

@ -30,6 +30,7 @@ describe('RunnerTest', function() {
}); });
env.currentRunner.execute(); env.currentRunner.execute();
fakeTimer.tick(0);
var runnerResults = env.currentRunner.getResults(); var runnerResults = env.currentRunner.getResults();
expect(runnerResults.totalCount).toEqual(2); expect(runnerResults.totalCount).toEqual(2);
@ -56,7 +57,8 @@ describe('RunnerTest', function() {
}); });
env.currentRunner.execute(); env.currentRunner.execute();
fakeTimer.tick(0);
var runnerResults = env.currentRunner.getResults(); var runnerResults = env.currentRunner.getResults();
expect(runnerResults.totalCount).toEqual(1); expect(runnerResults.totalCount).toEqual(1);
expect(runnerResults.passedCount).toEqual(0); expect(runnerResults.passedCount).toEqual(0);
@ -64,7 +66,6 @@ describe('RunnerTest', function() {
}); });
it('should roll up results from all specs', function() { it('should roll up results from all specs', function() {
var env = new jasmine.Env();
env.describe('one suite description', function () { env.describe('one suite description', function () {
env.it('should be a test', function() { env.it('should be a test', function() {
this.runs(function () { this.runs(function () {
@ -82,7 +83,8 @@ describe('RunnerTest', function() {
}); });
env.currentRunner.execute(); env.currentRunner.execute();
fakeTimer.tick(0);
var results = env.currentRunner.getResults(); var results = env.currentRunner.getResults();
expect(results.totalCount).toEqual(2); expect(results.totalCount).toEqual(2);
expect(results.passedCount).toEqual(1); expect(results.passedCount).toEqual(1);

View File

@ -64,7 +64,8 @@ describe("jasmine spec running", function () {
}); });
suite.execute(); suite.execute();
fakeTimer.tick(0);
expect(specWithNoBody.description).toEqual('new spec'); expect(specWithNoBody.description).toEqual('new spec');
expect(specWithExpectation.results.getItems().length).toEqual(1); // "Results aren't there after a spec was executed" expect(specWithExpectation.results.getItems().length).toEqual(1); // "Results aren't there after a spec was executed"
@ -116,6 +117,8 @@ describe("jasmine spec running", function () {
expect(foo).toEqual(0); expect(foo).toEqual(0);
specWithRunsAndWaits.execute(); specWithRunsAndWaits.execute();
fakeTimer.tick(0);
expect(foo).toEqual(1); expect(foo).toEqual(1);
fakeTimer.tick(500); fakeTimer.tick(500);
expect(foo).toEqual(2); expect(foo).toEqual(2);
@ -139,6 +142,7 @@ describe("jasmine spec running", function () {
}); });
a_spec.execute(); a_spec.execute();
fakeTimer.tick(0);
expect(a_spec.results.getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions'; expect(a_spec.results.getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions';
expect(a_spec.results.getItems()[0].passed).toEqual(true); // 'No call to waits(): Queued expectation failed'; expect(a_spec.results.getItems()[0].passed).toEqual(true); // 'No call to waits(): Queued expectation failed';
@ -159,6 +163,8 @@ describe("jasmine spec running", function () {
}); });
a_spec.execute(); a_spec.execute();
fakeTimer.tick(0);
expect(a_spec.results.getItems().length).toEqual(0); expect(a_spec.results.getItems().length).toEqual(0);
fakeTimer.tick(500); fakeTimer.tick(500);
@ -218,7 +224,10 @@ describe("jasmine spec running", function () {
yet_another_spec.execute(); yet_another_spec.execute();
fakeTimer.tick(250); //tick twice so that second runs gets eval'd first: mockClock bug?
fakeTimer.tick(100);
fakeTimer.tick(150);
expect(yet_another_spec.results.getItems().length).toEqual(1); expect(yet_another_spec.results.getItems().length).toEqual(1);
expect(yet_another_spec.results.getItems()[0].passed).toEqual(false); expect(yet_another_spec.results.getItems()[0].passed).toEqual(false);
@ -353,6 +362,8 @@ describe("jasmine spec running", function () {
}); });
suite.execute(); suite.execute();
fakeTimer.tick(0);
expect(log).toEqual("specafter2after1"); expect(log).toEqual("specafter2after1");
}); });
@ -383,6 +394,8 @@ describe("jasmine spec running", function () {
}); });
suite.execute(); suite.execute();
fakeTimer.tick(0);
expect(foo).toEqual(1); expect(foo).toEqual(1);
expect(bar).toEqual(0); expect(bar).toEqual(0);
@ -415,6 +428,8 @@ describe("jasmine spec running", function () {
}); });
suiteWithBefore.execute(); suiteWithBefore.execute();
fakeTimer.tick(0);
var suite = suiteWithBefore; var suite = suiteWithBefore;
expect(suite.beforeEachFunction); // "testBeforeAndAfterCallbacks: Suite's beforeEach was not defined"); expect(suite.beforeEachFunction); // "testBeforeAndAfterCallbacks: Suite's beforeEach was not defined");
expect(suite.getResults()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2"); expect(suite.getResults()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2");
@ -442,6 +457,8 @@ describe("jasmine spec running", function () {
}); });
suiteWithAfter.execute(); suiteWithAfter.execute();
fakeTimer.tick(0);
suite = suiteWithAfter; suite = suiteWithAfter;
expect(suite.afterEach.length).toEqual(1); expect(suite.afterEach.length).toEqual(1);
expect(suite.getResults()[0].passed()).toEqual(true); expect(suite.getResults()[0].passed()).toEqual(true);
@ -502,6 +519,8 @@ describe("jasmine spec running", function () {
expect(baz).toEqual(0); expect(baz).toEqual(0);
expect(quux).toEqual(0); expect(quux).toEqual(0);
nested.execute(); nested.execute();
fakeTimer.tick(0);
expect(foo).toEqual(1); expect(foo).toEqual(1);
expect(bar).toEqual(1); expect(bar).toEqual(1);
expect(baz).toEqual(1); expect(baz).toEqual(1);
@ -536,6 +555,8 @@ describe("jasmine spec running", function () {
expect(reachedFirstWaitsFor).toEqual(false); expect(reachedFirstWaitsFor).toEqual(false);
waitsSuite.execute(); waitsSuite.execute();
fakeTimer.tick(0);
expect(reachedFirstWaitsFor).toEqual(true); expect(reachedFirstWaitsFor).toEqual(true);
expect(foo).toEqual(0); expect(foo).toEqual(0);
expect(reachedSecondWaitsFor).toEqual(false); expect(reachedSecondWaitsFor).toEqual(false);
@ -618,6 +639,7 @@ describe("jasmine spec running", function () {
expect(foo).toEqual(0); expect(foo).toEqual(0);
expect(bar).toEqual(0); expect(bar).toEqual(0);
suiteWithBefore.execute(); suiteWithBefore.execute();
fakeTimer.tick(0);
expect(bar).toEqual(0); expect(bar).toEqual(0);
expect(foo).toEqual(1); expect(foo).toEqual(1);
@ -659,6 +681,8 @@ describe("jasmine spec running", function () {
expect(foo).toEqual(0); expect(foo).toEqual(0);
suiteWithAfter.execute(); suiteWithAfter.execute();
fakeTimer.tick(0);
expect(firstSpecHasRun).toEqual(true); expect(firstSpecHasRun).toEqual(true);
expect(secondSpecHasRun).toEqual(false); expect(secondSpecHasRun).toEqual(false);
@ -794,6 +818,7 @@ describe("jasmine spec running", function () {
}); });
suite.execute(); suite.execute();
fakeTimer.tick(0);
expect(report).toEqual("firstsecond"); expect(report).toEqual("firstsecond");
var suiteResults = suite.getResults(); var suiteResults = suite.getResults();
@ -832,6 +857,7 @@ describe("jasmine spec running", function () {
}); });
suite.execute(); suite.execute();
fakeTimer.tick(0);
expect(report).toEqual("firstsecondthird"); // "all tests should run"); expect(report).toEqual("firstsecondthird"); // "all tests should run");
//After each errors should not go in spec results because it confuses the count. //After each errors should not go in spec results because it confuses the count.
@ -898,7 +924,8 @@ describe("jasmine spec running", function () {
}); });
env.execute(); env.execute();
fakeTimer.tick(0);
var expected = [ var expected = [
"outer beforeEach", "outer beforeEach",
@ -1048,6 +1075,7 @@ describe("jasmine spec running", function () {
}); });
suite.execute(); suite.execute();
fakeTimer.tick(0);
expect(spec1Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: xxx; expected: expected"); expect(spec1Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: xxx; expected: expected");
expect(spec1Matcher.matcherForSpec("expected")).toEqual("matcherForSpec: actual: xxx; expected: expected"); expect(spec1Matcher.matcherForSpec("expected")).toEqual("matcherForSpec: actual: xxx; expected: expected");

View File

@ -1,4 +1,5 @@
jasmine.Queue = function() { jasmine.Queue = function(env) {
this.env = env;
this.blocks = []; this.blocks = [];
this.running = false; this.running = false;
this.index = 0; this.index = 0;
@ -37,13 +38,17 @@ jasmine.Queue.prototype.isRunning = function () {
jasmine.Queue.prototype._next = function () { jasmine.Queue.prototype._next = function () {
var self = this; var self = this;
self.offset = 0; self.env.setTimeout(function () {
self.index++; self.offset = 0;
if (self.index < self.blocks.length) { self.index++;
self.blocks[self.index].execute(function () {self._next();}); if (self.index < self.blocks.length) {
} else { self.blocks[self.index].execute(function () {
self.finish(); self._next();
} });
} else {
self.finish();
}
}, 0);
}; };
jasmine.Queue.prototype.finish = function () { jasmine.Queue.prototype.finish = function () {

View File

@ -7,7 +7,7 @@
jasmine.Runner = function(env) { jasmine.Runner = function(env) {
var self = this; var self = this;
self.env = env; self.env = env;
self.queue = new jasmine.Queue(); self.queue = new jasmine.Queue(env);
}; };
jasmine.Runner.prototype.execute = function() { jasmine.Runner.prototype.execute = function() {

View File

@ -12,7 +12,7 @@ jasmine.Spec = function(env, suite, description) {
spec.env = env; spec.env = env;
spec.suite = suite; spec.suite = suite;
spec.description = description; spec.description = description;
spec.queue = new jasmine.Queue(); spec.queue = new jasmine.Queue(env);
spec.finished = false; spec.finished = false;
spec.afterCallbacks = []; spec.afterCallbacks = [];

View File

@ -11,7 +11,7 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
var self = this; var self = this;
self.id = env.nextSuiteId_++; self.id = env.nextSuiteId_++;
self.description = description; self.description = description;
self.queue = new jasmine.Queue(); self.queue = new jasmine.Queue(env);
self.parentSuite = parentSuite; self.parentSuite = parentSuite;
self.env = env; self.env = env;
self.beforeQueue = []; self.beforeQueue = [];