This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
81 lines
2.4 KiB
JavaScript
81 lines
2.4 KiB
JavaScript
import IconImage from '../../../../src/ol/style/IconImage.js';
|
|
import {VOID} from '../../../../src/ol/functions.js';
|
|
import {shared as iconImageCache} from '../../../../src/ol/style/IconImageCache.js';
|
|
import {listen} from '../../../../src/ol/events.js';
|
|
|
|
describe('ol.style.IconImageCache', function () {
|
|
let originalMaxCacheSize;
|
|
|
|
beforeEach(function () {
|
|
iconImageCache.clear();
|
|
originalMaxCacheSize = iconImageCache.maxCacheSize;
|
|
iconImageCache.maxCacheSize_ = 4;
|
|
});
|
|
|
|
afterEach(function () {
|
|
iconImageCache.maxCacheSize_ = originalMaxCacheSize;
|
|
iconImageCache.clear();
|
|
});
|
|
|
|
describe('#expire', function () {
|
|
it('expires images when expected', function () {
|
|
let i, src, iconImage;
|
|
|
|
for (i = 0; i < 4; ++i) {
|
|
src = i + '';
|
|
iconImage = new IconImage(null, src);
|
|
iconImageCache.set(src, null, null, iconImage);
|
|
}
|
|
|
|
expect(iconImageCache.cacheSize_).to.eql(4);
|
|
|
|
iconImageCache.expire();
|
|
expect(iconImageCache.cacheSize_).to.eql(4);
|
|
|
|
src = '4';
|
|
iconImage = new IconImage(null, src);
|
|
iconImageCache.set(src, null, null, iconImage);
|
|
expect(iconImageCache.cacheSize_).to.eql(5);
|
|
|
|
iconImageCache.expire(); // remove '0' and '4'
|
|
expect(iconImageCache.cacheSize_).to.eql(3);
|
|
|
|
src = '0';
|
|
iconImage = new IconImage(null, src);
|
|
listen(iconImage, 'change', VOID, false);
|
|
iconImageCache.set(src, null, null, iconImage);
|
|
expect(iconImageCache.cacheSize_).to.eql(4);
|
|
|
|
src = '4';
|
|
iconImage = new IconImage(null, src);
|
|
listen(iconImage, 'change', VOID, false);
|
|
iconImageCache.set(src, null, null, iconImage);
|
|
expect(iconImageCache.cacheSize_).to.eql(5);
|
|
|
|
// check that '0' and '4' are not removed from the cache
|
|
iconImageCache.expire();
|
|
expect(iconImageCache.get('0', null, null)).to.not.be(null);
|
|
expect(iconImageCache.get('4', null, null)).to.not.be(null);
|
|
});
|
|
});
|
|
|
|
describe('#setSize', function () {
|
|
it('sets max cache size and expires cache', function () {
|
|
let i, src, iconImage;
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
src = i + '';
|
|
iconImage = new IconImage(null, src);
|
|
iconImageCache.set(src, null, null, iconImage);
|
|
}
|
|
|
|
expect(iconImageCache.cacheSize_).to.eql(3);
|
|
|
|
iconImageCache.setSize(2);
|
|
|
|
expect(iconImageCache.maxCacheSize_).to.eql(2);
|
|
expect(iconImageCache.cacheSize_).to.eql(2);
|
|
});
|
|
});
|
|
});
|