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() {
var env;
var fakeTimer;
beforeEach(function() {
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() {
@ -49,6 +57,7 @@ describe('jasmine.Reporter', function() {
var runner = env.currentRunner;
runner.execute();
fakeTimer.tick(0);
expect(foo).toEqual(3); // 'foo was expected to be 3, was ' + foo);
expect(bar).toEqual(2); // 'bar was expected to be 2, was ' + bar);

View File

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

View File

@ -64,6 +64,7 @@ describe("jasmine spec running", function () {
});
suite.execute();
fakeTimer.tick(0);
expect(specWithNoBody.description).toEqual('new spec');
@ -116,6 +117,8 @@ describe("jasmine spec running", function () {
expect(foo).toEqual(0);
specWithRunsAndWaits.execute();
fakeTimer.tick(0);
expect(foo).toEqual(1);
fakeTimer.tick(500);
expect(foo).toEqual(2);
@ -139,6 +142,7 @@ describe("jasmine spec running", function () {
});
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()[0].passed).toEqual(true); // 'No call to waits(): Queued expectation failed';
@ -159,6 +163,8 @@ describe("jasmine spec running", function () {
});
a_spec.execute();
fakeTimer.tick(0);
expect(a_spec.results.getItems().length).toEqual(0);
fakeTimer.tick(500);
@ -218,7 +224,10 @@ describe("jasmine spec running", function () {
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()[0].passed).toEqual(false);
@ -353,6 +362,8 @@ describe("jasmine spec running", function () {
});
suite.execute();
fakeTimer.tick(0);
expect(log).toEqual("specafter2after1");
});
@ -383,6 +394,8 @@ describe("jasmine spec running", function () {
});
suite.execute();
fakeTimer.tick(0);
expect(foo).toEqual(1);
expect(bar).toEqual(0);
@ -415,6 +428,8 @@ describe("jasmine spec running", function () {
});
suiteWithBefore.execute();
fakeTimer.tick(0);
var suite = suiteWithBefore;
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");
@ -442,6 +457,8 @@ describe("jasmine spec running", function () {
});
suiteWithAfter.execute();
fakeTimer.tick(0);
suite = suiteWithAfter;
expect(suite.afterEach.length).toEqual(1);
expect(suite.getResults()[0].passed()).toEqual(true);
@ -502,6 +519,8 @@ describe("jasmine spec running", function () {
expect(baz).toEqual(0);
expect(quux).toEqual(0);
nested.execute();
fakeTimer.tick(0);
expect(foo).toEqual(1);
expect(bar).toEqual(1);
expect(baz).toEqual(1);
@ -536,6 +555,8 @@ describe("jasmine spec running", function () {
expect(reachedFirstWaitsFor).toEqual(false);
waitsSuite.execute();
fakeTimer.tick(0);
expect(reachedFirstWaitsFor).toEqual(true);
expect(foo).toEqual(0);
expect(reachedSecondWaitsFor).toEqual(false);
@ -618,6 +639,7 @@ describe("jasmine spec running", function () {
expect(foo).toEqual(0);
expect(bar).toEqual(0);
suiteWithBefore.execute();
fakeTimer.tick(0);
expect(bar).toEqual(0);
expect(foo).toEqual(1);
@ -659,6 +681,8 @@ describe("jasmine spec running", function () {
expect(foo).toEqual(0);
suiteWithAfter.execute();
fakeTimer.tick(0);
expect(firstSpecHasRun).toEqual(true);
expect(secondSpecHasRun).toEqual(false);
@ -794,6 +818,7 @@ describe("jasmine spec running", function () {
});
suite.execute();
fakeTimer.tick(0);
expect(report).toEqual("firstsecond");
var suiteResults = suite.getResults();
@ -832,6 +857,7 @@ describe("jasmine spec running", function () {
});
suite.execute();
fakeTimer.tick(0);
expect(report).toEqual("firstsecondthird"); // "all tests should run");
//After each errors should not go in spec results because it confuses the count.
@ -898,6 +924,7 @@ describe("jasmine spec running", function () {
});
env.execute();
fakeTimer.tick(0);
var expected = [
@ -1048,6 +1075,7 @@ describe("jasmine spec running", function () {
});
suite.execute();
fakeTimer.tick(0);
expect(spec1Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: 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.running = false;
this.index = 0;
@ -37,13 +38,17 @@ jasmine.Queue.prototype.isRunning = function () {
jasmine.Queue.prototype._next = function () {
var self = this;
self.env.setTimeout(function () {
self.offset = 0;
self.index++;
if (self.index < self.blocks.length) {
self.blocks[self.index].execute(function () {self._next();});
self.blocks[self.index].execute(function () {
self._next();
});
} else {
self.finish();
}
}, 0);
};
jasmine.Queue.prototype.finish = function () {

View File

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

View File

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

View File

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