Moved dependencies out of HtmlReporter and into boot.js - QueryString for spec filtering and UI around raising exceptions checkbox; New object for handling spec filtering for browsers;
This commit is contained in:
@@ -62,6 +62,7 @@
|
|||||||
var htmlReporter = new jasmine.HtmlReporter({
|
var htmlReporter = new jasmine.HtmlReporter({
|
||||||
env: env,
|
env: env,
|
||||||
queryString: queryString,
|
queryString: queryString,
|
||||||
|
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); }
|
||||||
@@ -70,8 +71,12 @@
|
|||||||
env.addReporter(jasmineInterface.jsApiReporter);
|
env.addReporter(jasmineInterface.jsApiReporter);
|
||||||
env.addReporter(htmlReporter);
|
env.addReporter(htmlReporter);
|
||||||
|
|
||||||
|
var specFilter = new jasmine.HtmlSpecFilter({
|
||||||
|
filterString: function() { return queryString.getParam("spec"); }
|
||||||
|
});
|
||||||
|
|
||||||
env.specFilter = function(spec) {
|
env.specFilter = function(spec) {
|
||||||
return htmlReporter.specFilter(spec);
|
return specFilter.matches(spec);
|
||||||
};
|
};
|
||||||
|
|
||||||
var currentWindowOnload = window.onload;
|
var currentWindowOnload = window.onload;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ jasmine.HtmlReporter = function(options) {
|
|||||||
createElement = options.createElement,
|
createElement = options.createElement,
|
||||||
createTextNode = options.createTextNode,
|
createTextNode = options.createTextNode,
|
||||||
results = [],
|
results = [],
|
||||||
queryString = options.queryString,
|
|
||||||
startTime,
|
startTime,
|
||||||
specsExecuted = 0,
|
specsExecuted = 0,
|
||||||
failureCount = 0,
|
failureCount = 0,
|
||||||
@@ -29,18 +28,6 @@ jasmine.HtmlReporter = function(options) {
|
|||||||
symbols = find(".symbol-summary")[0];
|
symbols = find(".symbol-summary")[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
var specFilterPattern;
|
|
||||||
|
|
||||||
this.specFilter = function(spec) {
|
|
||||||
if (!isFiltered()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var specName = spec.getFullName();
|
|
||||||
|
|
||||||
return !!(specName.match(specFilterPattern));
|
|
||||||
};
|
|
||||||
|
|
||||||
var totalSpecsDefined;
|
var totalSpecsDefined;
|
||||||
this.jasmineStarted = function(options) {
|
this.jasmineStarted = function(options) {
|
||||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||||
@@ -120,9 +107,7 @@ jasmine.HtmlReporter = function(options) {
|
|||||||
var checkbox = find("input")[0];
|
var checkbox = find("input")[0];
|
||||||
|
|
||||||
checkbox.checked = !env.catchingExceptions();
|
checkbox.checked = !env.catchingExceptions();
|
||||||
checkbox.onclick = function() {
|
checkbox.onclick = options.onRaiseExceptionsClick;
|
||||||
queryString.setParam("catch", !checkbox.checked);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (specsExecuted < totalSpecsDefined) {
|
if (specsExecuted < totalSpecsDefined) {
|
||||||
var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
|
var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
|
||||||
@@ -245,21 +230,15 @@ jasmine.HtmlReporter = function(options) {
|
|||||||
return "?spec=" + encodeURIComponent(result.fullName);
|
return "?spec=" + encodeURIComponent(result.fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isFiltered() {
|
|
||||||
buildSpecFilter();
|
|
||||||
|
|
||||||
return !!specFilterPattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildSpecFilter() {
|
|
||||||
var specFilterParam = queryString.getParam("spec") || "";
|
|
||||||
|
|
||||||
specFilterPattern = new RegExp(specFilterParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setMenuModeTo(mode) {
|
function setMenuModeTo(mode) {
|
||||||
htmlReporterMain.setAttribute("class", "html-reporter " + mode);
|
htmlReporterMain.setAttribute("class", "html-reporter " + mode);
|
||||||
}
|
}
|
||||||
|
};jasmine.HtmlSpecFilter = function(options) {
|
||||||
|
var filterPattern = new RegExp(options && options.filterString());
|
||||||
|
|
||||||
|
this.matches = function(specName) {
|
||||||
|
return filterPattern.test(specName);
|
||||||
|
};
|
||||||
};jasmine.ResultsNode = function(result, type, parent) {
|
};jasmine.ResultsNode = function(result, type, parent) {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|||||||
+31
-157
@@ -188,7 +188,6 @@ describe("New HtmlReporter", function() {
|
|||||||
reporter.jasmineDone();
|
reporter.jasmineDone();
|
||||||
var summary = container.getElementsByClassName("summary")[0];
|
var summary = container.getElementsByClassName("summary")[0];
|
||||||
|
|
||||||
console.error("=============>", summary);
|
|
||||||
expect(summary.childNodes.length).toEqual(1);
|
expect(summary.childNodes.length).toEqual(1);
|
||||||
|
|
||||||
var outerSuite = summary.childNodes[0];
|
var outerSuite = summary.childNodes[0];
|
||||||
@@ -221,12 +220,18 @@ describe("New HtmlReporter", function() {
|
|||||||
it("should be unchecked if the env is catching", function() {
|
it("should be unchecked if the env is catching", function() {
|
||||||
var env = new jasmine.Env(),
|
var env = new jasmine.Env(),
|
||||||
container = document.createElement("div"),
|
container = document.createElement("div"),
|
||||||
getContainer = function() { return container; },
|
getContainer = function() {
|
||||||
reporter = new jasmine.HtmlReporter({
|
return container;
|
||||||
|
},
|
||||||
|
reporter = new jasmine.HtmlReporter({
|
||||||
env: env,
|
env: env,
|
||||||
getContainer: getContainer,
|
getContainer: getContainer,
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
createElement: function() {
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
return document.createElement.apply(document, arguments);
|
||||||
|
},
|
||||||
|
createTextNode: function() {
|
||||||
|
return document.createTextNode.apply(document, arguments);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
@@ -239,20 +244,18 @@ describe("New HtmlReporter", function() {
|
|||||||
it("should be checked if the env is not catching", function() {
|
it("should be checked if the env is not catching", function() {
|
||||||
var env = new jasmine.Env(),
|
var env = new jasmine.Env(),
|
||||||
container = document.createElement("div"),
|
container = document.createElement("div"),
|
||||||
fakeQueryString = "",
|
getContainer = function() {
|
||||||
fakeWindowLocation = {
|
return container;
|
||||||
search: fakeQueryString
|
|
||||||
},
|
},
|
||||||
queryString = new jasmine.QueryString({
|
reporter = new jasmine.HtmlReporter({
|
||||||
getWindowLocation: function() { return fakeWindowLocation; }
|
|
||||||
}),
|
|
||||||
getContainer = function() { return container; },
|
|
||||||
reporter = new jasmine.HtmlReporter({
|
|
||||||
env: env,
|
env: env,
|
||||||
getContainer: getContainer,
|
getContainer: getContainer,
|
||||||
queryString: queryString,
|
createElement: function() {
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
return document.createElement.apply(document, arguments);
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
},
|
||||||
|
createTextNode: function() {
|
||||||
|
return document.createTextNode.apply(document, arguments);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
@@ -266,20 +269,20 @@ describe("New HtmlReporter", function() {
|
|||||||
it("should affect the query param for catching exceptions", function() {
|
it("should affect the query param for catching exceptions", function() {
|
||||||
var env = new jasmine.Env(),
|
var env = new jasmine.Env(),
|
||||||
container = document.createElement("div"),
|
container = document.createElement("div"),
|
||||||
fakeQueryString = "",
|
exceptionsClickHandler = jasmine.createSpy("raise exceptions checked"),
|
||||||
fakeWindowLocation = {
|
getContainer = function() {
|
||||||
search: fakeQueryString
|
return container;
|
||||||
},
|
},
|
||||||
queryString = new jasmine.QueryString({
|
reporter = new jasmine.HtmlReporter({
|
||||||
getWindowLocation: function() { return fakeWindowLocation; }
|
|
||||||
}),
|
|
||||||
getContainer = function() { return container; },
|
|
||||||
reporter = new jasmine.HtmlReporter({
|
|
||||||
env: env,
|
env: env,
|
||||||
getContainer: getContainer,
|
getContainer: getContainer,
|
||||||
queryString: queryString,
|
onRaiseExceptionsClick: exceptionsClickHandler,
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
createElement: function() {
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
return document.createElement.apply(document, arguments);
|
||||||
|
},
|
||||||
|
createTextNode: function() {
|
||||||
|
return document.createTextNode.apply(document, arguments);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
@@ -287,10 +290,7 @@ describe("New HtmlReporter", function() {
|
|||||||
|
|
||||||
var input = container.getElementsByClassName("raise")[0];
|
var input = container.getElementsByClassName("raise")[0];
|
||||||
input.click();
|
input.click();
|
||||||
expect(queryString.getParam("catch")).toEqual(false);
|
expect(exceptionsClickHandler).toHaveBeenCalled();
|
||||||
|
|
||||||
input.click();
|
|
||||||
expect(queryString.getParam("catch")).toEqual(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -426,132 +426,6 @@ describe("New HtmlReporter", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("specFilter", function() {
|
|
||||||
|
|
||||||
it("always returns true if there is no filter", function() {
|
|
||||||
var env = new jasmine.Env(),
|
|
||||||
container = document.createElement("div"),
|
|
||||||
fakeQueryString = "",
|
|
||||||
fakeWindowLocation = {
|
|
||||||
search: fakeQueryString
|
|
||||||
},
|
|
||||||
queryString = new jasmine.QueryString({
|
|
||||||
getWindowLocation: function() { return fakeWindowLocation; }
|
|
||||||
}),
|
|
||||||
getContainer = function() { return container; },
|
|
||||||
reporter = new jasmine.HtmlReporter({
|
|
||||||
env: env,
|
|
||||||
getContainer: getContainer,
|
|
||||||
queryString: queryString,
|
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
|
||||||
}),
|
|
||||||
fakeSpec = {
|
|
||||||
getFullName: function() { return "A suite with a spec"}
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(reporter.specFilter(fakeSpec)).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("matches a focused spec name", function() {
|
|
||||||
var env = new jasmine.Env(),
|
|
||||||
container = document.createElement("div"),
|
|
||||||
fakeWindowLocation = {
|
|
||||||
search: "?spec=A%20suite%20with%20a%20spec"
|
|
||||||
},
|
|
||||||
queryString = new jasmine.QueryString({
|
|
||||||
getWindowLocation: function() { return fakeWindowLocation; }
|
|
||||||
}),
|
|
||||||
getContainer = function() { return container; },
|
|
||||||
reporter = new jasmine.HtmlReporter({
|
|
||||||
env: env,
|
|
||||||
getContainer: getContainer,
|
|
||||||
queryString: queryString,
|
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
|
||||||
}),
|
|
||||||
fakeMatchingSpec = {
|
|
||||||
getFullName: function() { return "A suite with a spec"}
|
|
||||||
},
|
|
||||||
fakeNonMatchingSpec = {
|
|
||||||
getFullName: function() { return "sasquatch"}
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(reporter.specFilter(fakeMatchingSpec)).toBe(true);
|
|
||||||
expect(reporter.specFilter(fakeNonMatchingSpec)).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("matches a substring of a spec name", function() {
|
|
||||||
var env = new jasmine.Env(),
|
|
||||||
container = document.createElement("div"),
|
|
||||||
fakeWindowLocation = {
|
|
||||||
search: "?spec=with"
|
|
||||||
},
|
|
||||||
queryString = new jasmine.QueryString({
|
|
||||||
getWindowLocation: function() { return fakeWindowLocation; }
|
|
||||||
}),
|
|
||||||
getContainer = function() { return container; },
|
|
||||||
reporter = new jasmine.HtmlReporter({
|
|
||||||
env: env,
|
|
||||||
getContainer: getContainer,
|
|
||||||
queryString: queryString,
|
|
||||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
|
||||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
|
||||||
}),
|
|
||||||
fakeMatchingSpec = {
|
|
||||||
getFullName: function() { return "A suite with a spec" }
|
|
||||||
},
|
|
||||||
fakeNonMatchingSpec = {
|
|
||||||
getFullName: function() { return "sasquatch"}
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(reporter.specFilter(fakeMatchingSpec)).toBe(true);
|
|
||||||
expect(reporter.specFilter(fakeNonMatchingSpec)).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("when specs are filtered", function() {
|
|
||||||
it("shows the count of run specs and defined specs", function() {
|
|
||||||
var env = new jasmine.Env(),
|
|
||||||
container = document.createElement("div"),
|
|
||||||
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); }
|
|
||||||
});
|
|
||||||
|
|
||||||
reporter.initialize();
|
|
||||||
|
|
||||||
reporter.jasmineStarted({
|
|
||||||
totalSpecsDefined: 2
|
|
||||||
});
|
|
||||||
reporter.specDone({
|
|
||||||
id: 123,
|
|
||||||
description: "with a spec",
|
|
||||||
fullName: "A Suite with a spec",
|
|
||||||
status: "passed"
|
|
||||||
});
|
|
||||||
reporter.specDone({
|
|
||||||
id: 124,
|
|
||||||
description: "with another spec",
|
|
||||||
fullName: "A Suite inner suite with another spec",
|
|
||||||
status: "disabled"
|
|
||||||
});
|
|
||||||
reporter.jasmineDone();
|
|
||||||
|
|
||||||
var skippedBar = container.getElementsByClassName("bar")[0];
|
|
||||||
expect(skippedBar.getAttribute("class")).toMatch(/skipped/);
|
|
||||||
|
|
||||||
var runAllLink = skippedBar.childNodes[0];
|
|
||||||
expect(runAllLink.getAttribute("href")).toEqual("?");
|
|
||||||
expect(runAllLink.text).toMatch(/Ran \d+ of \d+ specs - run all/);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// try/catch
|
|
||||||
|
|
||||||
// utility functions
|
// utility functions
|
||||||
function findElements(divs, withClass) {
|
function findElements(divs, withClass) {
|
||||||
var els = [];
|
var els = [];
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
describe("jasmine.HtmlSpecFilter", function() {
|
||||||
|
|
||||||
|
it("should match when no string is provided", function() {
|
||||||
|
var specFilter = new jasmine.HtmlSpecFilter();
|
||||||
|
|
||||||
|
expect(specFilter.matches("foo")).toBe(true);
|
||||||
|
expect(specFilter.matches("*bar")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should only match the provided string", function() {
|
||||||
|
var specFilter = new jasmine.HtmlSpecFilter({
|
||||||
|
filterString: function() { return "foo"; }
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(specFilter.matches("foo")).toBe(true);
|
||||||
|
expect(specFilter.matches("bar")).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -5,7 +5,6 @@ jasmine.HtmlReporter = function(options) {
|
|||||||
createElement = options.createElement,
|
createElement = options.createElement,
|
||||||
createTextNode = options.createTextNode,
|
createTextNode = options.createTextNode,
|
||||||
results = [],
|
results = [],
|
||||||
queryString = options.queryString,
|
|
||||||
startTime,
|
startTime,
|
||||||
specsExecuted = 0,
|
specsExecuted = 0,
|
||||||
failureCount = 0,
|
failureCount = 0,
|
||||||
@@ -29,18 +28,6 @@ jasmine.HtmlReporter = function(options) {
|
|||||||
symbols = find(".symbol-summary")[0];
|
symbols = find(".symbol-summary")[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
var specFilterPattern;
|
|
||||||
|
|
||||||
this.specFilter = function(spec) {
|
|
||||||
if (!isFiltered()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var specName = spec.getFullName();
|
|
||||||
|
|
||||||
return !!(specName.match(specFilterPattern));
|
|
||||||
};
|
|
||||||
|
|
||||||
var totalSpecsDefined;
|
var totalSpecsDefined;
|
||||||
this.jasmineStarted = function(options) {
|
this.jasmineStarted = function(options) {
|
||||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||||
@@ -120,9 +107,7 @@ jasmine.HtmlReporter = function(options) {
|
|||||||
var checkbox = find("input")[0];
|
var checkbox = find("input")[0];
|
||||||
|
|
||||||
checkbox.checked = !env.catchingExceptions();
|
checkbox.checked = !env.catchingExceptions();
|
||||||
checkbox.onclick = function() {
|
checkbox.onclick = options.onRaiseExceptionsClick;
|
||||||
queryString.setParam("catch", !checkbox.checked);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (specsExecuted < totalSpecsDefined) {
|
if (specsExecuted < totalSpecsDefined) {
|
||||||
var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
|
var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
|
||||||
@@ -245,18 +230,6 @@ jasmine.HtmlReporter = function(options) {
|
|||||||
return "?spec=" + encodeURIComponent(result.fullName);
|
return "?spec=" + encodeURIComponent(result.fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isFiltered() {
|
|
||||||
buildSpecFilter();
|
|
||||||
|
|
||||||
return !!specFilterPattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildSpecFilter() {
|
|
||||||
var specFilterParam = queryString.getParam("spec") || "";
|
|
||||||
|
|
||||||
specFilterPattern = new RegExp(specFilterParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setMenuModeTo(mode) {
|
function setMenuModeTo(mode) {
|
||||||
htmlReporterMain.setAttribute("class", "html-reporter " + mode);
|
htmlReporterMain.setAttribute("class", "html-reporter " + mode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
jasmine.HtmlSpecFilter = function(options) {
|
||||||
|
var filterPattern = new RegExp(options && options.filterString());
|
||||||
|
|
||||||
|
this.matches = function(specName) {
|
||||||
|
return filterPattern.test(specName);
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -19,6 +19,7 @@ class JasmineDev < Thor
|
|||||||
|
|
||||||
:html => [
|
:html => [
|
||||||
"HtmlReporter.js",
|
"HtmlReporter.js",
|
||||||
|
"HtmlSpecFilter.js",
|
||||||
"ResultsNode.js",
|
"ResultsNode.js",
|
||||||
"QueryString.js"
|
"QueryString.js"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user