grafana/public/test/jest-setup.ts
Marcus Andersson bc7386e815
PluginExtension: Added debug log (#94146)
* wip

* add simple scenes object with logs panel

* return hardcoded log message from runtime ds

* simplify log entry

* use log in links registry

* wired the log together.

* wip

* Connected the extensions log to the runtime datasource to steam logs

* wired the other registies.

* implemented child function.

* set right field type on labels

* set meta type

* using the logger in various places.

* added type of onclick.

* removed time picker.

* removed imports.

* passing log to functions where they are needed.

* moved scene into admin page.

* minor improvement to the message.

* added possibility to update query with values based on the data.

* added filter suppoert.

* wip

* wip

* fixed so extension points are displayed.

* use log level from grafana data

* fixed bugs with the filtering.

* Fixed some logs.

* only register extensions page in development mode.

* fixed filtering.

* added on click debug log.

* PluginExtensions: Add debug log to Grafana (Rewrite to scenes-react) (#93954)

* refactoring.

* simplify it even more.

* Update public/app/features/plugins/extensions/logs/LogViewer.tsx

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>

* used VizGridLayout instead of VizGrid component.

* Fixed feedback and fixed bug in filtering logic.

* fixed another nit.

* empty string instead of title.

* Added tests and fixed error.

* added test file.

* regenerated yarn.lock

* Update public/app/features/plugins/extensions/logs/filterTransformation.test.ts

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>

* fixed nit.

* more nits.

* added more test cases.

* simplified filtering logic.

* removed unused dep.

* defined broadcast channel in jest setup.

* added tests for datasource.

* fixed failed tests.

* fixed tests.

* fixing go lint issue.

* silent go lint.

* fixed lint issue.

---------

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
2024-10-10 09:27:57 +03:00

129 lines
3.4 KiB
TypeScript

// This import has side effects, and must be at the top so jQuery is made global before
// angular is imported.
import './global-jquery-shim';
import angular from 'angular';
import { TextEncoder, TextDecoder } from 'util';
import { EventBusSrv } from '@grafana/data';
import { GrafanaBootConfig } from '@grafana/runtime';
import { initIconCache } from 'app/core/icons/iconBundle';
import 'blob-polyfill';
import 'mutationobserver-shim';
import './mocks/workers';
import '../vendor/flot/jquery.flot';
import '../vendor/flot/jquery.flot.time';
// icon cache needs to be initialized for test to prevent
// libraries such as msw from throwing "unhandled resource"-errors
initIconCache();
const testAppEvents = new EventBusSrv();
const global = window as any;
global.$ = global.jQuery = $;
// mock the default window.grafanaBootData settings
const settings: Partial<GrafanaBootConfig> = {
angularSupportEnabled: true,
featureToggles: {},
};
global.grafanaBootData = {
settings,
user: {},
navTree: [],
};
window.matchMedia = (query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
});
angular.module('grafana', ['ngRoute']);
angular.module('grafana.services', ['ngRoute', '$strap.directives']);
angular.module('grafana.panels', []);
angular.module('grafana.controllers', []);
angular.module('grafana.directives', []);
angular.module('grafana.filters', []);
angular.module('grafana.routes', ['ngRoute']);
// mock the intersection observer and just say everything is in view
const mockIntersectionObserver = jest
.fn()
.mockImplementation((callback: (arg: IntersectionObserverEntry[]) => void) => ({
observe: jest.fn().mockImplementation((elem: HTMLElement) => {
callback([{ target: elem, isIntersecting: true }] as unknown as IntersectionObserverEntry[]);
}),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
global.IntersectionObserver = mockIntersectionObserver;
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
// add scrollTo interface since it's not implemented in jsdom
Element.prototype.scrollTo = () => {};
jest.mock('../app/core/core', () => ({
...jest.requireActual('../app/core/core'),
appEvents: testAppEvents,
}));
jest.mock('../app/angular/partials', () => ({}));
jest.mock('../app/features/plugins/plugin_loader', () => ({}));
const throwUnhandledRejections = () => {
process.on('unhandledRejection', (err) => {
throw err;
});
};
throwUnhandledRejections();
// Used by useMeasure
global.ResizeObserver = class ResizeObserver {
constructor(callback: ResizeObserverCallback) {
setTimeout(() => {
callback(
[
{
contentRect: {
x: 1,
y: 2,
width: 500,
height: 500,
top: 100,
bottom: 0,
left: 100,
right: 0,
},
target: {
// Needed for react-virtual to work in tests
getAttribute: () => 1,
},
} as unknown as ResizeObserverEntry,
],
this
);
});
}
observe() {}
disconnect() {}
unobserve() {}
};
global.BroadcastChannel = class BroadcastChannel {
onmessage() {}
onmessageerror() {}
postMessage(data: unknown) {}
close() {}
addEventListener() {}
removeEventListener() {}
};