Allow Env to take optional spec/suite ids when asked to execute
This commit is contained in:
@@ -381,6 +381,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
var realClearTimeout = j$.getGlobal().clearTimeout;
|
var realClearTimeout = j$.getGlobal().clearTimeout;
|
||||||
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler());
|
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler());
|
||||||
|
|
||||||
|
var runnableLookupTable = {};
|
||||||
|
|
||||||
var spies = [];
|
var spies = [];
|
||||||
|
|
||||||
this.currentSpec = null;
|
this.currentSpec = null;
|
||||||
@@ -518,6 +520,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
timer: {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}
|
timer: {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
runnableLookupTable[spec.id] = spec;
|
||||||
|
|
||||||
if (!self.specFilter(spec)) {
|
if (!self.specFilter(spec)) {
|
||||||
spec.disable();
|
spec.disable();
|
||||||
}
|
}
|
||||||
@@ -556,10 +560,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
completeCallback: function() {}, // TODO - hook this up
|
completeCallback: function() {}, // TODO - hook this up
|
||||||
resultCallback: function() {} // TODO - hook this up
|
resultCallback: function() {} // TODO - hook this up
|
||||||
});
|
});
|
||||||
|
runnableLookupTable[this.topSuite.id] = this.topSuite;
|
||||||
this.currentSuite = this.topSuite;
|
this.currentSuite = this.topSuite;
|
||||||
|
|
||||||
this.suiteFactory = function(description) {
|
this.suiteFactory = function(description) {
|
||||||
return new suiteConstructor({
|
var suite = new suiteConstructor({
|
||||||
env: self,
|
env: self,
|
||||||
id: self.nextSuiteId(),
|
id: self.nextSuiteId(),
|
||||||
description: description,
|
description: description,
|
||||||
@@ -570,13 +575,25 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
self.reporter.suiteDone(attrs);
|
self.reporter.suiteDone(attrs);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
runnableLookupTable[suite.id] = suite;
|
||||||
|
return suite;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.execute = function() {
|
this.execute = function(runnablesToRun) {
|
||||||
|
runnablesToRun = runnablesToRun || [this.topSuite.id];
|
||||||
|
|
||||||
|
var allFns = [];
|
||||||
|
for(var i = 0; i < runnablesToRun.length; i++) {
|
||||||
|
var runnable = runnableLookupTable[runnablesToRun[i]];
|
||||||
|
allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable));
|
||||||
|
}
|
||||||
|
|
||||||
this.reporter.jasmineStarted({
|
this.reporter.jasmineStarted({
|
||||||
totalSpecsDefined: totalSpecsDefined
|
totalSpecsDefined: totalSpecsDefined
|
||||||
});
|
});
|
||||||
this.topSuite.execute(self.reporter.jasmineDone);
|
|
||||||
|
queueRunnerFactory({fns: allFns, onComplete: this.reporter.jasmineDone});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOn = function(obj, methodName) {
|
this.spyOn = function(obj, methodName) {
|
||||||
|
|||||||
@@ -300,6 +300,42 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Allows specifying which specs and suites to run", function(done) {
|
||||||
|
var env = new j$.Env(),
|
||||||
|
calls = [],
|
||||||
|
suiteCallback = jasmine.createSpy('suite callback'),
|
||||||
|
firstSpec,
|
||||||
|
secondSuite;
|
||||||
|
|
||||||
|
var assertions = function() {
|
||||||
|
expect(calls).toEqual([
|
||||||
|
'third spec',
|
||||||
|
'first spec'
|
||||||
|
]);
|
||||||
|
expect(suiteCallback).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
|
env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback});
|
||||||
|
|
||||||
|
env.describe("first suite", function() {
|
||||||
|
firstSpec = env.it("first spec", function() {
|
||||||
|
calls.push('first spec');
|
||||||
|
});
|
||||||
|
env.it("second spec", function() {
|
||||||
|
calls.push('second spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
secondSuite = env.describe("second suite", function() {
|
||||||
|
env.it("third spec", function() {
|
||||||
|
calls.push('third spec');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute([secondSuite.id, firstSpec.id]);
|
||||||
|
});
|
||||||
|
|
||||||
it("Mock clock can be installed and used in tests", function(done) {
|
it("Mock clock can be installed and used in tests", function(done) {
|
||||||
var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
|
var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
|
||||||
delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
|
delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
var realClearTimeout = j$.getGlobal().clearTimeout;
|
var realClearTimeout = j$.getGlobal().clearTimeout;
|
||||||
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler());
|
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler());
|
||||||
|
|
||||||
|
var runnableLookupTable = {};
|
||||||
|
|
||||||
var spies = [];
|
var spies = [];
|
||||||
|
|
||||||
this.currentSpec = null;
|
this.currentSpec = null;
|
||||||
@@ -148,6 +150,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
timer: {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}
|
timer: {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
runnableLookupTable[spec.id] = spec;
|
||||||
|
|
||||||
if (!self.specFilter(spec)) {
|
if (!self.specFilter(spec)) {
|
||||||
spec.disable();
|
spec.disable();
|
||||||
}
|
}
|
||||||
@@ -186,10 +190,11 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
completeCallback: function() {}, // TODO - hook this up
|
completeCallback: function() {}, // TODO - hook this up
|
||||||
resultCallback: function() {} // TODO - hook this up
|
resultCallback: function() {} // TODO - hook this up
|
||||||
});
|
});
|
||||||
|
runnableLookupTable[this.topSuite.id] = this.topSuite;
|
||||||
this.currentSuite = this.topSuite;
|
this.currentSuite = this.topSuite;
|
||||||
|
|
||||||
this.suiteFactory = function(description) {
|
this.suiteFactory = function(description) {
|
||||||
return new suiteConstructor({
|
var suite = new suiteConstructor({
|
||||||
env: self,
|
env: self,
|
||||||
id: self.nextSuiteId(),
|
id: self.nextSuiteId(),
|
||||||
description: description,
|
description: description,
|
||||||
@@ -200,13 +205,25 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
self.reporter.suiteDone(attrs);
|
self.reporter.suiteDone(attrs);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
runnableLookupTable[suite.id] = suite;
|
||||||
|
return suite;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.execute = function() {
|
this.execute = function(runnablesToRun) {
|
||||||
|
runnablesToRun = runnablesToRun || [this.topSuite.id];
|
||||||
|
|
||||||
|
var allFns = [];
|
||||||
|
for(var i = 0; i < runnablesToRun.length; i++) {
|
||||||
|
var runnable = runnableLookupTable[runnablesToRun[i]];
|
||||||
|
allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable));
|
||||||
|
}
|
||||||
|
|
||||||
this.reporter.jasmineStarted({
|
this.reporter.jasmineStarted({
|
||||||
totalSpecsDefined: totalSpecsDefined
|
totalSpecsDefined: totalSpecsDefined
|
||||||
});
|
});
|
||||||
this.topSuite.execute(self.reporter.jasmineDone);
|
|
||||||
|
queueRunnerFactory({fns: allFns, onComplete: this.reporter.jasmineDone});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.spyOn = function(obj, methodName) {
|
this.spyOn = function(obj, methodName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user