The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/plugins/tests/pluginCacheBuster.test.ts

57 lines
2.0 KiB

import { invalidatePluginInCache, locateWithCache, registerPluginInCache } from '../pluginCacheBuster';
import * as pluginSettings from '../pluginSettings';
describe('PluginCacheBuster', () => {
const now = 12345;
it('should append plugin version as cache flag if plugin is registered in buster', () => {
const slug = 'bubble-chart-1';
const version = 'v1.0.0';
const path = resolvePath(slug);
const address = `http://localhost:3000/public/${path}.js`;
registerPluginInCache({ path, version });
const url = `${address}?_cache=${encodeURI(version)}`;
expect(locateWithCache({ address }, now)).toBe(url);
});
it('should append Date.now as cache flag if plugin is not registered in buster', () => {
const slug = 'bubble-chart-2';
const address = `http://localhost:3000/public/${resolvePath(slug)}.js`;
const url = `${address}?_cache=${encodeURI(String(now))}`;
expect(locateWithCache({ address }, now)).toBe(url);
});
it('should append Date.now as cache flag if plugin is invalidated in buster', () => {
const slug = 'bubble-chart-3';
const version = 'v1.0.0';
const path = resolvePath(slug);
const address = `http://localhost:3000/public/${path}.js`;
registerPluginInCache({ path, version });
invalidatePluginInCache(slug);
const url = `${address}?_cache=${encodeURI(String(now))}`;
expect(locateWithCache({ address }, now)).toBe(url);
});
it('should also clear plugin settings cache', () => {
const slug = 'bubble-chart-3';
const version = 'v1.0.0';
const path = resolvePath(slug);
const clearPluginSettingsCacheSpy = jest.spyOn(pluginSettings, 'clearPluginSettingsCache');
registerPluginInCache({ path, version });
invalidatePluginInCache(slug);
expect(clearPluginSettingsCacheSpy).toBeCalledTimes(1);
expect(clearPluginSettingsCacheSpy).toBeCalledWith('bubble-chart-3');
});
});
function resolvePath(slug: string): string {
return `plugins/${slug}/module`;
}