Re-add support for partial spec name filtering

No UI for this but users can construct URLs manually.
Fixes #2085.
This commit is contained in:
Steve Gravrock
2025-10-24 17:26:49 -07:00
parent 6667a42301
commit 85322d1877
8 changed files with 114 additions and 69 deletions

View File

@@ -58,6 +58,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
env.addReporter(jsApiReporter);
env.addReporter(htmlReporter);
/**
* Configures Jasmine based on the current set of query parameters. This
* supports all parameters set by the HTML reporter as well as
* spec=partialPath, which filters out specs whose paths don't contain the
* parameter.
*/
env.configure(urls.configFromCurrentUrl());
/**

View File

@@ -1233,7 +1233,10 @@ jasmineRequire.HtmlReporterV2Urls = function(j$) {
}
/**
* Creates a {@link Configuration} from the current page's URL.
* Creates a {@link Configuration} from the current page's URL. Supported
* query string parameters include all those set by {@link HtmlReporterV2}
* as well as spec=partialPath, which filters out specs whose paths don't
* contain partialPath.
* @returns {Configuration}
* @example
* const urls = new jasmine.HtmlReporterV2Urls();
@@ -1259,9 +1262,10 @@ jasmineRequire.HtmlReporterV2Urls = function(j$) {
}
const specFilter = new j$.private.HtmlSpecFilterV2({
filterString: () => {
return this.queryString.getParam('path');
}
filterParams: () => ({
path: this.queryString.getParam('path'),
spec: this.queryString.getParam('spec')
})
});
config.specFilter = function(spec) {
@@ -1281,35 +1285,35 @@ jasmineRequire.HtmlReporterV2Urls = function(j$) {
jasmineRequire.HtmlSpecFilterV2 = function() {
class HtmlSpecFilterV2 {
#getFilterString;
#getFilterParams;
constructor(options) {
this.#getFilterString = options.filterString;
this.#getFilterParams = options.filterParams;
}
/**
* Determines whether the spec with the specified name should be executed.
* @name HtmlSpecFilterV2#matches
* @function
* @param {Spec} spec
* @returns {boolean}
*/
matches(spec) {
const filterString = this.#getFilterString();
const params = this.#getFilterParams();
if (!filterString) {
return true;
if (params.path) {
return this.#matchesPath(spec, JSON.parse(params.path));
} else if (params.spec) {
// Like legacy HtmlSpecFilter, retained because it's convenient for
// hand-constructing filter URLs
return spec.getFullName().includes(params.spec);
}
const filterPath = JSON.parse(this.#getFilterString());
return true;
}
#matchesPath(spec, path) {
const specPath = spec.getPath();
if (filterPath.length > specPath.length) {
if (path.length > specPath.length) {
return false;
}
for (let i = 0; i < filterPath.length; i++) {
if (specPath[i] !== filterPath[i]) {
for (let i = 0; i < path.length; i++) {
if (specPath[i] !== path[i]) {
return false;
}
}

View File

@@ -8905,6 +8905,7 @@ getJasmineRequireObj().reporterEvents = function(j$) {
* {@link ReporterCapabilities} will apply.
* @name Reporter#reporterCapabilities
* @type ReporterCapabilities | undefined
* @optional
* @since 5.0
*/
/**
@@ -8971,6 +8972,7 @@ getJasmineRequireObj().reporterEvents = function(j$) {
/**
* `specStarted` is invoked when an `it` starts to run (including associated `beforeEach` functions)
* @function
* @optional
* @name Reporter#specStarted
* @param {SpecStartedEvent} result Information about the individual {@link it} being run
* @param {Function} [done] Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.