From d1a94bcf508d5347c5893eeffc1752dbd5f25d81 Mon Sep 17 00:00:00 2001 From: Dominick Reinhold Date: Sun, 28 Feb 2016 22:47:10 -0800 Subject: [PATCH] When the HtmlReporter has a 'spec' query param, the spec list only shows matching specs/suites --- lib/jasmine-core/boot/boot.js | 5 ++- spec/html/HtmlReporterSpec.js | 58 +++++++++++++++++++++++++++++++++++ src/html/HtmlReporter.js | 18 +++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/lib/jasmine-core/boot/boot.js b/lib/jasmine-core/boot/boot.js index a99774d0..d9b5a80b 100644 --- a/lib/jasmine-core/boot/boot.js +++ b/lib/jasmine-core/boot/boot.js @@ -49,6 +49,8 @@ getWindowLocation: function() { return window.location; } }); + var filterSpecs = !!queryString.getParam("spec"); + var catchingExceptions = queryString.getParam("catch"); env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions); @@ -76,7 +78,8 @@ getContainer: function() { return document.body; }, createElement: function() { return document.createElement.apply(document, arguments); }, createTextNode: function() { return document.createTextNode.apply(document, arguments); }, - timer: new jasmine.Timer() + timer: new jasmine.Timer(), + filterSpecs: filterSpecs }); /** diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index 980796b4..723ef8b7 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -804,6 +804,64 @@ describe("New HtmlReporter", function() { }); }); + describe("and there are disabled specs", function() { + var env, container, reporter, reporterConfig, specStatus; + beforeEach(function() { + env = new jasmineUnderTest.Env(); + container = document.createElement("div"); + reporterConfig = { + env: env, + getContainer: function() { return container; }, + createElement: function() { return document.createElement.apply(document, arguments); }, + createTextNode: function() { return document.createTextNode.apply(document, arguments); } + }; + specStatus = { + id: 123, + description: "with a disabled spec", + fullName: "A Suite with a disabled spec", + status: "disabled", + passedExpectations: [], + failedExpectations: [] + }; + }); + + describe("when the specs are not filtered", function() { + beforeEach(function() { + reporterConfig.filterSpecs = false; + reporter = new jasmineUnderTest.HtmlReporter(reporterConfig); + reporter.initialize(); + reporter.jasmineStarted({ totalSpecsDefined: 1 }); + reporter.specStarted(specStatus); + reporter.specDone(specStatus); + reporter.jasmineDone({}); + }); + + it("shows the disabled spec in the spec list", function() { + var specList = container.querySelector(".jasmine-summary"); + + expect(specList.innerHTML).toContain('with a disabled spec'); + }); + }); + + describe("when the specs are filtered", function() { + beforeEach(function() { + reporterConfig.filterSpecs = true; + reporter = new jasmineUnderTest.HtmlReporter(reporterConfig); + reporter.initialize(); + reporter.jasmineStarted({ totalSpecsDefined: 1 }); + reporter.specStarted(specStatus); + reporter.specDone(specStatus); + reporter.jasmineDone({}); + }); + + it("doesn't show the disabled spec in the spec list", function() { + var specList = container.querySelector(".jasmine-summary"); + + expect(specList.innerHTML).toEqual(''); + }); + }); + }); + describe("and there are pending specs", function() { var env, container, reporter; beforeEach(function() { diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index b321885f..03df043d 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -14,6 +14,7 @@ jasmineRequire.HtmlReporter = function(j$) { onThrowExpectationsClick = options.onThrowExpectationsClick || function() {}, onRandomClick = options.onRandomClick || function() {}, addToExistingQueryString = options.addToExistingQueryString || defaultQueryString, + filterSpecs = options.filterSpecs, timer = options.timer || noopTimer, results = [], specsExecuted = 0, @@ -234,6 +235,9 @@ jasmineRequire.HtmlReporter = function(j$) { var specListNode; for (var i = 0; i < resultsTree.children.length; i++) { var resultNode = resultsTree.children[i]; + if (filterSpecs && !hasActiveSpec(resultNode)) { + continue; + } if (resultNode.type == 'suite') { var suiteListNode = createDom('ul', {className: 'jasmine-suite', id: 'suite-' + resultNode.result.id}, createDom('li', {className: 'jasmine-suite-detail'}, @@ -361,6 +365,20 @@ jasmineRequire.HtmlReporter = function(j$) { return (result.failedExpectations.length + result.passedExpectations.length) === 0 && result.status === 'passed'; } + + function hasActiveSpec(resultNode) { + if (resultNode.type == 'spec' && resultNode.result.status != 'disabled') { + return true; + } + + if (resultNode.type == 'suite') { + for (var i = 0, j = resultNode.children.length; i < j; i++) { + if (hasActiveSpec(resultNode.children[i])) { + return true; + } + } + } + } } return HtmlReporter;