mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: add a bundle plugins folder (#20850)
This commit is contained in:
@@ -27,8 +27,6 @@ const mssqlPlugin = async () =>
|
||||
await import(/* webpackChunkName: "mssqlPlugin" */ 'app/plugins/datasource/mssql/module');
|
||||
const testDataDSPlugin = async () =>
|
||||
await import(/* webpackChunkName: "testDataDSPlugin" */ 'app/plugins/datasource/testdata/module');
|
||||
const inputDatasourcePlugin = async () =>
|
||||
await import(/* webpackChunkName: "inputDatasourcePlugin" */ 'app/plugins/datasource/input/module');
|
||||
const stackdriverPlugin = async () =>
|
||||
await import(/* webpackChunkName: "stackdriverPlugin" */ 'app/plugins/datasource/stackdriver/module');
|
||||
const azureMonitorPlugin = async () =>
|
||||
@@ -73,7 +71,6 @@ const builtInPlugins: any = {
|
||||
'app/plugins/datasource/mssql/module': mssqlPlugin,
|
||||
'app/plugins/datasource/prometheus/module': prometheusPlugin,
|
||||
'app/plugins/datasource/testdata/module': testDataDSPlugin,
|
||||
'app/plugins/datasource/input/module': inputDatasourcePlugin,
|
||||
'app/plugins/datasource/stackdriver/module': stackdriverPlugin,
|
||||
'app/plugins/datasource/grafana-azure-monitor-datasource/module': azureMonitorPlugin,
|
||||
|
||||
|
||||
68
public/app/features/plugins/plugin_loader.test.ts
Normal file
68
public/app/features/plugins/plugin_loader.test.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
// Use the real plugin_loader (stubbed by default)
|
||||
jest.unmock('app/features/plugins/plugin_loader');
|
||||
|
||||
(global as any).ace = {
|
||||
define: jest.fn(),
|
||||
};
|
||||
|
||||
jest.mock('app/core/core', () => {
|
||||
return {
|
||||
coreModule: {
|
||||
directive: jest.fn(),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
import { SystemJS } from '@grafana/runtime';
|
||||
import { AppPluginMeta, PluginMetaInfo, PluginType, AppPlugin } from '@grafana/data';
|
||||
|
||||
// Loaded after the `unmock` abve
|
||||
import { importAppPlugin } from './plugin_loader';
|
||||
|
||||
class MyCustomApp extends AppPlugin {
|
||||
initWasCalled = false;
|
||||
calledTwice = false;
|
||||
|
||||
init(meta: AppPluginMeta) {
|
||||
this.initWasCalled = true;
|
||||
this.calledTwice = this.meta === meta;
|
||||
}
|
||||
}
|
||||
|
||||
describe('Load App', () => {
|
||||
const app = new MyCustomApp();
|
||||
const modulePath = 'my/custom/plugin/module';
|
||||
|
||||
beforeAll(() => {
|
||||
SystemJS.set(modulePath, SystemJS.newModule({ plugin: app }));
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
SystemJS.delete(modulePath);
|
||||
});
|
||||
|
||||
it('should call init and set meta', async () => {
|
||||
const meta: AppPluginMeta = {
|
||||
id: 'test-app',
|
||||
module: modulePath,
|
||||
baseUrl: 'xxx',
|
||||
info: {} as PluginMetaInfo,
|
||||
type: PluginType.app,
|
||||
name: 'test',
|
||||
};
|
||||
|
||||
// Check that we mocked the import OK
|
||||
const m = await SystemJS.import(modulePath);
|
||||
expect(m.plugin).toBe(app);
|
||||
|
||||
const loaded = await importAppPlugin(meta);
|
||||
expect(loaded).toBe(app);
|
||||
expect(app.meta).toBe(meta);
|
||||
expect(app.initWasCalled).toBeTruthy();
|
||||
expect(app.calledTwice).toBeFalsy();
|
||||
|
||||
const again = await importAppPlugin(meta);
|
||||
expect(again).toBe(app);
|
||||
expect(app.calledTwice).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user