Simplify boot1.js
This commit is contained in:
@@ -39,57 +39,16 @@ 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(
|
||||
'stopSpecOnExpectationFailure'
|
||||
),
|
||||
hideDisabled: queryString.getParam('hideDisabled')
|
||||
};
|
||||
|
||||
const random = queryString.getParam('random');
|
||||
|
||||
if (random !== undefined && random !== '') {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
const seed = queryString.getParam('seed');
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
const urls = new jasmine.HtmlReporterV2Urls();
|
||||
|
||||
/**
|
||||
* ## Reporters
|
||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||
*/
|
||||
const htmlReporter = new jasmine.HtmlReporterV2({
|
||||
env: env,
|
||||
navigateWithNewParam: function(key, value) {
|
||||
return queryString.navigateWithNewParam(key, value);
|
||||
},
|
||||
addToExistingQueryString: function(key, value) {
|
||||
return queryString.fullStringWithNewParam(key, value);
|
||||
},
|
||||
getContainer: function() {
|
||||
return document.body;
|
||||
},
|
||||
timer: new jasmine.Timer(),
|
||||
filterSpecs: filterSpecs
|
||||
env,
|
||||
urls,
|
||||
container: document.body
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -97,21 +56,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
env.addReporter(jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
/**
|
||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||
*/
|
||||
const specFilter = new jasmine.HtmlSpecFilterV2({
|
||||
filterString: function() {
|
||||
return queryString.getParam('spec');
|
||||
}
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
env.configure(config);
|
||||
env.configure(urls.configFromCurrentUrl());
|
||||
|
||||
/**
|
||||
* ## Execution
|
||||
|
||||
@@ -35,10 +35,11 @@ jasmineRequire.html = function(j$) {
|
||||
j$.private.SummaryTreeView = jasmineRequire.SummaryTreeView(j$);
|
||||
j$.private.FailuresView = jasmineRequire.FailuresView(j$);
|
||||
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
||||
j$.HtmlReporterV2Urls = jasmineRequire.HtmlReporterV2Urls(j$);
|
||||
j$.HtmlReporterV2 = jasmineRequire.HtmlReporterV2(j$);
|
||||
j$.QueryString = jasmineRequire.QueryString();
|
||||
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
||||
j$.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
|
||||
j$.private.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
|
||||
};
|
||||
|
||||
jasmineRequire.HtmlReporter = function(j$) {
|
||||
@@ -984,8 +985,8 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
*/
|
||||
class HtmlReporterV2 {
|
||||
#env;
|
||||
#getContainer;
|
||||
#navigateWithNewParam;
|
||||
#container;
|
||||
#queryString;
|
||||
#urlBuilder;
|
||||
#filterSpecs;
|
||||
#stateBuilder;
|
||||
@@ -1001,13 +1002,16 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
constructor(options) {
|
||||
this.#env = options.env;
|
||||
|
||||
this.#getContainer = options.getContainer;
|
||||
this.#navigateWithNewParam =
|
||||
options.navigateWithNewParam || function() {};
|
||||
this.#urlBuilder = new UrlBuilder(
|
||||
options.addToExistingQueryString || defaultQueryString
|
||||
);
|
||||
this.#filterSpecs = options.filterSpecs;
|
||||
this.#container = options.container;
|
||||
this.#queryString =
|
||||
options.queryString ||
|
||||
new j$.QueryString({
|
||||
getWindowLocation() {
|
||||
return window.location;
|
||||
}
|
||||
});
|
||||
this.#urlBuilder = new UrlBuilder(this.#queryString);
|
||||
this.#filterSpecs = options.urls.filteringSpecs();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1023,7 +1027,9 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
|
||||
this.#alerts = new j$.private.AlertsView(this.#urlBuilder);
|
||||
this.#symbols = new j$.private.SymbolsView();
|
||||
this.#banner = new j$.private.Banner(this.#navigateWithNewParam);
|
||||
this.#banner = new j$.private.Banner(
|
||||
this.#queryString.navigateWithNewParam.bind(this.#queryString)
|
||||
);
|
||||
this.#failures = new j$.private.FailuresView(this.#urlBuilder);
|
||||
this.#htmlReporterMain = createDom(
|
||||
'div',
|
||||
@@ -1033,7 +1039,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
this.#alerts.rootEl,
|
||||
this.#failures.rootEl
|
||||
);
|
||||
this.#getContainer().appendChild(this.#htmlReporterMain);
|
||||
this.#container.appendChild(this.#htmlReporterMain);
|
||||
}
|
||||
|
||||
jasmineStarted(options) {
|
||||
@@ -1120,7 +1126,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
}
|
||||
|
||||
#find(selector) {
|
||||
return this.#getContainer().querySelector(
|
||||
return this.#container.querySelector(
|
||||
'.jasmine_html-reporter ' + selector
|
||||
);
|
||||
}
|
||||
@@ -1129,7 +1135,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
const oldReporter = this.#find('');
|
||||
|
||||
if (oldReporter) {
|
||||
this.#getContainer().removeChild(oldReporter);
|
||||
this.#container.removeChild(oldReporter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1142,15 +1148,10 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
}
|
||||
|
||||
class UrlBuilder {
|
||||
#addToExistingQueryString;
|
||||
#queryString;
|
||||
|
||||
constructor(addToExistingQueryString) {
|
||||
this.#addToExistingQueryString = function(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 (
|
||||
(window.location.pathname || '') + addToExistingQueryString(k, v)
|
||||
);
|
||||
};
|
||||
constructor(queryString) {
|
||||
this.#queryString = queryString;
|
||||
}
|
||||
|
||||
suiteHref(suite) {
|
||||
@@ -1175,15 +1176,78 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
seedHref(seed) {
|
||||
return this.#addToExistingQueryString('seed', seed);
|
||||
}
|
||||
}
|
||||
|
||||
function defaultQueryString(key, value) {
|
||||
return '?' + key + '=' + value;
|
||||
#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 (
|
||||
(window.location.pathname || '') +
|
||||
this.#queryString.fullStringWithNewParam(k, v)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return HtmlReporterV2;
|
||||
};
|
||||
|
||||
jasmineRequire.HtmlReporterV2Urls = function(j$) {
|
||||
'use strict';
|
||||
|
||||
// TODO jsdoc
|
||||
class HtmlReporterV2Urls {
|
||||
constructor(options = {}) {
|
||||
// queryString is injectable for use in our own tests, but user code will
|
||||
// not pass any options.
|
||||
this.queryString =
|
||||
options.queryString ||
|
||||
new jasmine.QueryString({
|
||||
getWindowLocation: function() {
|
||||
return window.location;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO jsdoc. This is public.
|
||||
configFromCurrentUrl() {
|
||||
const config = {
|
||||
stopOnSpecFailure: this.queryString.getParam('stopOnSpecFailure'),
|
||||
stopSpecOnExpectationFailure: this.queryString.getParam(
|
||||
'stopSpecOnExpectationFailure'
|
||||
),
|
||||
hideDisabled: this.queryString.getParam('hideDisabled')
|
||||
};
|
||||
|
||||
const random = this.queryString.getParam('random');
|
||||
|
||||
if (random !== undefined && random !== '') {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
const seed = this.queryString.getParam('seed');
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
|
||||
const specFilter = new j$.private.HtmlSpecFilterV2({
|
||||
filterString: () => {
|
||||
return this.queryString.getParam('spec');
|
||||
}
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
filteringSpecs() {
|
||||
return !!this.queryString.getParam('spec');
|
||||
}
|
||||
}
|
||||
|
||||
return HtmlReporterV2Urls;
|
||||
};
|
||||
|
||||
jasmineRequire.HtmlSpecFilterV2 = function() {
|
||||
'use strict';
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ describe('The jasmine namespace', function() {
|
||||
// jasmine-html.js
|
||||
result.add('HtmlReporter');
|
||||
result.add('HtmlReporterV2');
|
||||
result.add('HtmlReporterV2Urls');
|
||||
result.add('HtmlSpecFilter');
|
||||
result.add('HtmlSpecFilterV2');
|
||||
result.add('QueryString');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
describe('HtmlReporterV2', function() {
|
||||
let env, container;
|
||||
let env, container, location;
|
||||
|
||||
beforeEach(function() {
|
||||
container = document.createElement('div');
|
||||
env = new privateUnderTest.Env();
|
||||
location = { search: '' };
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
@@ -12,10 +13,14 @@ describe('HtmlReporterV2', function() {
|
||||
|
||||
function setup(options = {}) {
|
||||
return new jasmineUnderTest.HtmlReporterV2({
|
||||
env: env,
|
||||
getContainer() {
|
||||
return container;
|
||||
},
|
||||
env,
|
||||
container,
|
||||
urls: new jasmineUnderTest.HtmlReporterV2Urls(),
|
||||
queryString: new jasmineUnderTest.QueryString({
|
||||
getWindowLocation() {
|
||||
return location;
|
||||
}
|
||||
}),
|
||||
...options
|
||||
});
|
||||
}
|
||||
@@ -426,7 +431,7 @@ describe('HtmlReporterV2', function() {
|
||||
const suiteDetail = outerSuite.childNodes[0];
|
||||
const suiteLink = suiteDetail.childNodes[0];
|
||||
expect(suiteLink.innerHTML).toEqual('A Suite');
|
||||
expect(suiteLink.getAttribute('href')).toEqual('/?foo=bar&spec=A Suite');
|
||||
expect(suiteLink.getAttribute('href')).toEqual('/?spec=A%20Suite');
|
||||
|
||||
const specs = outerSuite.childNodes[1];
|
||||
const spec = specs.childNodes[0];
|
||||
@@ -436,7 +441,7 @@ describe('HtmlReporterV2', function() {
|
||||
const specLink = spec.childNodes[0];
|
||||
expect(specLink.innerHTML).toEqual('with a spec');
|
||||
expect(specLink.getAttribute('href')).toEqual(
|
||||
'/?foo=bar&spec=A Suite with a spec'
|
||||
'/?spec=A%20Suite%20with%20a%20spec'
|
||||
);
|
||||
|
||||
const specDuration = spec.childNodes[1];
|
||||
@@ -578,10 +583,7 @@ describe('HtmlReporterV2', function() {
|
||||
});
|
||||
|
||||
it('should navigate and turn the setting on', function() {
|
||||
const navigationHandler = jasmine.createSpy('navigate');
|
||||
const reporter = setup({
|
||||
navigateWithNewParam: navigationHandler
|
||||
});
|
||||
const reporter = setup();
|
||||
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
@@ -589,18 +591,11 @@ describe('HtmlReporterV2', function() {
|
||||
const stopOnFailureUI = container.querySelector('.jasmine-fail-fast');
|
||||
stopOnFailureUI.click();
|
||||
|
||||
expect(navigationHandler).toHaveBeenCalledWith(
|
||||
'stopOnSpecFailure',
|
||||
true
|
||||
);
|
||||
expect(location.search).toEqual('?stopOnSpecFailure=true');
|
||||
});
|
||||
|
||||
it('should navigate and turn the setting off', function() {
|
||||
const navigationHandler = jasmine.createSpy('navigate');
|
||||
const reporter = setup({
|
||||
navigateWithNewParam: navigationHandler
|
||||
});
|
||||
|
||||
const reporter = setup();
|
||||
env.configure({ stopOnSpecFailure: true });
|
||||
|
||||
reporter.initialize();
|
||||
@@ -609,10 +604,7 @@ describe('HtmlReporterV2', function() {
|
||||
const stopOnFailureUI = container.querySelector('.jasmine-fail-fast');
|
||||
stopOnFailureUI.click();
|
||||
|
||||
expect(navigationHandler).toHaveBeenCalledWith(
|
||||
'stopOnSpecFailure',
|
||||
false
|
||||
);
|
||||
expect(location.search).toEqual('?stopOnSpecFailure=false');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -642,11 +634,7 @@ describe('HtmlReporterV2', function() {
|
||||
});
|
||||
|
||||
it('should navigate and change the setting to on', function() {
|
||||
const navigateHandler = jasmine.createSpy('navigate');
|
||||
const reporter = setup({
|
||||
navigateWithNewParam: navigateHandler
|
||||
});
|
||||
|
||||
const reporter = setup();
|
||||
reporter.initialize();
|
||||
reporter.jasmineDone({});
|
||||
|
||||
@@ -655,17 +643,11 @@ describe('HtmlReporterV2', function() {
|
||||
);
|
||||
throwingExpectationsUI.click();
|
||||
|
||||
expect(navigateHandler).toHaveBeenCalledWith(
|
||||
'stopSpecOnExpectationFailure',
|
||||
true
|
||||
);
|
||||
expect(location.search).toEqual('?stopSpecOnExpectationFailure=true');
|
||||
});
|
||||
|
||||
it('should navigate and change the setting to off', function() {
|
||||
const navigateHandler = jasmine.createSpy('navigate');
|
||||
const reporter = setup({
|
||||
navigateWithNewParam: navigateHandler
|
||||
});
|
||||
const reporter = setup();
|
||||
|
||||
env.configure({ stopSpecOnExpectationFailure: true });
|
||||
|
||||
@@ -677,10 +659,7 @@ describe('HtmlReporterV2', function() {
|
||||
);
|
||||
throwingExpectationsUI.click();
|
||||
|
||||
expect(navigateHandler).toHaveBeenCalledWith(
|
||||
'stopSpecOnExpectationFailure',
|
||||
false
|
||||
);
|
||||
expect(location.search).toEqual('?stopSpecOnExpectationFailure=false');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -746,10 +725,7 @@ describe('HtmlReporterV2', function() {
|
||||
});
|
||||
|
||||
it('should navigate and change the setting to on', function() {
|
||||
const navigateHandler = jasmine.createSpy('navigate');
|
||||
const reporter = setup({
|
||||
navigateWithNewParam: navigateHandler
|
||||
});
|
||||
const reporter = setup();
|
||||
|
||||
env.configure({ random: false });
|
||||
reporter.initialize();
|
||||
@@ -758,14 +734,11 @@ describe('HtmlReporterV2', function() {
|
||||
const randomUI = container.querySelector('.jasmine-random');
|
||||
randomUI.click();
|
||||
|
||||
expect(navigateHandler).toHaveBeenCalledWith('random', true);
|
||||
expect(location.search).toEqual('?random=true');
|
||||
});
|
||||
|
||||
it('should navigate and change the setting to off', function() {
|
||||
const navigateHandler = jasmine.createSpy('navigate');
|
||||
const reporter = setup({
|
||||
navigateWithNewParam: navigateHandler
|
||||
});
|
||||
const reporter = setup();
|
||||
|
||||
env.configure({ random: true });
|
||||
reporter.initialize();
|
||||
@@ -774,7 +747,7 @@ describe('HtmlReporterV2', function() {
|
||||
const randomUI = container.querySelector('.jasmine-random');
|
||||
randomUI.click();
|
||||
|
||||
expect(navigateHandler).toHaveBeenCalledWith('random', false);
|
||||
expect(location.search).toEqual('?random=false');
|
||||
});
|
||||
|
||||
it('should show the seed bar if randomizing', function() {
|
||||
@@ -814,7 +787,7 @@ describe('HtmlReporterV2', function() {
|
||||
reporter.jasmineDone({ order: { random: true } });
|
||||
|
||||
const skippedLink = container.querySelector('.jasmine-skipped a');
|
||||
expect(skippedLink.getAttribute('href')).toEqual('/?foo=bar&spec=');
|
||||
expect(skippedLink.getAttribute('href')).toEqual('/?spec=');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -882,7 +855,11 @@ describe('HtmlReporterV2', function() {
|
||||
describe('when the specs are not filtered', function() {
|
||||
beforeEach(function() {
|
||||
reporter = setup({
|
||||
filterSpecs: false
|
||||
urls: {
|
||||
filteringSpecs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
reporter.initialize();
|
||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||
@@ -900,7 +877,13 @@ describe('HtmlReporterV2', function() {
|
||||
|
||||
describe('when the specs are filtered', function() {
|
||||
beforeEach(function() {
|
||||
reporter = setup({ filterSpecs: true });
|
||||
reporter = setup({
|
||||
urls: {
|
||||
filteringSpecs() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
reporter.initialize();
|
||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||
reporter.specStarted(specStatus);
|
||||
@@ -990,11 +973,7 @@ describe('HtmlReporterV2', function() {
|
||||
let reporter;
|
||||
|
||||
beforeEach(function() {
|
||||
reporter = setup({
|
||||
addToExistingQueryString: function(key, value) {
|
||||
return '?foo=bar&' + key + '=' + value;
|
||||
}
|
||||
});
|
||||
reporter = setup();
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||
@@ -1141,16 +1120,16 @@ describe('HtmlReporterV2', function() {
|
||||
expect(links.length).toEqual(3);
|
||||
expect(links[0].textContent).toEqual('A suite');
|
||||
|
||||
expect(links[0].getAttribute('href')).toMatch(/\?foo=bar&spec=A suite/);
|
||||
expect(links[0].getAttribute('href')).toMatch(/\?spec=A%20suite/);
|
||||
|
||||
expect(links[1].textContent).toEqual('inner suite');
|
||||
expect(links[1].getAttribute('href')).toMatch(
|
||||
/\?foo=bar&spec=A suite inner suite/
|
||||
/\?spec=A%20suite%20inner%20suite/
|
||||
);
|
||||
|
||||
expect(links[2].textContent).toEqual('a failing spec');
|
||||
expect(links[2].getAttribute('href')).toMatch(
|
||||
/\?foo=bar&spec=a suite inner suite a failing spec/
|
||||
/\?spec=a%20suite%20inner%20suite%20a%20failing%20spec/
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
67
spec/html/HtmlReporterV2UrlsSpec.js
Normal file
67
spec/html/HtmlReporterV2UrlsSpec.js
Normal file
@@ -0,0 +1,67 @@
|
||||
describe('HtmlReporterV2Urls', function() {
|
||||
describe('#configFromCurrentUrl', function() {
|
||||
passesThroughQueryParam('stopOnSpecFailure');
|
||||
passesThroughQueryParam('stopSpecOnExpectationFailure');
|
||||
passesThroughQueryParam('hideDisabled');
|
||||
passesThroughQueryParam('random');
|
||||
ignoresEmpty('random');
|
||||
passesThroughQueryParam('seed');
|
||||
ignoresEmpty('seed');
|
||||
|
||||
it('configures a matching spec filter', function() {
|
||||
const queryString = mockQueryString();
|
||||
queryString.getParam.withArgs('spec').and.returnValue('foo');
|
||||
const subject = new jasmineUnderTest.HtmlReporterV2Urls({ queryString });
|
||||
const config = subject.configFromCurrentUrl();
|
||||
const matching = {
|
||||
getFullName() {
|
||||
return 'foobar';
|
||||
}
|
||||
};
|
||||
const nonMatching = {
|
||||
getFullName() {
|
||||
return 'baz';
|
||||
}
|
||||
};
|
||||
expect(config.specFilter(matching)).toEqual(true);
|
||||
expect(config.specFilter(nonMatching)).toEqual(false);
|
||||
});
|
||||
|
||||
function passesThroughQueryParam(k) {
|
||||
it(`sets config.${k} to undefined when ${k} is not in the query string`, function() {
|
||||
const queryString = mockQueryString();
|
||||
queryString.getParam.withArgs(k).and.returnValue(undefined);
|
||||
const subject = new jasmineUnderTest.HtmlReporterV2Urls({
|
||||
queryString
|
||||
});
|
||||
expect(subject.configFromCurrentUrl()[k]).toBeUndefined();
|
||||
});
|
||||
|
||||
it(`sets config.${k} to the ${k} query param`, function() {
|
||||
const queryString = mockQueryString();
|
||||
queryString.getParam.withArgs(k).and.returnValue('someval');
|
||||
const subject = new jasmineUnderTest.HtmlReporterV2Urls({
|
||||
queryString
|
||||
});
|
||||
expect(subject.configFromCurrentUrl()[k]).toEqual('someval');
|
||||
});
|
||||
}
|
||||
|
||||
function ignoresEmpty(k) {
|
||||
it(`sets config.${k} to undefined when the ${k} query param is empty`, function() {
|
||||
const queryString = mockQueryString();
|
||||
queryString.getParam.withArgs(k).and.returnValue(undefined);
|
||||
const subject = new jasmineUnderTest.HtmlReporterV2Urls({
|
||||
queryString
|
||||
});
|
||||
expect(subject.configFromCurrentUrl()[k]).toBeUndefined();
|
||||
});
|
||||
}
|
||||
|
||||
function mockQueryString() {
|
||||
const qs = jasmine.createSpyObj('queryString', ['getParam']);
|
||||
qs.getParam.and.returnValue('NOT STUBBED');
|
||||
return qs;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
describe('HtmlSpecFilterV2', function() {
|
||||
it('should match when no string is provided', function() {
|
||||
const specFilter = new jasmineUnderTest.HtmlSpecFilterV2();
|
||||
const specFilter = new privateUnderTest.HtmlSpecFilterV2();
|
||||
|
||||
expect(specFilter.matches('foo')).toBe(true);
|
||||
expect(specFilter.matches('*bar')).toBe(true);
|
||||
});
|
||||
|
||||
it('should only match the provided string', function() {
|
||||
const specFilter = new jasmineUnderTest.HtmlSpecFilterV2({
|
||||
const specFilter = new privateUnderTest.HtmlSpecFilterV2({
|
||||
filterString: function() {
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
@@ -15,57 +15,16 @@
|
||||
|
||||
(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(
|
||||
'stopSpecOnExpectationFailure'
|
||||
),
|
||||
hideDisabled: queryString.getParam('hideDisabled')
|
||||
};
|
||||
|
||||
const random = queryString.getParam('random');
|
||||
|
||||
if (random !== undefined && random !== '') {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
const seed = queryString.getParam('seed');
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
const urls = new jasmine.HtmlReporterV2Urls();
|
||||
|
||||
/**
|
||||
* ## Reporters
|
||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||
*/
|
||||
const htmlReporter = new jasmine.HtmlReporterV2({
|
||||
env: env,
|
||||
navigateWithNewParam: function(key, value) {
|
||||
return queryString.navigateWithNewParam(key, value);
|
||||
},
|
||||
addToExistingQueryString: function(key, value) {
|
||||
return queryString.fullStringWithNewParam(key, value);
|
||||
},
|
||||
getContainer: function() {
|
||||
return document.body;
|
||||
},
|
||||
timer: new jasmine.Timer(),
|
||||
filterSpecs: filterSpecs
|
||||
env,
|
||||
urls,
|
||||
container: document.body
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -73,21 +32,7 @@
|
||||
*/
|
||||
env.addReporter(jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
/**
|
||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||
*/
|
||||
const specFilter = new jasmine.HtmlSpecFilterV2({
|
||||
filterString: function() {
|
||||
return queryString.getParam('spec');
|
||||
}
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
env.configure(config);
|
||||
env.configure(urls.configFromCurrentUrl());
|
||||
|
||||
/**
|
||||
* ## Execution
|
||||
|
||||
@@ -12,8 +12,8 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
*/
|
||||
class HtmlReporterV2 {
|
||||
#env;
|
||||
#getContainer;
|
||||
#navigateWithNewParam;
|
||||
#container;
|
||||
#queryString;
|
||||
#urlBuilder;
|
||||
#filterSpecs;
|
||||
#stateBuilder;
|
||||
@@ -29,13 +29,16 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
constructor(options) {
|
||||
this.#env = options.env;
|
||||
|
||||
this.#getContainer = options.getContainer;
|
||||
this.#navigateWithNewParam =
|
||||
options.navigateWithNewParam || function() {};
|
||||
this.#urlBuilder = new UrlBuilder(
|
||||
options.addToExistingQueryString || defaultQueryString
|
||||
);
|
||||
this.#filterSpecs = options.filterSpecs;
|
||||
this.#container = options.container;
|
||||
this.#queryString =
|
||||
options.queryString ||
|
||||
new j$.QueryString({
|
||||
getWindowLocation() {
|
||||
return window.location;
|
||||
}
|
||||
});
|
||||
this.#urlBuilder = new UrlBuilder(this.#queryString);
|
||||
this.#filterSpecs = options.urls.filteringSpecs();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +54,9 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
|
||||
this.#alerts = new j$.private.AlertsView(this.#urlBuilder);
|
||||
this.#symbols = new j$.private.SymbolsView();
|
||||
this.#banner = new j$.private.Banner(this.#navigateWithNewParam);
|
||||
this.#banner = new j$.private.Banner(
|
||||
this.#queryString.navigateWithNewParam.bind(this.#queryString)
|
||||
);
|
||||
this.#failures = new j$.private.FailuresView(this.#urlBuilder);
|
||||
this.#htmlReporterMain = createDom(
|
||||
'div',
|
||||
@@ -61,7 +66,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
this.#alerts.rootEl,
|
||||
this.#failures.rootEl
|
||||
);
|
||||
this.#getContainer().appendChild(this.#htmlReporterMain);
|
||||
this.#container.appendChild(this.#htmlReporterMain);
|
||||
}
|
||||
|
||||
jasmineStarted(options) {
|
||||
@@ -148,7 +153,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
}
|
||||
|
||||
#find(selector) {
|
||||
return this.#getContainer().querySelector(
|
||||
return this.#container.querySelector(
|
||||
'.jasmine_html-reporter ' + selector
|
||||
);
|
||||
}
|
||||
@@ -157,7 +162,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
const oldReporter = this.#find('');
|
||||
|
||||
if (oldReporter) {
|
||||
this.#getContainer().removeChild(oldReporter);
|
||||
this.#container.removeChild(oldReporter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,15 +175,10 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
}
|
||||
|
||||
class UrlBuilder {
|
||||
#addToExistingQueryString;
|
||||
#queryString;
|
||||
|
||||
constructor(addToExistingQueryString) {
|
||||
this.#addToExistingQueryString = function(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 (
|
||||
(window.location.pathname || '') + addToExistingQueryString(k, v)
|
||||
);
|
||||
};
|
||||
constructor(queryString) {
|
||||
this.#queryString = queryString;
|
||||
}
|
||||
|
||||
suiteHref(suite) {
|
||||
@@ -203,10 +203,14 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
||||
seedHref(seed) {
|
||||
return this.#addToExistingQueryString('seed', seed);
|
||||
}
|
||||
}
|
||||
|
||||
function defaultQueryString(key, value) {
|
||||
return '?' + key + '=' + value;
|
||||
#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 (
|
||||
(window.location.pathname || '') +
|
||||
this.#queryString.fullStringWithNewParam(k, v)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return HtmlReporterV2;
|
||||
|
||||
58
src/html/HtmlReporterV2Urls.js
Normal file
58
src/html/HtmlReporterV2Urls.js
Normal file
@@ -0,0 +1,58 @@
|
||||
jasmineRequire.HtmlReporterV2Urls = function(j$) {
|
||||
'use strict';
|
||||
|
||||
// TODO jsdoc
|
||||
class HtmlReporterV2Urls {
|
||||
constructor(options = {}) {
|
||||
// queryString is injectable for use in our own tests, but user code will
|
||||
// not pass any options.
|
||||
this.queryString =
|
||||
options.queryString ||
|
||||
new jasmine.QueryString({
|
||||
getWindowLocation: function() {
|
||||
return window.location;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO jsdoc. This is public.
|
||||
configFromCurrentUrl() {
|
||||
const config = {
|
||||
stopOnSpecFailure: this.queryString.getParam('stopOnSpecFailure'),
|
||||
stopSpecOnExpectationFailure: this.queryString.getParam(
|
||||
'stopSpecOnExpectationFailure'
|
||||
),
|
||||
hideDisabled: this.queryString.getParam('hideDisabled')
|
||||
};
|
||||
|
||||
const random = this.queryString.getParam('random');
|
||||
|
||||
if (random !== undefined && random !== '') {
|
||||
config.random = random;
|
||||
}
|
||||
|
||||
const seed = this.queryString.getParam('seed');
|
||||
if (seed) {
|
||||
config.seed = seed;
|
||||
}
|
||||
|
||||
const specFilter = new j$.private.HtmlSpecFilterV2({
|
||||
filterString: () => {
|
||||
return this.queryString.getParam('spec');
|
||||
}
|
||||
});
|
||||
|
||||
config.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
filteringSpecs() {
|
||||
return !!this.queryString.getParam('spec');
|
||||
}
|
||||
}
|
||||
|
||||
return HtmlReporterV2Urls;
|
||||
};
|
||||
@@ -11,8 +11,9 @@ jasmineRequire.html = function(j$) {
|
||||
j$.private.SummaryTreeView = jasmineRequire.SummaryTreeView(j$);
|
||||
j$.private.FailuresView = jasmineRequire.FailuresView(j$);
|
||||
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
||||
j$.HtmlReporterV2Urls = jasmineRequire.HtmlReporterV2Urls(j$);
|
||||
j$.HtmlReporterV2 = jasmineRequire.HtmlReporterV2(j$);
|
||||
j$.QueryString = jasmineRequire.QueryString();
|
||||
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
||||
j$.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
|
||||
j$.private.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user