Refactor suite timing out of Env and into each Reporter
[finishes #45659879]
This commit is contained in:
@@ -28,6 +28,18 @@ describe("ConsoleReporter", function() {
|
||||
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() {
|
||||
var reporter = new j$.ConsoleReporter({
|
||||
print: out.print
|
||||
@@ -69,15 +81,19 @@ describe("ConsoleReporter", function() {
|
||||
});
|
||||
|
||||
it("reports a summary when done (singluar spec and time)", function() {
|
||||
var reporter = new j$.ConsoleReporter({
|
||||
print: out.print,
|
||||
});
|
||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
reporter = new j$.ConsoleReporter({
|
||||
print: out.print,
|
||||
timer: timerSpy
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
reporter.specDone({status: "passed"});
|
||||
|
||||
timerSpy.elapsed.andReturn(1000);
|
||||
|
||||
out.clear();
|
||||
reporter.jasmineDone({executionTime: 1000});
|
||||
reporter.jasmineDone();
|
||||
|
||||
expect(out.getOutput()).toMatch(/1 spec, 0 failures/);
|
||||
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() {
|
||||
var reporter = new j$.ConsoleReporter({
|
||||
print: out.print,
|
||||
});
|
||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
reporter = new j$.ConsoleReporter({
|
||||
print: out.print,
|
||||
timer: timerSpy
|
||||
});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
reporter.specDone({status: "passed"});
|
||||
@@ -109,7 +127,9 @@ describe("ConsoleReporter", function() {
|
||||
|
||||
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("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.execute();
|
||||
@@ -83,7 +83,7 @@ xdescribe('JsApiReporter (integration specs)', function() {
|
||||
describe("JsApiReporter", 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.finished).toBe(false);
|
||||
@@ -95,7 +95,7 @@ describe("JsApiReporter", 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.finished).toBe(false);
|
||||
@@ -107,13 +107,13 @@ describe("JsApiReporter", function() {
|
||||
});
|
||||
|
||||
it("defaults to 'loaded' status", function() {
|
||||
var reporter = new j$.JsApiReporter();
|
||||
var reporter = new j$.JsApiReporter({});
|
||||
|
||||
expect(reporter.status()).toEqual('loaded');
|
||||
});
|
||||
|
||||
it("reports 'started' when Jasmine has started", function() {
|
||||
var reporter = new j$.JsApiReporter();
|
||||
var reporter = new j$.JsApiReporter({});
|
||||
|
||||
reporter.jasmineStarted();
|
||||
|
||||
@@ -121,7 +121,7 @@ describe("JsApiReporter", function() {
|
||||
});
|
||||
|
||||
it("reports 'done' when Jasmine is done", function() {
|
||||
var reporter = new j$.JsApiReporter();
|
||||
var reporter = new j$.JsApiReporter({});
|
||||
|
||||
reporter.jasmineDone({});
|
||||
|
||||
@@ -129,7 +129,7 @@ describe("JsApiReporter", function() {
|
||||
});
|
||||
|
||||
it("tracks a suite", function() {
|
||||
var reporter = new j$.JsApiReporter();
|
||||
var reporter = new j$.JsApiReporter({});
|
||||
|
||||
reporter.suiteStarted({
|
||||
id: 123,
|
||||
@@ -152,7 +152,7 @@ describe("JsApiReporter", function() {
|
||||
describe("#specResults", function() {
|
||||
var reporter, specResult1, specResult2;
|
||||
beforeEach(function() {
|
||||
reporter = new j$.JsApiReporter();
|
||||
reporter = new j$.JsApiReporter({});
|
||||
specResult1 = {
|
||||
id: 1,
|
||||
description: "A spec"
|
||||
@@ -180,18 +180,34 @@ describe("JsApiReporter", function() {
|
||||
});
|
||||
|
||||
describe("#executionTime", function() {
|
||||
var reporter;
|
||||
beforeEach(function() {
|
||||
reporter = new j$.JsApiReporter();
|
||||
it("should start the timer when jasmine starts", function() {
|
||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
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() {
|
||||
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);
|
||||
});
|
||||
|
||||
describe("when the specs haven't finished being run", function() {
|
||||
it("should return undefined", function() {
|
||||
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
reporter = new j$.JsApiReporter({
|
||||
timer: timerSpy
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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() {
|
||||
it("reports the status symbol of a disabled spec", function() {
|
||||
var env = new jasmine.Env(),
|
||||
@@ -119,18 +133,22 @@ describe("New HtmlReporter", function() {
|
||||
it("reports the run time", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
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.jasmineStarted({});
|
||||
reporter.jasmineDone({executionTime: 100});
|
||||
|
||||
timer.elapsed.andReturn(100);
|
||||
reporter.jasmineDone();
|
||||
|
||||
var duration = container.querySelector(".banner .duration");
|
||||
expect(duration.innerHTML).toMatch(/finished in 0.1s/);
|
||||
|
||||
@@ -55,7 +55,9 @@ var jasmineInterface = {
|
||||
setInterval: env.clock.setInterval,
|
||||
clearInterval: env.clock.clearInterval,
|
||||
|
||||
jsApiReporter: new jasmine.JsApiReporter(jasmine)
|
||||
jsApiReporter: new jasmine.JsApiReporter({
|
||||
timer: new jasmine.Timer()
|
||||
})
|
||||
};
|
||||
|
||||
extend(global, jasmineInterface);
|
||||
@@ -78,7 +80,8 @@ function executeSpecs(specs, done, isVerbose, showColors) {
|
||||
var consoleReporter = new jasmine.ConsoleReporter({
|
||||
print: util.print,
|
||||
onComplete: done,
|
||||
showColors: showColors
|
||||
showColors: showColors,
|
||||
timer: new jasmine.Timer()
|
||||
});
|
||||
|
||||
env.addReporter(consoleReporter);
|
||||
|
||||
@@ -53,7 +53,9 @@
|
||||
setInterval: env.clock.setInterval,
|
||||
clearInterval: env.clock.clearInterval,
|
||||
|
||||
jsApiReporter: new jasmine.JsApiReporter(jasmine)
|
||||
jsApiReporter: new jasmine.JsApiReporter({
|
||||
timer: new jasmine.Timer()
|
||||
})
|
||||
};
|
||||
|
||||
if (typeof window == "undefined" && typeof exports == "object") {
|
||||
@@ -76,7 +78,8 @@
|
||||
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
|
||||
getContainer: function() { return document.body; },
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user