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() {
|
(function() {
|
||||||
const env = jasmine.getEnv();
|
const env = jasmine.getEnv();
|
||||||
|
const urls = new jasmine.HtmlReporterV2Urls();
|
||||||
/**
|
|
||||||
* ## 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Reporters
|
* ## 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).
|
* 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({
|
const htmlReporter = new jasmine.HtmlReporterV2({
|
||||||
env: env,
|
env,
|
||||||
navigateWithNewParam: function(key, value) {
|
urls,
|
||||||
return queryString.navigateWithNewParam(key, value);
|
container: document.body
|
||||||
},
|
|
||||||
addToExistingQueryString: function(key, value) {
|
|
||||||
return queryString.fullStringWithNewParam(key, value);
|
|
||||||
},
|
|
||||||
getContainer: function() {
|
|
||||||
return document.body;
|
|
||||||
},
|
|
||||||
timer: new jasmine.Timer(),
|
|
||||||
filterSpecs: filterSpecs
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,21 +56,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
*/
|
*/
|
||||||
env.addReporter(jsApiReporter);
|
env.addReporter(jsApiReporter);
|
||||||
env.addReporter(htmlReporter);
|
env.addReporter(htmlReporter);
|
||||||
|
env.configure(urls.configFromCurrentUrl());
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Execution
|
* ## Execution
|
||||||
|
|||||||
@@ -35,10 +35,11 @@ jasmineRequire.html = function(j$) {
|
|||||||
j$.private.SummaryTreeView = jasmineRequire.SummaryTreeView(j$);
|
j$.private.SummaryTreeView = jasmineRequire.SummaryTreeView(j$);
|
||||||
j$.private.FailuresView = jasmineRequire.FailuresView(j$);
|
j$.private.FailuresView = jasmineRequire.FailuresView(j$);
|
||||||
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
||||||
|
j$.HtmlReporterV2Urls = jasmineRequire.HtmlReporterV2Urls(j$);
|
||||||
j$.HtmlReporterV2 = jasmineRequire.HtmlReporterV2(j$);
|
j$.HtmlReporterV2 = jasmineRequire.HtmlReporterV2(j$);
|
||||||
j$.QueryString = jasmineRequire.QueryString();
|
j$.QueryString = jasmineRequire.QueryString();
|
||||||
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
||||||
j$.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
|
j$.private.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmineRequire.HtmlReporter = function(j$) {
|
jasmineRequire.HtmlReporter = function(j$) {
|
||||||
@@ -984,8 +985,8 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
*/
|
*/
|
||||||
class HtmlReporterV2 {
|
class HtmlReporterV2 {
|
||||||
#env;
|
#env;
|
||||||
#getContainer;
|
#container;
|
||||||
#navigateWithNewParam;
|
#queryString;
|
||||||
#urlBuilder;
|
#urlBuilder;
|
||||||
#filterSpecs;
|
#filterSpecs;
|
||||||
#stateBuilder;
|
#stateBuilder;
|
||||||
@@ -1001,13 +1002,16 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.#env = options.env;
|
this.#env = options.env;
|
||||||
|
|
||||||
this.#getContainer = options.getContainer;
|
this.#container = options.container;
|
||||||
this.#navigateWithNewParam =
|
this.#queryString =
|
||||||
options.navigateWithNewParam || function() {};
|
options.queryString ||
|
||||||
this.#urlBuilder = new UrlBuilder(
|
new j$.QueryString({
|
||||||
options.addToExistingQueryString || defaultQueryString
|
getWindowLocation() {
|
||||||
);
|
return window.location;
|
||||||
this.#filterSpecs = options.filterSpecs;
|
}
|
||||||
|
});
|
||||||
|
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.#alerts = new j$.private.AlertsView(this.#urlBuilder);
|
||||||
this.#symbols = new j$.private.SymbolsView();
|
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.#failures = new j$.private.FailuresView(this.#urlBuilder);
|
||||||
this.#htmlReporterMain = createDom(
|
this.#htmlReporterMain = createDom(
|
||||||
'div',
|
'div',
|
||||||
@@ -1033,7 +1039,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
this.#alerts.rootEl,
|
this.#alerts.rootEl,
|
||||||
this.#failures.rootEl
|
this.#failures.rootEl
|
||||||
);
|
);
|
||||||
this.#getContainer().appendChild(this.#htmlReporterMain);
|
this.#container.appendChild(this.#htmlReporterMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
jasmineStarted(options) {
|
jasmineStarted(options) {
|
||||||
@@ -1120,7 +1126,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#find(selector) {
|
#find(selector) {
|
||||||
return this.#getContainer().querySelector(
|
return this.#container.querySelector(
|
||||||
'.jasmine_html-reporter ' + selector
|
'.jasmine_html-reporter ' + selector
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1129,7 +1135,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
const oldReporter = this.#find('');
|
const oldReporter = this.#find('');
|
||||||
|
|
||||||
if (oldReporter) {
|
if (oldReporter) {
|
||||||
this.#getContainer().removeChild(oldReporter);
|
this.#container.removeChild(oldReporter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1142,15 +1148,10 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class UrlBuilder {
|
class UrlBuilder {
|
||||||
#addToExistingQueryString;
|
#queryString;
|
||||||
|
|
||||||
constructor(addToExistingQueryString) {
|
constructor(queryString) {
|
||||||
this.#addToExistingQueryString = function(k, v) {
|
this.#queryString = queryString;
|
||||||
// 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)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suiteHref(suite) {
|
suiteHref(suite) {
|
||||||
@@ -1175,15 +1176,78 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
seedHref(seed) {
|
seedHref(seed) {
|
||||||
return this.#addToExistingQueryString('seed', seed);
|
return this.#addToExistingQueryString('seed', seed);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function defaultQueryString(key, value) {
|
#addToExistingQueryString(k, v) {
|
||||||
return '?' + key + '=' + value;
|
// 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;
|
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() {
|
jasmineRequire.HtmlSpecFilterV2 = function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ describe('The jasmine namespace', function() {
|
|||||||
// jasmine-html.js
|
// jasmine-html.js
|
||||||
result.add('HtmlReporter');
|
result.add('HtmlReporter');
|
||||||
result.add('HtmlReporterV2');
|
result.add('HtmlReporterV2');
|
||||||
|
result.add('HtmlReporterV2Urls');
|
||||||
result.add('HtmlSpecFilter');
|
result.add('HtmlSpecFilter');
|
||||||
result.add('HtmlSpecFilterV2');
|
|
||||||
result.add('QueryString');
|
result.add('QueryString');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
describe('HtmlReporterV2', function() {
|
describe('HtmlReporterV2', function() {
|
||||||
let env, container;
|
let env, container, location;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
container = document.createElement('div');
|
container = document.createElement('div');
|
||||||
env = new privateUnderTest.Env();
|
env = new privateUnderTest.Env();
|
||||||
|
location = { search: '' };
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
@@ -12,10 +13,14 @@ describe('HtmlReporterV2', function() {
|
|||||||
|
|
||||||
function setup(options = {}) {
|
function setup(options = {}) {
|
||||||
return new jasmineUnderTest.HtmlReporterV2({
|
return new jasmineUnderTest.HtmlReporterV2({
|
||||||
env: env,
|
env,
|
||||||
getContainer() {
|
container,
|
||||||
return container;
|
urls: new jasmineUnderTest.HtmlReporterV2Urls(),
|
||||||
},
|
queryString: new jasmineUnderTest.QueryString({
|
||||||
|
getWindowLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}),
|
||||||
...options
|
...options
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -426,7 +431,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
const suiteDetail = outerSuite.childNodes[0];
|
const suiteDetail = outerSuite.childNodes[0];
|
||||||
const suiteLink = suiteDetail.childNodes[0];
|
const suiteLink = suiteDetail.childNodes[0];
|
||||||
expect(suiteLink.innerHTML).toEqual('A Suite');
|
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 specs = outerSuite.childNodes[1];
|
||||||
const spec = specs.childNodes[0];
|
const spec = specs.childNodes[0];
|
||||||
@@ -436,7 +441,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
const specLink = spec.childNodes[0];
|
const specLink = spec.childNodes[0];
|
||||||
expect(specLink.innerHTML).toEqual('with a spec');
|
expect(specLink.innerHTML).toEqual('with a spec');
|
||||||
expect(specLink.getAttribute('href')).toEqual(
|
expect(specLink.getAttribute('href')).toEqual(
|
||||||
'/?foo=bar&spec=A Suite with a spec'
|
'/?spec=A%20Suite%20with%20a%20spec'
|
||||||
);
|
);
|
||||||
|
|
||||||
const specDuration = spec.childNodes[1];
|
const specDuration = spec.childNodes[1];
|
||||||
@@ -578,10 +583,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and turn the setting on', function() {
|
it('should navigate and turn the setting on', function() {
|
||||||
const navigationHandler = jasmine.createSpy('navigate');
|
const reporter = setup();
|
||||||
const reporter = setup({
|
|
||||||
navigateWithNewParam: navigationHandler
|
|
||||||
});
|
|
||||||
|
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
reporter.jasmineDone({});
|
reporter.jasmineDone({});
|
||||||
@@ -589,18 +591,11 @@ describe('HtmlReporterV2', function() {
|
|||||||
const stopOnFailureUI = container.querySelector('.jasmine-fail-fast');
|
const stopOnFailureUI = container.querySelector('.jasmine-fail-fast');
|
||||||
stopOnFailureUI.click();
|
stopOnFailureUI.click();
|
||||||
|
|
||||||
expect(navigationHandler).toHaveBeenCalledWith(
|
expect(location.search).toEqual('?stopOnSpecFailure=true');
|
||||||
'stopOnSpecFailure',
|
|
||||||
true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and turn the setting off', function() {
|
it('should navigate and turn the setting off', function() {
|
||||||
const navigationHandler = jasmine.createSpy('navigate');
|
const reporter = setup();
|
||||||
const reporter = setup({
|
|
||||||
navigateWithNewParam: navigationHandler
|
|
||||||
});
|
|
||||||
|
|
||||||
env.configure({ stopOnSpecFailure: true });
|
env.configure({ stopOnSpecFailure: true });
|
||||||
|
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
@@ -609,10 +604,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
const stopOnFailureUI = container.querySelector('.jasmine-fail-fast');
|
const stopOnFailureUI = container.querySelector('.jasmine-fail-fast');
|
||||||
stopOnFailureUI.click();
|
stopOnFailureUI.click();
|
||||||
|
|
||||||
expect(navigationHandler).toHaveBeenCalledWith(
|
expect(location.search).toEqual('?stopOnSpecFailure=false');
|
||||||
'stopOnSpecFailure',
|
|
||||||
false
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -642,11 +634,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and change the setting to on', function() {
|
it('should navigate and change the setting to on', function() {
|
||||||
const navigateHandler = jasmine.createSpy('navigate');
|
const reporter = setup();
|
||||||
const reporter = setup({
|
|
||||||
navigateWithNewParam: navigateHandler
|
|
||||||
});
|
|
||||||
|
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
reporter.jasmineDone({});
|
reporter.jasmineDone({});
|
||||||
|
|
||||||
@@ -655,17 +643,11 @@ describe('HtmlReporterV2', function() {
|
|||||||
);
|
);
|
||||||
throwingExpectationsUI.click();
|
throwingExpectationsUI.click();
|
||||||
|
|
||||||
expect(navigateHandler).toHaveBeenCalledWith(
|
expect(location.search).toEqual('?stopSpecOnExpectationFailure=true');
|
||||||
'stopSpecOnExpectationFailure',
|
|
||||||
true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and change the setting to off', function() {
|
it('should navigate and change the setting to off', function() {
|
||||||
const navigateHandler = jasmine.createSpy('navigate');
|
const reporter = setup();
|
||||||
const reporter = setup({
|
|
||||||
navigateWithNewParam: navigateHandler
|
|
||||||
});
|
|
||||||
|
|
||||||
env.configure({ stopSpecOnExpectationFailure: true });
|
env.configure({ stopSpecOnExpectationFailure: true });
|
||||||
|
|
||||||
@@ -677,10 +659,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
);
|
);
|
||||||
throwingExpectationsUI.click();
|
throwingExpectationsUI.click();
|
||||||
|
|
||||||
expect(navigateHandler).toHaveBeenCalledWith(
|
expect(location.search).toEqual('?stopSpecOnExpectationFailure=false');
|
||||||
'stopSpecOnExpectationFailure',
|
|
||||||
false
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -746,10 +725,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and change the setting to on', function() {
|
it('should navigate and change the setting to on', function() {
|
||||||
const navigateHandler = jasmine.createSpy('navigate');
|
const reporter = setup();
|
||||||
const reporter = setup({
|
|
||||||
navigateWithNewParam: navigateHandler
|
|
||||||
});
|
|
||||||
|
|
||||||
env.configure({ random: false });
|
env.configure({ random: false });
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
@@ -758,14 +734,11 @@ describe('HtmlReporterV2', function() {
|
|||||||
const randomUI = container.querySelector('.jasmine-random');
|
const randomUI = container.querySelector('.jasmine-random');
|
||||||
randomUI.click();
|
randomUI.click();
|
||||||
|
|
||||||
expect(navigateHandler).toHaveBeenCalledWith('random', true);
|
expect(location.search).toEqual('?random=true');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should navigate and change the setting to off', function() {
|
it('should navigate and change the setting to off', function() {
|
||||||
const navigateHandler = jasmine.createSpy('navigate');
|
const reporter = setup();
|
||||||
const reporter = setup({
|
|
||||||
navigateWithNewParam: navigateHandler
|
|
||||||
});
|
|
||||||
|
|
||||||
env.configure({ random: true });
|
env.configure({ random: true });
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
@@ -774,7 +747,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
const randomUI = container.querySelector('.jasmine-random');
|
const randomUI = container.querySelector('.jasmine-random');
|
||||||
randomUI.click();
|
randomUI.click();
|
||||||
|
|
||||||
expect(navigateHandler).toHaveBeenCalledWith('random', false);
|
expect(location.search).toEqual('?random=false');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show the seed bar if randomizing', function() {
|
it('should show the seed bar if randomizing', function() {
|
||||||
@@ -814,7 +787,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
reporter.jasmineDone({ order: { random: true } });
|
reporter.jasmineDone({ order: { random: true } });
|
||||||
|
|
||||||
const skippedLink = container.querySelector('.jasmine-skipped a');
|
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() {
|
describe('when the specs are not filtered', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
reporter = setup({
|
reporter = setup({
|
||||||
filterSpecs: false
|
urls: {
|
||||||
|
filteringSpecs() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||||
@@ -900,7 +877,13 @@ describe('HtmlReporterV2', function() {
|
|||||||
|
|
||||||
describe('when the specs are filtered', function() {
|
describe('when the specs are filtered', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
reporter = setup({ filterSpecs: true });
|
reporter = setup({
|
||||||
|
urls: {
|
||||||
|
filteringSpecs() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||||
reporter.specStarted(specStatus);
|
reporter.specStarted(specStatus);
|
||||||
@@ -990,11 +973,7 @@ describe('HtmlReporterV2', function() {
|
|||||||
let reporter;
|
let reporter;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
reporter = setup({
|
reporter = setup();
|
||||||
addToExistingQueryString: function(key, value) {
|
|
||||||
return '?foo=bar&' + key + '=' + value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
reporter.initialize();
|
reporter.initialize();
|
||||||
|
|
||||||
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
reporter.jasmineStarted({ totalSpecsDefined: 1 });
|
||||||
@@ -1141,16 +1120,16 @@ describe('HtmlReporterV2', function() {
|
|||||||
expect(links.length).toEqual(3);
|
expect(links.length).toEqual(3);
|
||||||
expect(links[0].textContent).toEqual('A suite');
|
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].textContent).toEqual('inner suite');
|
||||||
expect(links[1].getAttribute('href')).toMatch(
|
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].textContent).toEqual('a failing spec');
|
||||||
expect(links[2].getAttribute('href')).toMatch(
|
expect(links[2].getAttribute('href')).toMatch(
|
||||||
/\?foo=bar&spec=a suite inner suite a failing spec/
|
/\?spec=a%20suite%20inner%20suite%20a%20failing%20spec/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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() {
|
describe('HtmlSpecFilterV2', function() {
|
||||||
it('should match when no string is provided', 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('foo')).toBe(true);
|
||||||
expect(specFilter.matches('*bar')).toBe(true);
|
expect(specFilter.matches('*bar')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should only match the provided string', function() {
|
it('should only match the provided string', function() {
|
||||||
const specFilter = new jasmineUnderTest.HtmlSpecFilterV2({
|
const specFilter = new privateUnderTest.HtmlSpecFilterV2({
|
||||||
filterString: function() {
|
filterString: function() {
|
||||||
return 'foo';
|
return 'foo';
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-60
@@ -15,57 +15,16 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
const env = jasmine.getEnv();
|
const env = jasmine.getEnv();
|
||||||
|
const urls = new jasmine.HtmlReporterV2Urls();
|
||||||
/**
|
|
||||||
* ## 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Reporters
|
* ## 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).
|
* 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({
|
const htmlReporter = new jasmine.HtmlReporterV2({
|
||||||
env: env,
|
env,
|
||||||
navigateWithNewParam: function(key, value) {
|
urls,
|
||||||
return queryString.navigateWithNewParam(key, value);
|
container: document.body
|
||||||
},
|
|
||||||
addToExistingQueryString: function(key, value) {
|
|
||||||
return queryString.fullStringWithNewParam(key, value);
|
|
||||||
},
|
|
||||||
getContainer: function() {
|
|
||||||
return document.body;
|
|
||||||
},
|
|
||||||
timer: new jasmine.Timer(),
|
|
||||||
filterSpecs: filterSpecs
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,21 +32,7 @@
|
|||||||
*/
|
*/
|
||||||
env.addReporter(jsApiReporter);
|
env.addReporter(jsApiReporter);
|
||||||
env.addReporter(htmlReporter);
|
env.addReporter(htmlReporter);
|
||||||
|
env.configure(urls.configFromCurrentUrl());
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Execution
|
* ## Execution
|
||||||
|
|||||||
+28
-24
@@ -12,8 +12,8 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
*/
|
*/
|
||||||
class HtmlReporterV2 {
|
class HtmlReporterV2 {
|
||||||
#env;
|
#env;
|
||||||
#getContainer;
|
#container;
|
||||||
#navigateWithNewParam;
|
#queryString;
|
||||||
#urlBuilder;
|
#urlBuilder;
|
||||||
#filterSpecs;
|
#filterSpecs;
|
||||||
#stateBuilder;
|
#stateBuilder;
|
||||||
@@ -29,13 +29,16 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.#env = options.env;
|
this.#env = options.env;
|
||||||
|
|
||||||
this.#getContainer = options.getContainer;
|
this.#container = options.container;
|
||||||
this.#navigateWithNewParam =
|
this.#queryString =
|
||||||
options.navigateWithNewParam || function() {};
|
options.queryString ||
|
||||||
this.#urlBuilder = new UrlBuilder(
|
new j$.QueryString({
|
||||||
options.addToExistingQueryString || defaultQueryString
|
getWindowLocation() {
|
||||||
);
|
return window.location;
|
||||||
this.#filterSpecs = options.filterSpecs;
|
}
|
||||||
|
});
|
||||||
|
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.#alerts = new j$.private.AlertsView(this.#urlBuilder);
|
||||||
this.#symbols = new j$.private.SymbolsView();
|
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.#failures = new j$.private.FailuresView(this.#urlBuilder);
|
||||||
this.#htmlReporterMain = createDom(
|
this.#htmlReporterMain = createDom(
|
||||||
'div',
|
'div',
|
||||||
@@ -61,7 +66,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
this.#alerts.rootEl,
|
this.#alerts.rootEl,
|
||||||
this.#failures.rootEl
|
this.#failures.rootEl
|
||||||
);
|
);
|
||||||
this.#getContainer().appendChild(this.#htmlReporterMain);
|
this.#container.appendChild(this.#htmlReporterMain);
|
||||||
}
|
}
|
||||||
|
|
||||||
jasmineStarted(options) {
|
jasmineStarted(options) {
|
||||||
@@ -148,7 +153,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#find(selector) {
|
#find(selector) {
|
||||||
return this.#getContainer().querySelector(
|
return this.#container.querySelector(
|
||||||
'.jasmine_html-reporter ' + selector
|
'.jasmine_html-reporter ' + selector
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -157,7 +162,7 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
const oldReporter = this.#find('');
|
const oldReporter = this.#find('');
|
||||||
|
|
||||||
if (oldReporter) {
|
if (oldReporter) {
|
||||||
this.#getContainer().removeChild(oldReporter);
|
this.#container.removeChild(oldReporter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,15 +175,10 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class UrlBuilder {
|
class UrlBuilder {
|
||||||
#addToExistingQueryString;
|
#queryString;
|
||||||
|
|
||||||
constructor(addToExistingQueryString) {
|
constructor(queryString) {
|
||||||
this.#addToExistingQueryString = function(k, v) {
|
this.#queryString = queryString;
|
||||||
// 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)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suiteHref(suite) {
|
suiteHref(suite) {
|
||||||
@@ -203,10 +203,14 @@ jasmineRequire.HtmlReporterV2 = function(j$) {
|
|||||||
seedHref(seed) {
|
seedHref(seed) {
|
||||||
return this.#addToExistingQueryString('seed', seed);
|
return this.#addToExistingQueryString('seed', seed);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function defaultQueryString(key, value) {
|
#addToExistingQueryString(k, v) {
|
||||||
return '?' + key + '=' + value;
|
// 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;
|
return HtmlReporterV2;
|
||||||
|
|||||||
@@ -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.SummaryTreeView = jasmineRequire.SummaryTreeView(j$);
|
||||||
j$.private.FailuresView = jasmineRequire.FailuresView(j$);
|
j$.private.FailuresView = jasmineRequire.FailuresView(j$);
|
||||||
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
||||||
|
j$.HtmlReporterV2Urls = jasmineRequire.HtmlReporterV2Urls(j$);
|
||||||
j$.HtmlReporterV2 = jasmineRequire.HtmlReporterV2(j$);
|
j$.HtmlReporterV2 = jasmineRequire.HtmlReporterV2(j$);
|
||||||
j$.QueryString = jasmineRequire.QueryString();
|
j$.QueryString = jasmineRequire.QueryString();
|
||||||
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
||||||
j$.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
|
j$.private.HtmlSpecFilterV2 = jasmineRequire.HtmlSpecFilterV2();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user