Testing: Tidy up alerting handlers in default mock worker setup (#111292)

This commit is contained in:
Tom Ratcliffe 2025-09-29 09:19:31 +01:00 committed by GitHub
parent 85534ae143
commit 310c83531c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 18 deletions

View File

@ -27,7 +27,7 @@ export const potentiallySetupMockApi = async () => {
const { default: worker } = await import('@grafana/test-utils/worker');
// 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.start({ onUnhandledRequest: 'bypass' });

View File

@ -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';
/**
* Array of all mock handlers that are required across Alerting tests
* @deprecated Move to `@grafana/test-utils` instead
* All alerting-specific handlers that are required across tests
* @deprecated Move to `@grafana/alerting/testing` instead
*/
const allHandlers = [
...accessControlHandlers,
export const alertingHandlers = [
...alertNotifierHandlers,
...grafanaRulerHandlers,
...mimirRulerHandlers,
...alertmanagerHandlers,
...datasourcesHandlers,
...evalHandlers,
...folderHandlers,
...pluginsHandlers,
...provisioningHandlers,
...silenceHandlers,
...searchHandlers,
...allPluginHandlers,
...provisioningHandlers,
// Kubernetes-style handlers
...timeIntervalK8sHandlers,
@ -47,4 +39,22 @@ const allHandlers = [
...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;

View File

@ -52,6 +52,7 @@ const listFoldersHandler = (folders = DEFAULT_FOLDERS) =>
return HttpResponse.json(strippedFolders);
});
/** @deprecated Move to or use inbuilt handlers from `@grafana/test-utils` instead */
const handlers = [listFoldersHandler(), getFolderHandler()];
export default handlers;

View File

@ -29,6 +29,7 @@ const defaultSearchResponse = [
export const searchHandler = (response = defaultSearchResponse) =>
http.get(`/api/search`, () => HttpResponse.json(response));
/** @deprecated Move to or use inbuilt handlers from `@grafana/test-utils` instead */
const handlers = [searchHandler()];
export default handlers;

View File

@ -1,5 +0,0 @@
import { setupWorker } from 'msw/browser';
import allAlertingHandlers from 'app/features/alerting/unified/mocks/server/all-handlers';
export default setupWorker(...allAlertingHandlers);