Add reportRunnerStarting callback to reporters.
This commit is contained in:
parent
e1408a9f58
commit
f451e633cb
334
lib/jasmine.js
334
lib/jasmine.js
@ -852,6 +852,10 @@ jasmine.ActionCollection.prototype.waitForDone = function(action) {
|
|||||||
jasmine.Reporter = function() {
|
jasmine.Reporter = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//noinspection JSUnusedLocalSymbols
|
||||||
|
jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
|
||||||
|
};
|
||||||
|
|
||||||
//noinspection JSUnusedLocalSymbols
|
//noinspection JSUnusedLocalSymbols
|
||||||
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
|
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
|
||||||
};
|
};
|
||||||
@ -1140,164 +1144,164 @@ jasmine.Matchers.Any.prototype.toString = function() {
|
|||||||
return '<jasmine.any(' + this.expectedClass + ')>';
|
return '<jasmine.any(' + this.expectedClass + ')>';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock setTimeout, clearTimeout
|
// Mock setTimeout, clearTimeout
|
||||||
// Contributed by Pivotal Computer Systems, www.pivotalsf.com
|
// Contributed by Pivotal Computer Systems, www.pivotalsf.com
|
||||||
|
|
||||||
jasmine.FakeTimer = function() {
|
jasmine.FakeTimer = function() {
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
self.setTimeout = function(funcToCall, millis) {
|
self.setTimeout = function(funcToCall, millis) {
|
||||||
self.timeoutsMade++;
|
self.timeoutsMade++;
|
||||||
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
|
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
|
||||||
return self.timeoutsMade;
|
return self.timeoutsMade;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.setInterval = function(funcToCall, millis) {
|
self.setInterval = function(funcToCall, millis) {
|
||||||
self.timeoutsMade++;
|
self.timeoutsMade++;
|
||||||
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
|
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
|
||||||
return self.timeoutsMade;
|
return self.timeoutsMade;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.clearTimeout = function(timeoutKey) {
|
self.clearTimeout = function(timeoutKey) {
|
||||||
self.scheduledFunctions[timeoutKey] = undefined;
|
self.scheduledFunctions[timeoutKey] = undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.clearInterval = function(timeoutKey) {
|
self.clearInterval = function(timeoutKey) {
|
||||||
self.scheduledFunctions[timeoutKey] = undefined;
|
self.scheduledFunctions[timeoutKey] = undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.FakeTimer.prototype.reset = function() {
|
jasmine.FakeTimer.prototype.reset = function() {
|
||||||
this.timeoutsMade = 0;
|
this.timeoutsMade = 0;
|
||||||
this.scheduledFunctions = {};
|
this.scheduledFunctions = {};
|
||||||
this.nowMillis = 0;
|
this.nowMillis = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.FakeTimer.prototype.tick = function(millis) {
|
jasmine.FakeTimer.prototype.tick = function(millis) {
|
||||||
var oldMillis = this.nowMillis;
|
var oldMillis = this.nowMillis;
|
||||||
var newMillis = oldMillis + millis;
|
var newMillis = oldMillis + millis;
|
||||||
this.runFunctionsWithinRange(oldMillis, newMillis);
|
this.runFunctionsWithinRange(oldMillis, newMillis);
|
||||||
this.nowMillis = newMillis;
|
this.nowMillis = newMillis;
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
|
jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
|
||||||
var scheduledFunc;
|
var scheduledFunc;
|
||||||
var funcsToRun = [];
|
var funcsToRun = [];
|
||||||
for (var timeoutKey in this.scheduledFunctions) {
|
for (var timeoutKey in this.scheduledFunctions) {
|
||||||
scheduledFunc = this.scheduledFunctions[timeoutKey];
|
scheduledFunc = this.scheduledFunctions[timeoutKey];
|
||||||
if (scheduledFunc != undefined &&
|
if (scheduledFunc != undefined &&
|
||||||
scheduledFunc.runAtMillis >= oldMillis &&
|
scheduledFunc.runAtMillis >= oldMillis &&
|
||||||
scheduledFunc.runAtMillis <= nowMillis) {
|
scheduledFunc.runAtMillis <= nowMillis) {
|
||||||
funcsToRun.push(scheduledFunc);
|
funcsToRun.push(scheduledFunc);
|
||||||
this.scheduledFunctions[timeoutKey] = undefined;
|
this.scheduledFunctions[timeoutKey] = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (funcsToRun.length > 0) {
|
if (funcsToRun.length > 0) {
|
||||||
funcsToRun.sort(function(a, b) {
|
funcsToRun.sort(function(a, b) {
|
||||||
return a.runAtMillis - b.runAtMillis;
|
return a.runAtMillis - b.runAtMillis;
|
||||||
});
|
});
|
||||||
for (var i = 0; i < funcsToRun.length; ++i) {
|
for (var i = 0; i < funcsToRun.length; ++i) {
|
||||||
try {
|
try {
|
||||||
var funcToRun = funcsToRun[i];
|
var funcToRun = funcsToRun[i];
|
||||||
this.nowMillis = funcToRun.runAtMillis;
|
this.nowMillis = funcToRun.runAtMillis;
|
||||||
funcToRun.funcToCall();
|
funcToRun.funcToCall();
|
||||||
if (funcToRun.recurring) {
|
if (funcToRun.recurring) {
|
||||||
this.scheduleFunction(funcToRun.timeoutKey,
|
this.scheduleFunction(funcToRun.timeoutKey,
|
||||||
funcToRun.funcToCall,
|
funcToRun.funcToCall,
|
||||||
funcToRun.millis,
|
funcToRun.millis,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.runFunctionsWithinRange(oldMillis, nowMillis);
|
this.runFunctionsWithinRange(oldMillis, nowMillis);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
|
jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
|
||||||
this.scheduledFunctions[timeoutKey] = {
|
this.scheduledFunctions[timeoutKey] = {
|
||||||
runAtMillis: this.nowMillis + millis,
|
runAtMillis: this.nowMillis + millis,
|
||||||
funcToCall: funcToCall,
|
funcToCall: funcToCall,
|
||||||
recurring: recurring,
|
recurring: recurring,
|
||||||
timeoutKey: timeoutKey,
|
timeoutKey: timeoutKey,
|
||||||
millis: millis
|
millis: millis
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
jasmine.Clock = {
|
jasmine.Clock = {
|
||||||
defaultFakeTimer: new jasmine.FakeTimer(),
|
defaultFakeTimer: new jasmine.FakeTimer(),
|
||||||
|
|
||||||
reset: function() {
|
reset: function() {
|
||||||
jasmine.Clock.assertInstalled();
|
jasmine.Clock.assertInstalled();
|
||||||
jasmine.Clock.defaultFakeTimer.reset();
|
jasmine.Clock.defaultFakeTimer.reset();
|
||||||
},
|
},
|
||||||
|
|
||||||
tick: function(millis) {
|
tick: function(millis) {
|
||||||
jasmine.Clock.assertInstalled();
|
jasmine.Clock.assertInstalled();
|
||||||
jasmine.Clock.defaultFakeTimer.tick(millis);
|
jasmine.Clock.defaultFakeTimer.tick(millis);
|
||||||
},
|
},
|
||||||
|
|
||||||
runFunctionsWithinRange: function(oldMillis, nowMillis) {
|
runFunctionsWithinRange: function(oldMillis, nowMillis) {
|
||||||
jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
|
jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
|
||||||
},
|
},
|
||||||
|
|
||||||
scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
|
scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
|
||||||
jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
|
jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
|
||||||
},
|
},
|
||||||
|
|
||||||
useMock: function() {
|
useMock: function() {
|
||||||
var spec = jasmine.getEnv().currentSpec;
|
var spec = jasmine.getEnv().currentSpec;
|
||||||
spec.after(jasmine.Clock.uninstallMock);
|
spec.after(jasmine.Clock.uninstallMock);
|
||||||
|
|
||||||
jasmine.Clock.installMock();
|
jasmine.Clock.installMock();
|
||||||
},
|
},
|
||||||
|
|
||||||
installMock: function() {
|
installMock: function() {
|
||||||
jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
|
jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
|
||||||
},
|
},
|
||||||
|
|
||||||
uninstallMock: function() {
|
uninstallMock: function() {
|
||||||
jasmine.Clock.assertInstalled();
|
jasmine.Clock.assertInstalled();
|
||||||
jasmine.Clock.installed = jasmine.Clock.real;
|
jasmine.Clock.installed = jasmine.Clock.real;
|
||||||
},
|
},
|
||||||
|
|
||||||
real: {
|
real: {
|
||||||
setTimeout: window.setTimeout,
|
setTimeout: window.setTimeout,
|
||||||
clearTimeout: window.clearTimeout,
|
clearTimeout: window.clearTimeout,
|
||||||
setInterval: window.setInterval,
|
setInterval: window.setInterval,
|
||||||
clearInterval: window.clearInterval
|
clearInterval: window.clearInterval
|
||||||
},
|
},
|
||||||
|
|
||||||
assertInstalled: function() {
|
assertInstalled: function() {
|
||||||
if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) {
|
if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) {
|
||||||
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
|
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
installed: null
|
installed: null
|
||||||
};
|
};
|
||||||
jasmine.Clock.installed = jasmine.Clock.real;
|
jasmine.Clock.installed = jasmine.Clock.real;
|
||||||
|
|
||||||
window.setTimeout = function(funcToCall, millis) {
|
window.setTimeout = function(funcToCall, millis) {
|
||||||
return jasmine.Clock.installed.setTimeout.apply(this, arguments);
|
return jasmine.Clock.installed.setTimeout.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.setInterval = function(funcToCall, millis) {
|
window.setInterval = function(funcToCall, millis) {
|
||||||
return jasmine.Clock.installed.setInterval.apply(this, arguments);
|
return jasmine.Clock.installed.setInterval.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.clearTimeout = function(timeoutKey) {
|
window.clearTimeout = function(timeoutKey) {
|
||||||
return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
|
return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.clearInterval = function(timeoutKey) {
|
window.clearInterval = function(timeoutKey) {
|
||||||
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
|
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
@ -1311,13 +1315,16 @@ jasmine.MultiReporter.prototype.addReporter = function(reporter) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var functionNames = ["reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"];
|
var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"];
|
||||||
for (var i = 0; i < functionNames.length; i++) {
|
for (var i = 0; i < functionNames.length; i++) {
|
||||||
var functionName = functionNames[i];
|
var functionName = functionNames[i];
|
||||||
jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
|
jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
|
||||||
return function() {
|
return function() {
|
||||||
for (var j = 0; j < this.subReporters_.length; j++) {
|
for (var j = 0; j < this.subReporters_.length; j++) {
|
||||||
this.subReporters_[j][functionName].apply(this.subReporters_[j], arguments);
|
var subReporter = this.subReporters_[j];
|
||||||
|
if (subReporter[functionName]) {
|
||||||
|
subReporter[functionName].apply(subReporter, arguments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(functionName);
|
})(functionName);
|
||||||
@ -1648,6 +1655,13 @@ jasmine.Runner = function(env) {
|
|||||||
};
|
};
|
||||||
jasmine.util.inherit(jasmine.Runner, jasmine.ActionCollection);
|
jasmine.util.inherit(jasmine.Runner, jasmine.ActionCollection);
|
||||||
|
|
||||||
|
jasmine.Runner.prototype.execute = function() {
|
||||||
|
if (this.env.reporter.reportRunnerStarting) {
|
||||||
|
this.env.reporter.reportRunnerStarting(this);
|
||||||
|
}
|
||||||
|
jasmine.ActionCollection.prototype.execute.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
jasmine.Runner.prototype.finishCallback = function() {
|
jasmine.Runner.prototype.finishCallback = function() {
|
||||||
this.env.reporter.reportRunnerResults(this);
|
this.env.reporter.reportRunnerResults(this);
|
||||||
};
|
};
|
||||||
|
@ -13,9 +13,5 @@ describe("jasmine.Env", function() {
|
|||||||
env.reporter.log("message");
|
env.reporter.log("message");
|
||||||
expect(fakeReporter.log).wasCalledWith("message");
|
expect(fakeReporter.log).wasCalledWith("message");
|
||||||
});
|
});
|
||||||
|
|
||||||
xit("should report when the tests start running", function() {
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -1,13 +1,30 @@
|
|||||||
describe("jasmine.MultiReporter", function() {
|
describe("jasmine.MultiReporter", function() {
|
||||||
it("should delegate to any and all subreporters", function() {
|
var multiReporter, fakeReporter1, fakeReporter2;
|
||||||
var multiReporter = new jasmine.MultiReporter();
|
|
||||||
var fakeReporter1 = jasmine.createSpyObj("fakeReporter1", ["reportSpecResults"]);
|
beforeEach(function() {
|
||||||
var fakeReporter2 = jasmine.createSpyObj("fakeReporter2", ["reportSpecResults"]);
|
multiReporter = new jasmine.MultiReporter();
|
||||||
|
fakeReporter1 = jasmine.createSpyObj("fakeReporter1", ["reportSpecResults"]);
|
||||||
|
fakeReporter2 = jasmine.createSpyObj("fakeReporter2", ["reportSpecResults", "reportRunnerStarting"]);
|
||||||
multiReporter.addReporter(fakeReporter1);
|
multiReporter.addReporter(fakeReporter1);
|
||||||
multiReporter.addReporter(fakeReporter2);
|
multiReporter.addReporter(fakeReporter2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should support all the method calls that jasmine.Reporter supports", function() {
|
||||||
|
multiReporter.reportRunnerStarting();
|
||||||
|
multiReporter.reportRunnerResults();
|
||||||
|
multiReporter.reportSuiteResults();
|
||||||
|
multiReporter.reportSpecResults();
|
||||||
|
multiReporter.log();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should delegate to any and all subreporters", function() {
|
||||||
multiReporter.reportSpecResults('blah', 'foo');
|
multiReporter.reportSpecResults('blah', 'foo');
|
||||||
expect(fakeReporter1.reportSpecResults).wasCalledWith('blah', 'foo');
|
expect(fakeReporter1.reportSpecResults).wasCalledWith('blah', 'foo');
|
||||||
expect(fakeReporter2.reportSpecResults).wasCalledWith('blah', 'foo');
|
expect(fakeReporter2.reportSpecResults).wasCalledWith('blah', 'foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should quietly skip delegating to any subreporters which lack the given method", function() {
|
||||||
|
multiReporter.reportRunnerStarting('blah', 'foo');
|
||||||
|
expect(fakeReporter2.reportRunnerStarting).wasCalledWith('blah', 'foo');
|
||||||
|
});
|
||||||
});
|
});
|
@ -114,4 +114,13 @@ describe('RunnerTest', function() {
|
|||||||
expect(foo).toEqual(1);
|
expect(foo).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should report when the tests start running", function() {
|
||||||
|
var fakeReporter = jasmine.createSpyObj("fakeReporter", ["log", "reportRunnerStarting"]);
|
||||||
|
env.addReporter(fakeReporter);
|
||||||
|
|
||||||
|
var runner = new jasmine.Runner(env);
|
||||||
|
runner.execute();
|
||||||
|
expect(fakeReporter.reportRunnerStarting).wasCalledWith(env.currentRunner);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
@ -11,13 +11,16 @@ jasmine.MultiReporter.prototype.addReporter = function(reporter) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var functionNames = ["reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"];
|
var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"];
|
||||||
for (var i = 0; i < functionNames.length; i++) {
|
for (var i = 0; i < functionNames.length; i++) {
|
||||||
var functionName = functionNames[i];
|
var functionName = functionNames[i];
|
||||||
jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
|
jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
|
||||||
return function() {
|
return function() {
|
||||||
for (var j = 0; j < this.subReporters_.length; j++) {
|
for (var j = 0; j < this.subReporters_.length; j++) {
|
||||||
this.subReporters_[j][functionName].apply(this.subReporters_[j], arguments);
|
var subReporter = this.subReporters_[j];
|
||||||
|
if (subReporter[functionName]) {
|
||||||
|
subReporter[functionName].apply(subReporter, arguments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(functionName);
|
})(functionName);
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
jasmine.Reporter = function() {
|
jasmine.Reporter = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//noinspection JSUnusedLocalSymbols
|
||||||
|
jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
|
||||||
|
};
|
||||||
|
|
||||||
//noinspection JSUnusedLocalSymbols
|
//noinspection JSUnusedLocalSymbols
|
||||||
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
|
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,13 @@ jasmine.Runner = function(env) {
|
|||||||
};
|
};
|
||||||
jasmine.util.inherit(jasmine.Runner, jasmine.ActionCollection);
|
jasmine.util.inherit(jasmine.Runner, jasmine.ActionCollection);
|
||||||
|
|
||||||
|
jasmine.Runner.prototype.execute = function() {
|
||||||
|
if (this.env.reporter.reportRunnerStarting) {
|
||||||
|
this.env.reporter.reportRunnerStarting(this);
|
||||||
|
}
|
||||||
|
jasmine.ActionCollection.prototype.execute.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
jasmine.Runner.prototype.finishCallback = function() {
|
jasmine.Runner.prototype.finishCallback = function() {
|
||||||
this.env.reporter.reportRunnerResults(this);
|
this.env.reporter.reportRunnerResults(this);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user