Clicking a link in HtmlReporterV2 does exact filtering
This commit is contained in:
@@ -37,7 +37,10 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
return window.location;
|
||||
}
|
||||
});
|
||||
this.#urlBuilder = new UrlBuilder(this.#queryString);
|
||||
this.#urlBuilder = new UrlBuilder({
|
||||
queryString: this.#queryString,
|
||||
getSuiteById: id => this.#stateBuilder.suitesById[id]
|
||||
});
|
||||
this.#filterSpecs = options.urls.filteringSpecs();
|
||||
}
|
||||
|
||||
@@ -174,34 +177,48 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
|
||||
class UrlBuilder {
|
||||
#queryString;
|
||||
#getSuiteById;
|
||||
|
||||
constructor(queryString) {
|
||||
this.#queryString = queryString;
|
||||
constructor(options) {
|
||||
this.#queryString = options.queryString;
|
||||
this.#getSuiteById = options.getSuiteById;
|
||||
}
|
||||
|
||||
suiteHref(suite) {
|
||||
const els = [];
|
||||
|
||||
while (suite && suite.parent) {
|
||||
els.unshift(suite.result.description);
|
||||
suite = suite.parent;
|
||||
}
|
||||
|
||||
return this.#addToExistingQueryString('spec', els.join(' '));
|
||||
const path = this.#suitePath(suite);
|
||||
return this.#specPathHref(path);
|
||||
}
|
||||
|
||||
specHref(result) {
|
||||
return this.#addToExistingQueryString('spec', result.fullName);
|
||||
specHref(specResult) {
|
||||
const suite = this.#getSuiteById(specResult.parentSuiteId);
|
||||
const path = this.#suitePath(suite);
|
||||
path.push(specResult.description);
|
||||
return this.#specPathHref(path);
|
||||
}
|
||||
|
||||
runAllHref() {
|
||||
return this.#addToExistingQueryString('spec', '');
|
||||
return this.#addToExistingQueryString('path', '');
|
||||
}
|
||||
|
||||
seedHref(seed) {
|
||||
return this.#addToExistingQueryString('seed', seed);
|
||||
}
|
||||
|
||||
#suitePath(suite) {
|
||||
const path = [];
|
||||
|
||||
while (suite && suite.parent) {
|
||||
path.unshift(suite.result.description);
|
||||
suite = suite.parent;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#specPathHref(specPath) {
|
||||
return this.#addToExistingQueryString('path', JSON.stringify(specPath));
|
||||
}
|
||||
|
||||
#addToExistingQueryString(k, v) {
|
||||
// include window.location.pathname to fix issue with karma-jasmine-html-reporter in angular: see https://github.com/jasmine/jasmine/issues/1906
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
jasmineRequire.HtmlReporterV2Urls = function(j$) {
|
||||
'use strict';
|
||||
|
||||
// TODO unify with V2 UrlBuilder?
|
||||
// TODO jsdoc
|
||||
class HtmlReporterV2Urls {
|
||||
constructor(options = {}) {
|
||||
@@ -38,19 +39,19 @@ jasmineRequire.HtmlReporterV2Urls = function(j$) {
|
||||
|
||||
const specFilter = new j$.private.HtmlSpecFilterV2({
|
||||
filterString: () => {
|
||||
return this.queryString.getParam('spec');
|
||||
return this.queryString.getParam('path');
|
||||
}
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
return specFilter.matches(spec);
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
filteringSpecs() {
|
||||
return !!this.queryString.getParam('spec');
|
||||
return !!this.queryString.getParam('path');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,40 @@
|
||||
jasmineRequire.HtmlSpecFilterV2 = function() {
|
||||
'use strict';
|
||||
class HtmlSpecFilterV2 {
|
||||
#getFilterString;
|
||||
|
||||
function HtmlSpecFilterV2(options) {
|
||||
const filterString =
|
||||
options &&
|
||||
options.filterString() &&
|
||||
options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
||||
const filterPattern = new RegExp(filterString);
|
||||
constructor(options) {
|
||||
this.#getFilterString = options.filterString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the spec with the specified name should be executed.
|
||||
* @name HtmlSpecFilter#matches
|
||||
* @name HtmlSpecFilterV2#matches
|
||||
* @function
|
||||
* @param {string} specName The full name of the spec
|
||||
* @param {Spec} spec
|
||||
* @returns {boolean}
|
||||
*/
|
||||
this.matches = function(specName) {
|
||||
return filterPattern.test(specName);
|
||||
};
|
||||
matches(spec) {
|
||||
const filterString = this.#getFilterString();
|
||||
|
||||
if (!filterString) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const filterPath = JSON.parse(this.#getFilterString());
|
||||
const specPath = spec.getPath();
|
||||
|
||||
if (filterPath.length > specPath.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < filterPath.length; i++) {
|
||||
if (specPath[i] !== filterPath[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return HtmlSpecFilterV2;
|
||||
|
||||
@@ -5,6 +5,7 @@ jasmineRequire.ResultsStateBuilder = function(j$) {
|
||||
constructor() {
|
||||
this.topResults = new j$.private.ResultsNode({}, '', null);
|
||||
this.currentParent = this.topResults;
|
||||
this.suitesById = {};
|
||||
this.totalSpecsDefined = 0;
|
||||
this.specsExecuted = 0;
|
||||
this.failureCount = 0;
|
||||
@@ -15,6 +16,7 @@ jasmineRequire.ResultsStateBuilder = function(j$) {
|
||||
suiteStarted(result) {
|
||||
this.currentParent.addChild(result, 'suite');
|
||||
this.currentParent = this.currentParent.last();
|
||||
this.suitesById[result.id] = this.currentParent;
|
||||
}
|
||||
|
||||
suiteDone(result) {
|
||||
|
||||
Reference in New Issue
Block a user