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({
|
||||
env: env,
|
||||
queryString: queryString,
|
||||
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); }
|
||||
@@ -70,8 +71,12 @@
|
||||
env.addReporter(jasmineInterface.jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() { return queryString.getParam("spec"); }
|
||||
});
|
||||
|
||||
env.specFilter = function(spec) {
|
||||
return htmlReporter.specFilter(spec);
|
||||
return specFilter.matches(spec);
|
||||
};
|
||||
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
@@ -5,7 +5,6 @@ jasmine.HtmlReporter = function(options) {
|
||||
createElement = options.createElement,
|
||||
createTextNode = options.createTextNode,
|
||||
results = [],
|
||||
queryString = options.queryString,
|
||||
startTime,
|
||||
specsExecuted = 0,
|
||||
failureCount = 0,
|
||||
@@ -29,18 +28,6 @@ jasmine.HtmlReporter = function(options) {
|
||||
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;
|
||||
this.jasmineStarted = function(options) {
|
||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||
@@ -120,9 +107,7 @@ jasmine.HtmlReporter = function(options) {
|
||||
var checkbox = find("input")[0];
|
||||
|
||||
checkbox.checked = !env.catchingExceptions();
|
||||
checkbox.onclick = function() {
|
||||
queryString.setParam("catch", !checkbox.checked);
|
||||
};
|
||||
checkbox.onclick = options.onRaiseExceptionsClick;
|
||||
|
||||
if (specsExecuted < totalSpecsDefined) {
|
||||
var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
|
||||
@@ -245,21 +230,15 @@ jasmine.HtmlReporter = function(options) {
|
||||
return "?spec=" + encodeURIComponent(result.fullName);
|
||||
}
|
||||
|
||||
function isFiltered() {
|
||||
buildSpecFilter();
|
||||
|
||||
return !!specFilterPattern;
|
||||
}
|
||||
|
||||
function buildSpecFilter() {
|
||||
var specFilterParam = queryString.getParam("spec") || "";
|
||||
|
||||
specFilterPattern = new RegExp(specFilterParam);
|
||||
}
|
||||
|
||||
function setMenuModeTo(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) {
|
||||
this.result = result;
|
||||
this.type = type;
|
||||
|
||||
@@ -188,7 +188,6 @@ describe("New HtmlReporter", function() {
|
||||
reporter.jasmineDone();
|
||||
var summary = container.getElementsByClassName("summary")[0];
|
||||
|
||||
console.error("=============>", summary);
|
||||
expect(summary.childNodes.length).toEqual(1);
|
||||
|
||||
var outerSuite = summary.childNodes[0];
|
||||
@@ -221,12 +220,18 @@ describe("New HtmlReporter", function() {
|
||||
it("should be unchecked if the env is catching", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
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); }
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
@@ -239,20 +244,18 @@ describe("New HtmlReporter", function() {
|
||||
it("should be checked if the env is not catching", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
fakeQueryString = "",
|
||||
fakeWindowLocation = {
|
||||
search: fakeQueryString
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() { return fakeWindowLocation; }
|
||||
}),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
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); }
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
@@ -266,20 +269,20 @@ describe("New HtmlReporter", function() {
|
||||
it("should affect the query param for catching exceptions", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
fakeQueryString = "",
|
||||
fakeWindowLocation = {
|
||||
search: fakeQueryString
|
||||
exceptionsClickHandler = jasmine.createSpy("raise exceptions checked"),
|
||||
getContainer = function() {
|
||||
return container;
|
||||
},
|
||||
queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() { return fakeWindowLocation; }
|
||||
}),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
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); }
|
||||
onRaiseExceptionsClick: exceptionsClickHandler,
|
||||
createElement: function() {
|
||||
return document.createElement.apply(document, arguments);
|
||||
},
|
||||
createTextNode: function() {
|
||||
return document.createTextNode.apply(document, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
reporter.initialize();
|
||||
@@ -287,10 +290,7 @@ describe("New HtmlReporter", function() {
|
||||
|
||||
var input = container.getElementsByClassName("raise")[0];
|
||||
input.click();
|
||||
expect(queryString.getParam("catch")).toEqual(false);
|
||||
|
||||
input.click();
|
||||
expect(queryString.getParam("catch")).toEqual(true);
|
||||
expect(exceptionsClickHandler).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
function findElements(divs, withClass) {
|
||||
var els = [];
|
||||
|
||||
18
spec/html/HtmlSpecFilterSpec.js
Normal file
18
spec/html/HtmlSpecFilterSpec.js
Normal file
@@ -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,
|
||||
createTextNode = options.createTextNode,
|
||||
results = [],
|
||||
queryString = options.queryString,
|
||||
startTime,
|
||||
specsExecuted = 0,
|
||||
failureCount = 0,
|
||||
@@ -29,18 +28,6 @@ jasmine.HtmlReporter = function(options) {
|
||||
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;
|
||||
this.jasmineStarted = function(options) {
|
||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||
@@ -120,9 +107,7 @@ jasmine.HtmlReporter = function(options) {
|
||||
var checkbox = find("input")[0];
|
||||
|
||||
checkbox.checked = !env.catchingExceptions();
|
||||
checkbox.onclick = function() {
|
||||
queryString.setParam("catch", !checkbox.checked);
|
||||
};
|
||||
checkbox.onclick = options.onRaiseExceptionsClick;
|
||||
|
||||
if (specsExecuted < totalSpecsDefined) {
|
||||
var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
|
||||
@@ -245,18 +230,6 @@ jasmine.HtmlReporter = function(options) {
|
||||
return "?spec=" + encodeURIComponent(result.fullName);
|
||||
}
|
||||
|
||||
function isFiltered() {
|
||||
buildSpecFilter();
|
||||
|
||||
return !!specFilterPattern;
|
||||
}
|
||||
|
||||
function buildSpecFilter() {
|
||||
var specFilterParam = queryString.getParam("spec") || "";
|
||||
|
||||
specFilterPattern = new RegExp(specFilterParam);
|
||||
}
|
||||
|
||||
function setMenuModeTo(mode) {
|
||||
htmlReporterMain.setAttribute("class", "html-reporter " + mode);
|
||||
}
|
||||
|
||||
7
src/html/HtmlSpecFilter.js
Normal file
7
src/html/HtmlSpecFilter.js
Normal file
@@ -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 => [
|
||||
"HtmlReporter.js",
|
||||
"HtmlSpecFilter.js",
|
||||
"ResultsNode.js",
|
||||
"QueryString.js"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user