Move knowledge of query parameters out of boot1.js

This commit is contained in:
Steve Gravrock
2025-09-17 18:23:45 -07:00
parent fa481b2bd1
commit 6715f24fd0
7 changed files with 63 additions and 58 deletions

View File

@@ -38,20 +38,12 @@ 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(
@@ -93,7 +85,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
return document.createTextNode.apply(document, arguments);
},
timer: new jasmine.Timer(),
filterSpecs: filterSpecs
queryString
});
/**
@@ -105,12 +97,7 @@ 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({
filterString: function() {
return queryString.getParam('spec');
}
});
const specFilter = new jasmine.HtmlExactSpecFilter({ queryString });
config.specFilter = function(spec) {
return specFilter.matches(spec);
};

View File

@@ -99,10 +99,14 @@ 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.filterSpecs;
const filterSpecs = options.queryString
? !!options.queryString.getParam('spec')
: options.filterSpecs; // For compatibility with pre-5.11 boot files
let htmlReporterMain;
let symbols;
const deprecationWarnings = [];
@@ -1032,16 +1036,13 @@ jasmineRequire.HtmlExactSpecFilter = function() {
/**
* Create a filter instance.
* @param options Object with a filterString method, which should
* return the value of the "spec" query string parameter set by
* {@link HtmlReporter}.
* @param options Object with a queryString property, which should be an
* instance of {@link QueryString}.
*/
constructor(options) {
if (typeof options?.filterString !== 'function') {
throw new Error('options.filterString must be a function');
}
this.#getFilterString = options.filterString;
this.#getFilterString = function() {
return options.queryString.getParam('spec');
};
}
/**

View File

@@ -1,8 +1,10 @@
describe('HtmlExactSpecFilter', function() {
it('matches everything when no string is provided', function() {
const specFilter = new jasmineUnderTest.HtmlExactSpecFilter({
filterString() {
return '';
queryString: {
getParam(name) {
return '';
}
}
});
@@ -11,8 +13,12 @@ describe('HtmlExactSpecFilter', function() {
it('matches a spec with the exact same path', function() {
const specFilter = new jasmineUnderTest.HtmlExactSpecFilter({
filterString() {
return '["a","b","c"]';
queryString: {
getParam(name) {
if (name === 'spec') {
return '["a","b","c"]';
}
}
}
});
@@ -21,8 +27,12 @@ describe('HtmlExactSpecFilter', function() {
it('matches a spec whose path has the filter path as a prefix', function() {
const specFilter = new jasmineUnderTest.HtmlExactSpecFilter({
filterString() {
return '["a","b"]';
queryString: {
getParam(name) {
if (name === 'spec') {
return '["a","b"]';
}
}
}
});
@@ -31,8 +41,12 @@ describe('HtmlExactSpecFilter', function() {
it('does not match a spec with a different path', function() {
const specFilter = new jasmineUnderTest.HtmlExactSpecFilter({
filterString() {
return '["a","b","c"]';
queryString: {
getParam(name) {
if (name === 'spec') {
return '["a","b","c"]';
}
}
}
});

View File

@@ -1368,6 +1368,11 @@ describe('HtmlReporter', function() {
},
createTextNode: function() {
return document.createTextNode.apply(document, arguments);
},
queryString: {
getParam(name) {
return '';
}
}
};
specStatus = {
@@ -1382,7 +1387,12 @@ describe('HtmlReporter', function() {
describe('when the specs are not filtered', function() {
beforeEach(function() {
reporterConfig.filterSpecs = false;
reporterConfig.queryString.getParam = function(name) {
if (name !== 'spec') {
throw new Error('Unexpected query param ' + name);
}
return '';
};
reporter = new jasmineUnderTest.HtmlReporter(reporterConfig);
reporter.initialize();
reporter.jasmineStarted({ totalSpecsDefined: 1 });
@@ -1400,7 +1410,12 @@ describe('HtmlReporter', function() {
describe('when the specs are filtered', function() {
beforeEach(function() {
reporterConfig.filterSpecs = true;
reporterConfig.queryString.getParam = function(name) {
if (name !== 'spec') {
throw new Error('Unexpected query param ' + name);
}
return 'not the empty string';
};
reporter = new jasmineUnderTest.HtmlReporter(reporterConfig);
reporter.initialize();
reporter.jasmineStarted({ totalSpecsDefined: 1 });

View File

@@ -14,20 +14,12 @@
(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(
@@ -69,7 +61,7 @@
return document.createTextNode.apply(document, arguments);
},
timer: new jasmine.Timer(),
filterSpecs: filterSpecs
queryString
});
/**
@@ -81,12 +73,7 @@
/**
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
*/
const specFilter = new jasmine.HtmlExactSpecFilter({
filterString: function() {
return queryString.getParam('spec');
}
});
const specFilter = new jasmine.HtmlExactSpecFilter({ queryString });
config.specFilter = function(spec) {
return specFilter.matches(spec);
};

View File

@@ -10,16 +10,13 @@ jasmineRequire.HtmlExactSpecFilter = function() {
/**
* Create a filter instance.
* @param options Object with a filterString method, which should
* return the value of the "spec" query string parameter set by
* {@link HtmlReporter}.
* @param options Object with a queryString property, which should be an
* instance of {@link QueryString}.
*/
constructor(options) {
if (typeof options?.filterString !== 'function') {
throw new Error('options.filterString must be a function');
}
this.#getFilterString = options.filterString;
this.#getFilterString = function() {
return options.queryString.getParam('spec');
};
}
/**

View File

@@ -64,10 +64,14 @@ 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.filterSpecs;
const filterSpecs = options.queryString
? !!options.queryString.getParam('spec')
: options.filterSpecs; // For compatibility with pre-5.11 boot files
let htmlReporterMain;
let symbols;
const deprecationWarnings = [];