2017-10-22 07:03:26 +02:00
|
|
|
import { configure } from 'enzyme';
|
2021-11-09 12:30:04 +01:00
|
|
|
import { EventBusSrv } from '@grafana/data';
|
2020-11-18 19:37:17 +01:00
|
|
|
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
2018-06-12 16:14:22 +02:00
|
|
|
import $ from 'jquery';
|
2020-02-17 11:13:13 +01:00
|
|
|
import 'mutationobserver-shim';
|
2021-11-09 21:05:01 +04:00
|
|
|
import './mocks/workers';
|
2019-11-07 12:37:46 +01:00
|
|
|
|
2021-11-09 12:30:04 +01:00
|
|
|
const testAppEvents = new EventBusSrv();
|
2019-11-07 12:37:46 +01:00
|
|
|
const global = window as any;
|
|
|
|
|
global.$ = global.jQuery = $;
|
|
|
|
|
|
2021-06-17 13:20:27 -05:00
|
|
|
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
|
|
|
Object.defineProperty(global, 'matchMedia', {
|
|
|
|
|
writable: true,
|
|
|
|
|
value: jest.fn().mockImplementation((query) => ({
|
|
|
|
|
matches: false,
|
|
|
|
|
media: query,
|
|
|
|
|
onchange: null,
|
|
|
|
|
addListener: jest.fn(), // deprecated
|
|
|
|
|
removeListener: jest.fn(), // deprecated
|
|
|
|
|
addEventListener: jest.fn(),
|
|
|
|
|
removeEventListener: jest.fn(),
|
|
|
|
|
dispatchEvent: jest.fn(),
|
|
|
|
|
})),
|
|
|
|
|
});
|
|
|
|
|
|
2019-11-07 12:37:46 +01:00
|
|
|
import '../vendor/flot/jquery.flot';
|
|
|
|
|
import '../vendor/flot/jquery.flot.time';
|
2018-06-12 16:14:22 +02:00
|
|
|
import angular from 'angular';
|
|
|
|
|
|
|
|
|
|
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']);
|
|
|
|
|
|
2021-11-09 12:30:04 +01:00
|
|
|
jest.mock('../app/core/core', () => ({ appEvents: testAppEvents }));
|
2021-10-27 14:21:07 +01:00
|
|
|
jest.mock('../app/angular/partials', () => ({}));
|
|
|
|
|
jest.mock('../app/features/plugins/plugin_loader', () => ({}));
|
2017-10-22 07:03:26 +02:00
|
|
|
|
|
|
|
|
configure({ adapter: new Adapter() });
|
2018-06-12 16:14:22 +02:00
|
|
|
|
2018-09-07 17:55:38 +02:00
|
|
|
const localStorageMock = (() => {
|
2019-06-19 19:59:03 +02:00
|
|
|
let store: any = {};
|
2018-09-02 10:36:36 -07:00
|
|
|
return {
|
2019-04-03 11:41:08 +02:00
|
|
|
getItem: (key: string) => {
|
2018-09-02 10:36:36 -07:00
|
|
|
return store[key];
|
|
|
|
|
},
|
2019-06-19 19:59:03 +02:00
|
|
|
setItem: (key: string, value: any) => {
|
2018-09-02 10:36:36 -07:00
|
|
|
store[key] = value.toString();
|
|
|
|
|
},
|
2018-09-07 17:55:38 +02:00
|
|
|
clear: () => {
|
2018-09-02 10:36:36 -07:00
|
|
|
store = {};
|
|
|
|
|
},
|
2019-04-03 11:41:08 +02:00
|
|
|
removeItem: (key: string) => {
|
2018-09-02 10:36:36 -07:00
|
|
|
delete store[key];
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
global.localStorage = localStorageMock;
|
2019-10-04 12:01:42 +02:00
|
|
|
|
2019-09-25 05:10:11 -07:00
|
|
|
const throwUnhandledRejections = () => {
|
2021-01-20 07:59:48 +01:00
|
|
|
process.on('unhandledRejection', (err) => {
|
2019-09-25 05:10:11 -07:00
|
|
|
throw err;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
throwUnhandledRejections();
|