From 489b83c61b558cc20c5b1be6a9779ecfa213ca41 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sun, 5 Oct 2025 09:54:25 -0700 Subject: [PATCH] Revert "Move knowledge of query parameters out of boot1.js" This reverts commit 6715f24fd0ccbe8a53392dcd62a494db127f6271. --- lib/jasmine-core/boot1.js | 17 ++++++++++++++-- lib/jasmine-core/jasmine-html.js | 19 +++++++++--------- spec/html/HtmlExactSpecFilterSpec.js | 30 ++++++++-------------------- spec/html/HtmlReporterSpec.js | 19 ++---------------- src/boot/boot1.js | 17 ++++++++++++++-- src/html/HtmlExactSpecFilter.js | 13 +++++++----- src/html/HtmlReporter.js | 6 +----- 7 files changed, 58 insertions(+), 63 deletions(-) diff --git a/lib/jasmine-core/boot1.js b/lib/jasmine-core/boot1.js index c1bf086b..302fceec 100644 --- a/lib/jasmine-core/boot1.js +++ b/lib/jasmine-core/boot1.js @@ -38,12 +38,20 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (function() { const env = jasmine.getEnv(); + /** + * ## Runner Parameters + * + * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface. + */ + const queryString = new jasmine.QueryString({ getWindowLocation: function() { return window.location; } }); + const filterSpecs = !!queryString.getParam('spec'); + const config = { stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'), stopSpecOnExpectationFailure: queryString.getParam( @@ -85,7 +93,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. return document.createTextNode.apply(document, arguments); }, timer: new jasmine.Timer(), - queryString + filterSpecs: filterSpecs }); /** @@ -97,7 +105,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /** * Filter which specs will be run by matching the start of the full name against the `spec` query param. */ - const specFilter = new jasmine.HtmlExactSpecFilter({ queryString }); + const specFilter = new jasmine.HtmlExactSpecFilter({ + filterString: function() { + return queryString.getParam('spec'); + } + }); + config.specFilter = function(spec) { return specFilter.matches(spec); }; diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 61f389d1..c9aa3c59 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -99,14 +99,10 @@ jasmineRequire.HtmlReporter = function(j$) { const getContainer = options.getContainer; const createElement = options.createElement; const createTextNode = options.createTextNode; - // TODO: in the next major release, replace navigateWithNewParam and - // addToExistingQueryString with direct usage of options.queryString const navigateWithNewParam = options.navigateWithNewParam || function() {}; const addToExistingQueryString = options.addToExistingQueryString || defaultQueryString; - const filterSpecs = options.queryString - ? !!options.queryString.getParam('spec') - : options.filterSpecs; // For compatibility with pre-5.11 boot files + const filterSpecs = options.filterSpecs; let htmlReporterMain; let symbols; const deprecationWarnings = []; @@ -1065,13 +1061,16 @@ jasmineRequire.HtmlExactSpecFilter = function() { /** * Create a filter instance. - * @param options Object with a queryString property, which should be an - * instance of {@link QueryString}. + * @param options Object with a filterString method, which should + * return the value of the "spec" query string parameter set by + * {@link HtmlReporter}. */ constructor(options) { - this.#getFilterString = function() { - return options.queryString.getParam('spec'); - }; + if (typeof options?.filterString !== 'function') { + throw new Error('options.filterString must be a function'); + } + + this.#getFilterString = options.filterString; } /** diff --git a/spec/html/HtmlExactSpecFilterSpec.js b/spec/html/HtmlExactSpecFilterSpec.js index ada0c49e..9fcef7d3 100644 --- a/spec/html/HtmlExactSpecFilterSpec.js +++ b/spec/html/HtmlExactSpecFilterSpec.js @@ -1,10 +1,8 @@ describe('HtmlExactSpecFilter', function() { it('matches everything when no string is provided', function() { const specFilter = new jasmineUnderTest.HtmlExactSpecFilter({ - queryString: { - getParam(name) { - return ''; - } + filterString() { + return ''; } }); @@ -13,12 +11,8 @@ describe('HtmlExactSpecFilter', function() { it('matches a spec with the exact same path', function() { const specFilter = new jasmineUnderTest.HtmlExactSpecFilter({ - queryString: { - getParam(name) { - if (name === 'spec') { - return '["a","b","c"]'; - } - } + filterString() { + return '["a","b","c"]'; } }); @@ -27,12 +21,8 @@ describe('HtmlExactSpecFilter', function() { it('matches a spec whose path has the filter path as a prefix', function() { const specFilter = new jasmineUnderTest.HtmlExactSpecFilter({ - queryString: { - getParam(name) { - if (name === 'spec') { - return '["a","b"]'; - } - } + filterString() { + return '["a","b"]'; } }); @@ -41,12 +31,8 @@ describe('HtmlExactSpecFilter', function() { it('does not match a spec with a different path', function() { const specFilter = new jasmineUnderTest.HtmlExactSpecFilter({ - queryString: { - getParam(name) { - if (name === 'spec') { - return '["a","b","c"]'; - } - } + filterString() { + return '["a","b","c"]'; } }); diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index a62fd187..fc06c560 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -1368,11 +1368,6 @@ describe('HtmlReporter', function() { }, createTextNode: function() { return document.createTextNode.apply(document, arguments); - }, - queryString: { - getParam(name) { - return ''; - } } }; specStatus = { @@ -1387,12 +1382,7 @@ describe('HtmlReporter', function() { describe('when the specs are not filtered', function() { beforeEach(function() { - reporterConfig.queryString.getParam = function(name) { - if (name !== 'spec') { - throw new Error('Unexpected query param ' + name); - } - return ''; - }; + reporterConfig.filterSpecs = false; reporter = new jasmineUnderTest.HtmlReporter(reporterConfig); reporter.initialize(); reporter.jasmineStarted({ totalSpecsDefined: 1 }); @@ -1410,12 +1400,7 @@ describe('HtmlReporter', function() { describe('when the specs are filtered', function() { beforeEach(function() { - reporterConfig.queryString.getParam = function(name) { - if (name !== 'spec') { - throw new Error('Unexpected query param ' + name); - } - return 'not the empty string'; - }; + reporterConfig.filterSpecs = true; reporter = new jasmineUnderTest.HtmlReporter(reporterConfig); reporter.initialize(); reporter.jasmineStarted({ totalSpecsDefined: 1 }); diff --git a/src/boot/boot1.js b/src/boot/boot1.js index 45547069..39327ca7 100644 --- a/src/boot/boot1.js +++ b/src/boot/boot1.js @@ -14,12 +14,20 @@ (function() { const env = jasmine.getEnv(); + /** + * ## Runner Parameters + * + * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface. + */ + const queryString = new jasmine.QueryString({ getWindowLocation: function() { return window.location; } }); + const filterSpecs = !!queryString.getParam('spec'); + const config = { stopOnSpecFailure: queryString.getParam('stopOnSpecFailure'), stopSpecOnExpectationFailure: queryString.getParam( @@ -61,7 +69,7 @@ return document.createTextNode.apply(document, arguments); }, timer: new jasmine.Timer(), - queryString + filterSpecs: filterSpecs }); /** @@ -73,7 +81,12 @@ /** * Filter which specs will be run by matching the start of the full name against the `spec` query param. */ - const specFilter = new jasmine.HtmlExactSpecFilter({ queryString }); + const specFilter = new jasmine.HtmlExactSpecFilter({ + filterString: function() { + return queryString.getParam('spec'); + } + }); + config.specFilter = function(spec) { return specFilter.matches(spec); }; diff --git a/src/html/HtmlExactSpecFilter.js b/src/html/HtmlExactSpecFilter.js index a027648c..f4209c7c 100644 --- a/src/html/HtmlExactSpecFilter.js +++ b/src/html/HtmlExactSpecFilter.js @@ -10,13 +10,16 @@ jasmineRequire.HtmlExactSpecFilter = function() { /** * Create a filter instance. - * @param options Object with a queryString property, which should be an - * instance of {@link QueryString}. + * @param options Object with a filterString method, which should + * return the value of the "spec" query string parameter set by + * {@link HtmlReporter}. */ constructor(options) { - this.#getFilterString = function() { - return options.queryString.getParam('spec'); - }; + if (typeof options?.filterString !== 'function') { + throw new Error('options.filterString must be a function'); + } + + this.#getFilterString = options.filterString; } /** diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index 88cafae1..ed011091 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -64,14 +64,10 @@ jasmineRequire.HtmlReporter = function(j$) { const getContainer = options.getContainer; const createElement = options.createElement; const createTextNode = options.createTextNode; - // TODO: in the next major release, replace navigateWithNewParam and - // addToExistingQueryString with direct usage of options.queryString const navigateWithNewParam = options.navigateWithNewParam || function() {}; const addToExistingQueryString = options.addToExistingQueryString || defaultQueryString; - const filterSpecs = options.queryString - ? !!options.queryString.getParam('spec') - : options.filterSpecs; // For compatibility with pre-5.11 boot files + const filterSpecs = options.filterSpecs; let htmlReporterMain; let symbols; const deprecationWarnings = [];