Simplify boot1.js

This commit is contained in:
Steve Gravrock
2025-10-08 20:25:53 -07:00
parent fb814b5f94
commit a457cf1b81
10 changed files with 298 additions and 235 deletions

View File

@@ -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');
}

View File

@@ -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/
);
});

View 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;
}
});
});

View File

@@ -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';
}