Refactor suite timing out of Env and into each Reporter
[finishes #45659879]
This commit is contained in:
@@ -73,8 +73,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
clearTimeout: env.clock.clearTimeout,
|
clearTimeout: env.clock.clearTimeout,
|
||||||
setInterval: env.clock.setInterval,
|
setInterval: env.clock.setInterval,
|
||||||
clearInterval: env.clock.clearInterval,
|
clearInterval: env.clock.clearInterval,
|
||||||
|
jsApiReporter: new jasmine.JsApiReporter({
|
||||||
jsApiReporter: new jasmine.JsApiReporter(jasmine)
|
timer: new jasmine.Timer()
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof window == "undefined" && typeof exports == "object") {
|
if (typeof window == "undefined" && typeof exports == "object") {
|
||||||
@@ -97,7 +98,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
|
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
|
||||||
getContainer: function() { return document.body; },
|
getContainer: function() { return document.body; },
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||||
|
timer: new jasmine.Timer()
|
||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter(jasmineInterface.jsApiReporter);
|
env.addReporter(jasmineInterface.jsApiReporter);
|
||||||
|
|||||||
@@ -51,8 +51,9 @@
|
|||||||
clearTimeout: env.clock.clearTimeout,
|
clearTimeout: env.clock.clearTimeout,
|
||||||
setInterval: env.clock.setInterval,
|
setInterval: env.clock.setInterval,
|
||||||
clearInterval: env.clock.clearInterval,
|
clearInterval: env.clock.clearInterval,
|
||||||
|
jsApiReporter: new jasmine.JsApiReporter({
|
||||||
jsApiReporter: new jasmine.JsApiReporter(jasmine)
|
timer: new jasmine.Timer()
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof window == "undefined" && typeof exports == "object") {
|
if (typeof window == "undefined" && typeof exports == "object") {
|
||||||
@@ -75,7 +76,8 @@
|
|||||||
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
|
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
|
||||||
getContainer: function() { return document.body; },
|
getContainer: function() { return document.body; },
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||||
|
timer: new jasmine.Timer()
|
||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter(jasmineInterface.jsApiReporter);
|
env.addReporter(jasmineInterface.jsApiReporter);
|
||||||
|
|||||||
@@ -27,12 +27,19 @@ jasmineRequire.html = function(j$) {
|
|||||||
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
||||||
};
|
};
|
||||||
jasmineRequire.HtmlReporter = function() {
|
jasmineRequire.HtmlReporter = function() {
|
||||||
|
|
||||||
|
var noopTimer = {
|
||||||
|
start: function(){},
|
||||||
|
elapsed: function(){ return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
function HtmlReporter(options) {
|
function HtmlReporter(options) {
|
||||||
var env = options.env || {},
|
var env = options.env || {},
|
||||||
getContainer = options.getContainer,
|
getContainer = options.getContainer,
|
||||||
createElement = options.createElement,
|
createElement = options.createElement,
|
||||||
createTextNode = options.createTextNode,
|
createTextNode = options.createTextNode,
|
||||||
onRaiseExceptionsClick = options.onRaiseExceptionsClick,
|
onRaiseExceptionsClick = options.onRaiseExceptionsClick,
|
||||||
|
timer = options.timer || noopTimer,
|
||||||
results = [],
|
results = [],
|
||||||
specsExecuted = 0,
|
specsExecuted = 0,
|
||||||
failureCount = 0,
|
failureCount = 0,
|
||||||
@@ -60,6 +67,7 @@ jasmineRequire.HtmlReporter = function() {
|
|||||||
var totalSpecsDefined;
|
var totalSpecsDefined;
|
||||||
this.jasmineStarted = function(options) {
|
this.jasmineStarted = function(options) {
|
||||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||||
|
timer.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
var summary = createDom("div", {className: "summary"});
|
var summary = createDom("div", {className: "summary"});
|
||||||
@@ -120,9 +128,9 @@ jasmineRequire.HtmlReporter = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.jasmineDone = function(options) {
|
this.jasmineDone = function() {
|
||||||
var banner = find(".banner");
|
var banner = find(".banner");
|
||||||
banner.appendChild(createDom("span", {className: "duration"}, "finished in " + options.executionTime / 1000 + "s"));
|
banner.appendChild(createDom("span", {className: "duration"}, "finished in " + timer.elapsed() / 1000 + "s"));
|
||||||
|
|
||||||
var alert = find(".alert");
|
var alert = find(".alert");
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ getJasmineRequireObj().core = function(jRequire) {
|
|||||||
j$.Spec = jRequire.Spec();
|
j$.Spec = jRequire.Spec();
|
||||||
j$.Spy = jRequire.Spy(j$);
|
j$.Spy = jRequire.Spy(j$);
|
||||||
j$.Suite = jRequire.Suite();
|
j$.Suite = jRequire.Suite();
|
||||||
|
j$.Timer = jRequire.Timer();
|
||||||
j$.version = jRequire.version();
|
j$.version = jRequire.version();
|
||||||
|
|
||||||
j$.matchers = jRequire.requireMatchers(jRequire, j$);
|
j$.matchers = jRequire.requireMatchers(jRequire, j$);
|
||||||
@@ -648,23 +649,30 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().JsApiReporter = function() {
|
getJasmineRequireObj().JsApiReporter = function() {
|
||||||
function JsApiReporter(jasmine) { // TODO: this doesn't appear to be used
|
|
||||||
this.jasmine = jasmine || {};
|
var noopTimer = {
|
||||||
|
start: function(){},
|
||||||
|
elapsed: function(){ return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
function JsApiReporter(options) {
|
||||||
|
var timer = options.timer || noopTimer,
|
||||||
|
status = "loaded";
|
||||||
|
|
||||||
this.started = false;
|
this.started = false;
|
||||||
this.finished = false;
|
this.finished = false;
|
||||||
|
|
||||||
var status = 'loaded';
|
|
||||||
|
|
||||||
this.jasmineStarted = function() {
|
this.jasmineStarted = function() {
|
||||||
this.started = true;
|
this.started = true;
|
||||||
status = 'started';
|
status = 'started';
|
||||||
|
timer.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
var executionTime;
|
var executionTime;
|
||||||
|
|
||||||
this.jasmineDone = function(options) {
|
this.jasmineDone = function() {
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
executionTime = options.executionTime;
|
executionTime = timer.elapsed();
|
||||||
status = 'done';
|
status = 'done';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1567,6 +1575,24 @@ if (typeof window == void 0 && typeof exports == "object") {
|
|||||||
exports.Suite = jasmineRequire.Suite;
|
exports.Suite = jasmineRequire.Suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getJasmineRequireObj().Timer = function() {
|
||||||
|
function Timer(options) {
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
var now = options.now || function() { return new Date().getTime(); },
|
||||||
|
startTime;
|
||||||
|
|
||||||
|
this.start = function() {
|
||||||
|
startTime = now();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.elapsed = function() {
|
||||||
|
return now() - startTime;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return Timer;
|
||||||
|
};
|
||||||
getJasmineRequireObj().matchersUtil = function(j$) {
|
getJasmineRequireObj().matchersUtil = function(j$) {
|
||||||
// TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter?
|
// TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter?
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,18 @@ describe("ConsoleReporter", function() {
|
|||||||
expect(out.getOutput()).toEqual("Started\n");
|
expect(out.getOutput()).toEqual("Started\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("starts the provided timer when jasmine starts", function() {
|
||||||
|
var timerSpy = jasmine.createSpyObj('timer', ['start']),
|
||||||
|
reporter = new j$.ConsoleReporter({
|
||||||
|
print: out.print,
|
||||||
|
timer: timerSpy
|
||||||
|
});
|
||||||
|
|
||||||
|
reporter.jasmineStarted();
|
||||||
|
|
||||||
|
expect(timerSpy.start).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("reports a passing spec as a dot", function() {
|
it("reports a passing spec as a dot", function() {
|
||||||
var reporter = new j$.ConsoleReporter({
|
var reporter = new j$.ConsoleReporter({
|
||||||
print: out.print
|
print: out.print
|
||||||
@@ -69,15 +81,19 @@ describe("ConsoleReporter", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a summary when done (singluar spec and time)", function() {
|
it("reports a summary when done (singluar spec and time)", function() {
|
||||||
var reporter = new j$.ConsoleReporter({
|
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
print: out.print,
|
reporter = new j$.ConsoleReporter({
|
||||||
});
|
print: out.print,
|
||||||
|
timer: timerSpy
|
||||||
|
});
|
||||||
|
|
||||||
reporter.jasmineStarted();
|
reporter.jasmineStarted();
|
||||||
reporter.specDone({status: "passed"});
|
reporter.specDone({status: "passed"});
|
||||||
|
|
||||||
|
timerSpy.elapsed.andReturn(1000);
|
||||||
|
|
||||||
out.clear();
|
out.clear();
|
||||||
reporter.jasmineDone({executionTime: 1000});
|
reporter.jasmineDone();
|
||||||
|
|
||||||
expect(out.getOutput()).toMatch(/1 spec, 0 failures/);
|
expect(out.getOutput()).toMatch(/1 spec, 0 failures/);
|
||||||
expect(out.getOutput()).not.toMatch(/0 pending specs/);
|
expect(out.getOutput()).not.toMatch(/0 pending specs/);
|
||||||
@@ -85,9 +101,11 @@ describe("ConsoleReporter", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports a summary when done (pluralized specs and seconds)", function() {
|
it("reports a summary when done (pluralized specs and seconds)", function() {
|
||||||
var reporter = new j$.ConsoleReporter({
|
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
print: out.print,
|
reporter = new j$.ConsoleReporter({
|
||||||
});
|
print: out.print,
|
||||||
|
timer: timerSpy
|
||||||
|
});
|
||||||
|
|
||||||
reporter.jasmineStarted();
|
reporter.jasmineStarted();
|
||||||
reporter.specDone({status: "passed"});
|
reporter.specDone({status: "passed"});
|
||||||
@@ -109,7 +127,9 @@ describe("ConsoleReporter", function() {
|
|||||||
|
|
||||||
out.clear();
|
out.clear();
|
||||||
|
|
||||||
reporter.jasmineDone({executionTime: 100});
|
timerSpy.elapsed.andReturn(100);
|
||||||
|
|
||||||
|
reporter.jasmineDone();
|
||||||
|
|
||||||
expect(out.getOutput()).toMatch(/3 specs, 1 failure, 1 pending spec/);
|
expect(out.getOutput()).toMatch(/3 specs, 1 failure, 1 pending spec/);
|
||||||
expect(out.getOutput()).toMatch("Finished in 0.1 seconds\n");
|
expect(out.getOutput()).toMatch("Finished in 0.1 seconds\n");
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ xdescribe('JsApiReporter (integration specs)', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
reporter = new j$.JsApiReporter(jasmine);
|
reporter = new j$.JsApiReporter({});
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
|
|
||||||
env.execute();
|
env.execute();
|
||||||
@@ -83,7 +83,7 @@ xdescribe('JsApiReporter (integration specs)', function() {
|
|||||||
describe("JsApiReporter", function() {
|
describe("JsApiReporter", function() {
|
||||||
|
|
||||||
it("knows when a full environment is started", function() {
|
it("knows when a full environment is started", function() {
|
||||||
var reporter = new j$.JsApiReporter();
|
var reporter = new j$.JsApiReporter({});
|
||||||
|
|
||||||
expect(reporter.started).toBe(false);
|
expect(reporter.started).toBe(false);
|
||||||
expect(reporter.finished).toBe(false);
|
expect(reporter.finished).toBe(false);
|
||||||
@@ -95,7 +95,7 @@ describe("JsApiReporter", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("knows when a full environment is done", function() {
|
it("knows when a full environment is done", function() {
|
||||||
var reporter = new j$.JsApiReporter();
|
var reporter = new j$.JsApiReporter({});
|
||||||
|
|
||||||
expect(reporter.started).toBe(false);
|
expect(reporter.started).toBe(false);
|
||||||
expect(reporter.finished).toBe(false);
|
expect(reporter.finished).toBe(false);
|
||||||
@@ -107,13 +107,13 @@ describe("JsApiReporter", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("defaults to 'loaded' status", function() {
|
it("defaults to 'loaded' status", function() {
|
||||||
var reporter = new j$.JsApiReporter();
|
var reporter = new j$.JsApiReporter({});
|
||||||
|
|
||||||
expect(reporter.status()).toEqual('loaded');
|
expect(reporter.status()).toEqual('loaded');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports 'started' when Jasmine has started", function() {
|
it("reports 'started' when Jasmine has started", function() {
|
||||||
var reporter = new j$.JsApiReporter();
|
var reporter = new j$.JsApiReporter({});
|
||||||
|
|
||||||
reporter.jasmineStarted();
|
reporter.jasmineStarted();
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ describe("JsApiReporter", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("reports 'done' when Jasmine is done", function() {
|
it("reports 'done' when Jasmine is done", function() {
|
||||||
var reporter = new j$.JsApiReporter();
|
var reporter = new j$.JsApiReporter({});
|
||||||
|
|
||||||
reporter.jasmineDone({});
|
reporter.jasmineDone({});
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ describe("JsApiReporter", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("tracks a suite", function() {
|
it("tracks a suite", function() {
|
||||||
var reporter = new j$.JsApiReporter();
|
var reporter = new j$.JsApiReporter({});
|
||||||
|
|
||||||
reporter.suiteStarted({
|
reporter.suiteStarted({
|
||||||
id: 123,
|
id: 123,
|
||||||
@@ -152,7 +152,7 @@ describe("JsApiReporter", function() {
|
|||||||
describe("#specResults", function() {
|
describe("#specResults", function() {
|
||||||
var reporter, specResult1, specResult2;
|
var reporter, specResult1, specResult2;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
reporter = new j$.JsApiReporter();
|
reporter = new j$.JsApiReporter({});
|
||||||
specResult1 = {
|
specResult1 = {
|
||||||
id: 1,
|
id: 1,
|
||||||
description: "A spec"
|
description: "A spec"
|
||||||
@@ -180,18 +180,34 @@ describe("JsApiReporter", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("#executionTime", function() {
|
describe("#executionTime", function() {
|
||||||
var reporter;
|
it("should start the timer when jasmine starts", function() {
|
||||||
beforeEach(function() {
|
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
reporter = new j$.JsApiReporter();
|
reporter = new j$.JsApiReporter({
|
||||||
|
timer: timerSpy
|
||||||
|
});
|
||||||
|
|
||||||
|
reporter.jasmineStarted();
|
||||||
|
expect(timerSpy.start).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return the time it took the specs to run, in ms", function() {
|
it("should return the time it took the specs to run, in ms", function() {
|
||||||
reporter.jasmineDone({executionTime: 1000});
|
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
|
reporter = new j$.JsApiReporter({
|
||||||
|
timer: timerSpy
|
||||||
|
});
|
||||||
|
|
||||||
|
timerSpy.elapsed.andReturn(1000);
|
||||||
|
reporter.jasmineDone();
|
||||||
expect(reporter.executionTime()).toEqual(1000);
|
expect(reporter.executionTime()).toEqual(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when the specs haven't finished being run", function() {
|
describe("when the specs haven't finished being run", function() {
|
||||||
it("should return undefined", function() {
|
it("should return undefined", function() {
|
||||||
|
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
|
reporter = new j$.JsApiReporter({
|
||||||
|
timer: timerSpy
|
||||||
|
});
|
||||||
|
|
||||||
expect(reporter.executionTime()).toBeUndefined();
|
expect(reporter.executionTime()).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
13
spec/core/TimerSpec.js
Normal file
13
spec/core/TimerSpec.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
describe("Timer", function() {
|
||||||
|
it("reports the time elapsed", function() {
|
||||||
|
var fakeNow = jasmine.createSpy('fake Date.now'),
|
||||||
|
timer = new j$.Timer({now: fakeNow});
|
||||||
|
|
||||||
|
fakeNow.andReturn(100);
|
||||||
|
timer.start();
|
||||||
|
|
||||||
|
fakeNow.andReturn(200);
|
||||||
|
|
||||||
|
expect(timer.elapsed()).toEqual(100);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -30,6 +30,20 @@ describe("New HtmlReporter", function() {
|
|||||||
expect(version.innerHTML).toEqual(jasmine.version);
|
expect(version.innerHTML).toEqual(jasmine.version);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("starts the timer when jasmine begins", function() {
|
||||||
|
var env = new jasmine.Env(),
|
||||||
|
startTimerSpy = jasmine.createSpy("start-timer-spy"),
|
||||||
|
reporter = new jasmine.HtmlReporter({
|
||||||
|
env: env,
|
||||||
|
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||||
|
timer: { start: startTimerSpy }
|
||||||
|
});
|
||||||
|
|
||||||
|
reporter.jasmineStarted({});
|
||||||
|
|
||||||
|
expect(startTimerSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
describe("when a spec is done", function() {
|
describe("when a spec is done", function() {
|
||||||
it("reports the status symbol of a disabled spec", function() {
|
it("reports the status symbol of a disabled spec", function() {
|
||||||
var env = new jasmine.Env(),
|
var env = new jasmine.Env(),
|
||||||
@@ -119,18 +133,22 @@ describe("New HtmlReporter", function() {
|
|||||||
it("reports the run time", function() {
|
it("reports the run time", function() {
|
||||||
var env = new jasmine.Env(),
|
var env = new jasmine.Env(),
|
||||||
container = document.createElement("div"),
|
container = document.createElement("div"),
|
||||||
|
timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||||
getContainer = function() { return container; },
|
getContainer = function() { return container; },
|
||||||
reporter = new jasmine.HtmlReporter({
|
reporter = new jasmine.HtmlReporter({
|
||||||
env: env,
|
env: env,
|
||||||
getContainer: getContainer,
|
getContainer: getContainer,
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||||
|
timer: timer
|
||||||
});
|
});
|
||||||
|
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
|
|
||||||
reporter.jasmineStarted({});
|
reporter.jasmineStarted({});
|
||||||
reporter.jasmineDone({executionTime: 100});
|
|
||||||
|
timer.elapsed.andReturn(100);
|
||||||
|
reporter.jasmineDone();
|
||||||
|
|
||||||
var duration = container.querySelector(".banner .duration");
|
var duration = container.querySelector(".banner .duration");
|
||||||
expect(duration.innerHTML).toMatch(/finished in 0.1s/);
|
expect(duration.innerHTML).toMatch(/finished in 0.1s/);
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ var jasmineInterface = {
|
|||||||
setInterval: env.clock.setInterval,
|
setInterval: env.clock.setInterval,
|
||||||
clearInterval: env.clock.clearInterval,
|
clearInterval: env.clock.clearInterval,
|
||||||
|
|
||||||
jsApiReporter: new jasmine.JsApiReporter(jasmine)
|
jsApiReporter: new jasmine.JsApiReporter({
|
||||||
|
timer: new jasmine.Timer()
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
extend(global, jasmineInterface);
|
extend(global, jasmineInterface);
|
||||||
@@ -78,7 +80,8 @@ function executeSpecs(specs, done, isVerbose, showColors) {
|
|||||||
var consoleReporter = new jasmine.ConsoleReporter({
|
var consoleReporter = new jasmine.ConsoleReporter({
|
||||||
print: util.print,
|
print: util.print,
|
||||||
onComplete: done,
|
onComplete: done,
|
||||||
showColors: showColors
|
showColors: showColors,
|
||||||
|
timer: new jasmine.Timer()
|
||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter(consoleReporter);
|
env.addReporter(consoleReporter);
|
||||||
|
|||||||
@@ -53,7 +53,9 @@
|
|||||||
setInterval: env.clock.setInterval,
|
setInterval: env.clock.setInterval,
|
||||||
clearInterval: env.clock.clearInterval,
|
clearInterval: env.clock.clearInterval,
|
||||||
|
|
||||||
jsApiReporter: new jasmine.JsApiReporter(jasmine)
|
jsApiReporter: new jasmine.JsApiReporter({
|
||||||
|
timer: new jasmine.Timer()
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof window == "undefined" && typeof exports == "object") {
|
if (typeof window == "undefined" && typeof exports == "object") {
|
||||||
@@ -76,7 +78,8 @@
|
|||||||
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
|
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
|
||||||
getContainer: function() { return document.body; },
|
getContainer: function() { return document.body; },
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||||
|
timer: new jasmine.Timer()
|
||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter(jasmineInterface.jsApiReporter);
|
env.addReporter(jasmineInterface.jsApiReporter);
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
getJasmineRequireObj().ConsoleReporter = function() {
|
getJasmineRequireObj().ConsoleReporter = function() {
|
||||||
|
|
||||||
|
var noopTimer = {
|
||||||
|
start: function(){},
|
||||||
|
elapsed: function(){ return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
function ConsoleReporter(options) {
|
function ConsoleReporter(options) {
|
||||||
var print = options.print,
|
var print = options.print,
|
||||||
showColors = options.showColors || false,
|
showColors = options.showColors || false,
|
||||||
onComplete = options.onComplete || function() {},
|
onComplete = options.onComplete || function() {},
|
||||||
|
timer = options.timer || noopTimer,
|
||||||
specCount,
|
specCount,
|
||||||
failureCount,
|
failureCount,
|
||||||
failedSpecs = [],
|
failedSpecs = [],
|
||||||
@@ -20,9 +27,10 @@ getJasmineRequireObj().ConsoleReporter = function() {
|
|||||||
pendingCount = 0;
|
pendingCount = 0;
|
||||||
print("Started");
|
print("Started");
|
||||||
printNewline();
|
printNewline();
|
||||||
|
timer.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.jasmineDone = function(options) {
|
this.jasmineDone = function() {
|
||||||
printNewline();
|
printNewline();
|
||||||
for (var i = 0; i < failedSpecs.length; i++) {
|
for (var i = 0; i < failedSpecs.length; i++) {
|
||||||
specFailureDetails(failedSpecs[i]);
|
specFailureDetails(failedSpecs[i]);
|
||||||
@@ -39,7 +47,7 @@ getJasmineRequireObj().ConsoleReporter = function() {
|
|||||||
print(specCounts);
|
print(specCounts);
|
||||||
|
|
||||||
printNewline();
|
printNewline();
|
||||||
var seconds = options.executionTime / 1000;
|
var seconds = timer.elapsed() / 1000;
|
||||||
print("Finished in " + seconds + " " + plural("second", seconds));
|
print("Finished in " + seconds + " " + plural("second", seconds));
|
||||||
|
|
||||||
printNewline();
|
printNewline();
|
||||||
|
|||||||
@@ -34,10 +34,17 @@ getJasmineRequireObj().console = function(jRequire, j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().ConsoleReporter = function() {
|
getJasmineRequireObj().ConsoleReporter = function() {
|
||||||
|
|
||||||
|
var noopTimer = {
|
||||||
|
start: function(){},
|
||||||
|
elapsed: function(){ return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
function ConsoleReporter(options) {
|
function ConsoleReporter(options) {
|
||||||
var print = options.print,
|
var print = options.print,
|
||||||
showColors = options.showColors || false,
|
showColors = options.showColors || false,
|
||||||
onComplete = options.onComplete || function() {},
|
onComplete = options.onComplete || function() {},
|
||||||
|
timer = options.timer || noopTimer,
|
||||||
specCount,
|
specCount,
|
||||||
failureCount,
|
failureCount,
|
||||||
failedSpecs = [],
|
failedSpecs = [],
|
||||||
@@ -55,9 +62,10 @@ getJasmineRequireObj().ConsoleReporter = function() {
|
|||||||
pendingCount = 0;
|
pendingCount = 0;
|
||||||
print("Started");
|
print("Started");
|
||||||
printNewline();
|
printNewline();
|
||||||
|
timer.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.jasmineDone = function(options) {
|
this.jasmineDone = function() {
|
||||||
printNewline();
|
printNewline();
|
||||||
for (var i = 0; i < failedSpecs.length; i++) {
|
for (var i = 0; i < failedSpecs.length; i++) {
|
||||||
specFailureDetails(failedSpecs[i]);
|
specFailureDetails(failedSpecs[i]);
|
||||||
@@ -74,7 +82,7 @@ getJasmineRequireObj().ConsoleReporter = function() {
|
|||||||
print(specCounts);
|
print(specCounts);
|
||||||
|
|
||||||
printNewline();
|
printNewline();
|
||||||
var seconds = options.executionTime / 1000;
|
var seconds = timer.elapsed() / 1000;
|
||||||
print("Finished in " + seconds + " " + plural("second", seconds));
|
print("Finished in " + seconds + " " + plural("second", seconds));
|
||||||
|
|
||||||
printNewline();
|
printNewline();
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
getJasmineRequireObj().JsApiReporter = function() {
|
getJasmineRequireObj().JsApiReporter = function() {
|
||||||
function JsApiReporter(jasmine) { // TODO: this doesn't appear to be used
|
|
||||||
this.jasmine = jasmine || {};
|
var noopTimer = {
|
||||||
|
start: function(){},
|
||||||
|
elapsed: function(){ return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
function JsApiReporter(options) {
|
||||||
|
var timer = options.timer || noopTimer,
|
||||||
|
status = "loaded";
|
||||||
|
|
||||||
this.started = false;
|
this.started = false;
|
||||||
this.finished = false;
|
this.finished = false;
|
||||||
|
|
||||||
var status = 'loaded';
|
|
||||||
|
|
||||||
this.jasmineStarted = function() {
|
this.jasmineStarted = function() {
|
||||||
this.started = true;
|
this.started = true;
|
||||||
status = 'started';
|
status = 'started';
|
||||||
|
timer.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
var executionTime;
|
var executionTime;
|
||||||
|
|
||||||
this.jasmineDone = function(options) {
|
this.jasmineDone = function() {
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
executionTime = options.executionTime;
|
executionTime = timer.elapsed();
|
||||||
status = 'done';
|
status = 'done';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
18
src/core/Timer.js
Normal file
18
src/core/Timer.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
getJasmineRequireObj().Timer = function() {
|
||||||
|
function Timer(options) {
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
var now = options.now || function() { return new Date().getTime(); },
|
||||||
|
startTime;
|
||||||
|
|
||||||
|
this.start = function() {
|
||||||
|
startTime = now();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.elapsed = function() {
|
||||||
|
return now() - startTime;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return Timer;
|
||||||
|
};
|
||||||
@@ -28,6 +28,7 @@ getJasmineRequireObj().core = function(jRequire) {
|
|||||||
j$.Spec = jRequire.Spec();
|
j$.Spec = jRequire.Spec();
|
||||||
j$.Spy = jRequire.Spy(j$);
|
j$.Spy = jRequire.Spy(j$);
|
||||||
j$.Suite = jRequire.Suite();
|
j$.Suite = jRequire.Suite();
|
||||||
|
j$.Timer = jRequire.Timer();
|
||||||
j$.version = jRequire.version();
|
j$.version = jRequire.version();
|
||||||
|
|
||||||
j$.matchers = jRequire.requireMatchers(jRequire, j$);
|
j$.matchers = jRequire.requireMatchers(jRequire, j$);
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
jasmineRequire.HtmlReporter = function() {
|
jasmineRequire.HtmlReporter = function() {
|
||||||
|
|
||||||
|
var noopTimer = {
|
||||||
|
start: function(){},
|
||||||
|
elapsed: function(){ return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
function HtmlReporter(options) {
|
function HtmlReporter(options) {
|
||||||
var env = options.env || {},
|
var env = options.env || {},
|
||||||
getContainer = options.getContainer,
|
getContainer = options.getContainer,
|
||||||
createElement = options.createElement,
|
createElement = options.createElement,
|
||||||
createTextNode = options.createTextNode,
|
createTextNode = options.createTextNode,
|
||||||
onRaiseExceptionsClick = options.onRaiseExceptionsClick,
|
onRaiseExceptionsClick = options.onRaiseExceptionsClick,
|
||||||
|
timer = options.timer || noopTimer,
|
||||||
results = [],
|
results = [],
|
||||||
specsExecuted = 0,
|
specsExecuted = 0,
|
||||||
failureCount = 0,
|
failureCount = 0,
|
||||||
@@ -32,6 +39,7 @@ jasmineRequire.HtmlReporter = function() {
|
|||||||
var totalSpecsDefined;
|
var totalSpecsDefined;
|
||||||
this.jasmineStarted = function(options) {
|
this.jasmineStarted = function(options) {
|
||||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||||
|
timer.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
var summary = createDom("div", {className: "summary"});
|
var summary = createDom("div", {className: "summary"});
|
||||||
@@ -92,9 +100,9 @@ jasmineRequire.HtmlReporter = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.jasmineDone = function(options) {
|
this.jasmineDone = function() {
|
||||||
var banner = find(".banner");
|
var banner = find(".banner");
|
||||||
banner.appendChild(createDom("span", {className: "duration"}, "finished in " + options.executionTime / 1000 + "s"));
|
banner.appendChild(createDom("span", {className: "duration"}, "finished in " + timer.elapsed() / 1000 + "s"));
|
||||||
|
|
||||||
var alert = find(".alert");
|
var alert = find(".alert");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user