Testing: Tidy up alerting handlers in default mock worker setup (#111292)
This commit is contained in:
@@ -27,7 +27,7 @@ export const potentiallySetupMockApi = async () => {
|
|||||||
const { default: worker } = await import('@grafana/test-utils/worker');
|
const { default: worker } = await import('@grafana/test-utils/worker');
|
||||||
|
|
||||||
// TODO: Generalise and move Alerting handlers into @grafana/test-utils or @grafana/alerting package
|
// TODO: Generalise and move Alerting handlers into @grafana/test-utils or @grafana/alerting package
|
||||||
const { default: alertingHandlers } = await import('./features/alerting/unified/mocks/server/all-handlers');
|
const { alertingHandlers } = await import('./features/alerting/unified/mocks/server/all-handlers');
|
||||||
worker.use(...alertingHandlers);
|
worker.use(...alertingHandlers);
|
||||||
|
|
||||||
worker.start({ onUnhandledRequest: 'bypass' });
|
worker.start({ onUnhandledRequest: 'bypass' });
|
||||||
|
|||||||
@@ -21,24 +21,16 @@ import searchHandlers from 'app/features/alerting/unified/mocks/server/handlers/
|
|||||||
import silenceHandlers from 'app/features/alerting/unified/mocks/server/handlers/silences';
|
import silenceHandlers from 'app/features/alerting/unified/mocks/server/handlers/silences';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of all mock handlers that are required across Alerting tests
|
* All alerting-specific handlers that are required across tests
|
||||||
* @deprecated Move to `@grafana/test-utils` instead
|
* @deprecated Move to `@grafana/alerting/testing` instead
|
||||||
*/
|
*/
|
||||||
const allHandlers = [
|
export const alertingHandlers = [
|
||||||
...accessControlHandlers,
|
|
||||||
...alertNotifierHandlers,
|
...alertNotifierHandlers,
|
||||||
...grafanaRulerHandlers,
|
...grafanaRulerHandlers,
|
||||||
...mimirRulerHandlers,
|
...mimirRulerHandlers,
|
||||||
...alertmanagerHandlers,
|
...alertmanagerHandlers,
|
||||||
...datasourcesHandlers,
|
|
||||||
...evalHandlers,
|
|
||||||
...folderHandlers,
|
|
||||||
...pluginsHandlers,
|
|
||||||
...provisioningHandlers,
|
|
||||||
...silenceHandlers,
|
...silenceHandlers,
|
||||||
...searchHandlers,
|
...provisioningHandlers,
|
||||||
|
|
||||||
...allPluginHandlers,
|
|
||||||
|
|
||||||
// Kubernetes-style handlers
|
// Kubernetes-style handlers
|
||||||
...timeIntervalK8sHandlers,
|
...timeIntervalK8sHandlers,
|
||||||
@@ -47,4 +39,22 @@ const allHandlers = [
|
|||||||
...routingTreeK8sHandlers,
|
...routingTreeK8sHandlers,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of all mock handlers that are required across Alerting tests,
|
||||||
|
* including some re-defined behaviour for handlers that are defined in `@grafana/test-utils`
|
||||||
|
*
|
||||||
|
* @deprecated Move to or use inbuilt handlers from `@grafana/test-utils` instead
|
||||||
|
*/
|
||||||
|
const allHandlers = [
|
||||||
|
...alertingHandlers,
|
||||||
|
...folderHandlers,
|
||||||
|
...searchHandlers,
|
||||||
|
|
||||||
|
...accessControlHandlers,
|
||||||
|
...allPluginHandlers,
|
||||||
|
...datasourcesHandlers,
|
||||||
|
...evalHandlers,
|
||||||
|
...pluginsHandlers,
|
||||||
|
];
|
||||||
|
|
||||||
export default allHandlers;
|
export default allHandlers;
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ const listFoldersHandler = (folders = DEFAULT_FOLDERS) =>
|
|||||||
return HttpResponse.json(strippedFolders);
|
return HttpResponse.json(strippedFolders);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** @deprecated Move to or use inbuilt handlers from `@grafana/test-utils` instead */
|
||||||
const handlers = [listFoldersHandler(), getFolderHandler()];
|
const handlers = [listFoldersHandler(), getFolderHandler()];
|
||||||
|
|
||||||
export default handlers;
|
export default handlers;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const defaultSearchResponse = [
|
|||||||
export const searchHandler = (response = defaultSearchResponse) =>
|
export const searchHandler = (response = defaultSearchResponse) =>
|
||||||
http.get(`/api/search`, () => HttpResponse.json(response));
|
http.get(`/api/search`, () => HttpResponse.json(response));
|
||||||
|
|
||||||
|
/** @deprecated Move to or use inbuilt handlers from `@grafana/test-utils` instead */
|
||||||
const handlers = [searchHandler()];
|
const handlers = [searchHandler()];
|
||||||
|
|
||||||
export default handlers;
|
export default handlers;
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import { setupWorker } from 'msw/browser';
|
|
||||||
|
|
||||||
import allAlertingHandlers from 'app/features/alerting/unified/mocks/server/all-handlers';
|
|
||||||
|
|
||||||
export default setupWorker(...allAlertingHandlers);
|
|
||||||
Reference in New Issue
Block a user