From 03715f062b89003ecfbfa909e7fc01043949abe8 Mon Sep 17 00:00:00 2001 From: Tom Ratcliffe Date: Tue, 29 Oct 2024 16:40:05 +0100 Subject: [PATCH] Chore: Move `structured-clone` polyfill to setupTests (#95406) * Add structured-clone polyfill to setupTests * Remove manual structured-clone imports --- .../app/features/alerting/unified/NotificationPolicies.test.tsx | 1 - public/app/features/alerting/unified/Receivers.test.tsx | 1 - .../unified/components/receivers/NewReceiverView.test.tsx | 1 - .../components/receivers/form/GrafanaReceiverForm.test.tsx | 2 -- .../unified/components/rule-editor/AnnotationsStep.test.tsx | 2 -- .../unified/components/rule-editor/DashboardPicker.test.tsx | 2 -- .../notificaton-preview/NotificationPreview.test.tsx | 1 - .../alerting/unified/utils/notification-policies.test.ts | 2 -- .../app/features/alerting/unified/utils/receiver-form.test.ts | 2 -- public/test/setupTests.ts | 2 ++ 10 files changed, 2 insertions(+), 14 deletions(-) diff --git a/public/app/features/alerting/unified/NotificationPolicies.test.tsx b/public/app/features/alerting/unified/NotificationPolicies.test.tsx index 9cbc98ccf37..ca359ac411e 100644 --- a/public/app/features/alerting/unified/NotificationPolicies.test.tsx +++ b/public/app/features/alerting/unified/NotificationPolicies.test.tsx @@ -1,4 +1,3 @@ -import 'core-js/stable/structured-clone'; import { clickSelectOption } from 'test/helpers/selectOptionInTest'; import { render, screen, userEvent } from 'test/test-utils'; import { byLabelText, byRole, byTestId, byText } from 'testing-library-selector'; diff --git a/public/app/features/alerting/unified/Receivers.test.tsx b/public/app/features/alerting/unified/Receivers.test.tsx index 36b18b52ee3..6620a674c37 100644 --- a/public/app/features/alerting/unified/Receivers.test.tsx +++ b/public/app/features/alerting/unified/Receivers.test.tsx @@ -12,7 +12,6 @@ import { grantUserPermissions } from 'app/features/alerting/unified/mocks'; import { setupDataSources } from 'app/features/alerting/unified/testSetup/datasources'; import { AccessControlAction } from 'app/types'; -import 'core-js/stable/structured-clone'; import ContactPoints from './components/contact-points/ContactPoints'; import EditContactPoint from './components/contact-points/EditContactPoint'; import NewReceiverView from './components/receivers/NewReceiverView'; diff --git a/public/app/features/alerting/unified/components/receivers/NewReceiverView.test.tsx b/public/app/features/alerting/unified/components/receivers/NewReceiverView.test.tsx index b0509065b58..545cf1d49a0 100644 --- a/public/app/features/alerting/unified/components/receivers/NewReceiverView.test.tsx +++ b/public/app/features/alerting/unified/components/receivers/NewReceiverView.test.tsx @@ -1,4 +1,3 @@ -import 'core-js/stable/structured-clone'; import { Routes, Route } from 'react-router-dom-v5-compat'; import { render, screen } from 'test/test-utils'; import { byLabelText, byPlaceholderText, byRole, byTestId } from 'testing-library-selector'; diff --git a/public/app/features/alerting/unified/components/receivers/form/GrafanaReceiverForm.test.tsx b/public/app/features/alerting/unified/components/receivers/form/GrafanaReceiverForm.test.tsx index b7c6c9517be..a5753c1e983 100644 --- a/public/app/features/alerting/unified/components/receivers/form/GrafanaReceiverForm.test.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/GrafanaReceiverForm.test.tsx @@ -19,8 +19,6 @@ import { renderWithProvider } from '../../contact-points/ContactPoints.test'; import { GrafanaReceiverForm } from './GrafanaReceiverForm'; -import 'core-js/stable/structured-clone'; - setupMswServer(); const ui = { diff --git a/public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.test.tsx b/public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.test.tsx index 565f7ed6cf6..5130de55dbc 100644 --- a/public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.test.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.test.tsx @@ -3,8 +3,6 @@ import { FormProvider, useForm } from 'react-hook-form'; import { screen, render, within } from 'test/test-utils'; import { byRole, byTestId } from 'testing-library-selector'; -import 'core-js/stable/structured-clone'; - import { DashboardSearchItemType } from '../../../../search/types'; import { mockDashboardApi, setupMswServer } from '../../mockApi'; import { mockDashboardDto, mockDashboardSearchItem } from '../../mocks'; diff --git a/public/app/features/alerting/unified/components/rule-editor/DashboardPicker.test.tsx b/public/app/features/alerting/unified/components/rule-editor/DashboardPicker.test.tsx index dcf8b06dd91..0644dc95480 100644 --- a/public/app/features/alerting/unified/components/rule-editor/DashboardPicker.test.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/DashboardPicker.test.tsx @@ -3,8 +3,6 @@ import { Props } from 'react-virtualized-auto-sizer'; import { render } from 'test/test-utils'; import { byRole } from 'testing-library-selector'; -import 'core-js/stable/structured-clone'; - import { DashboardSearchItemType } from '../../../../search/types'; import { mockDashboardApi, setupMswServer } from '../../mockApi'; import { mockDashboardDto, mockDashboardSearchItem } from '../../mocks'; diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPreview.test.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPreview.test.tsx index e0fc849dcd8..ea6dbbaeab4 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPreview.test.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationPreview.test.tsx @@ -3,7 +3,6 @@ import { byRole, byTestId, byText } from 'testing-library-selector'; import { AccessControlAction } from 'app/types/accessControl'; -import 'core-js/stable/structured-clone'; import { MatcherOperator } from '../../../../../../plugins/datasource/alertmanager/types'; import { Labels } from '../../../../../../types/unified-alerting-dto'; import { mockApi, setupMswServer } from '../../../mockApi'; diff --git a/public/app/features/alerting/unified/utils/notification-policies.test.ts b/public/app/features/alerting/unified/utils/notification-policies.test.ts index 9dd13f9dfdd..52dd314b591 100644 --- a/public/app/features/alerting/unified/utils/notification-policies.test.ts +++ b/public/app/features/alerting/unified/utils/notification-policies.test.ts @@ -10,8 +10,6 @@ import { unquoteRouteMatchers, } from './notification-policies'; -import 'core-js/stable/structured-clone'; - const CATCH_ALL_ROUTE: Route = { receiver: 'ALL', object_matchers: [], diff --git a/public/app/features/alerting/unified/utils/receiver-form.test.ts b/public/app/features/alerting/unified/utils/receiver-form.test.ts index 06ee33629a2..aa3194cd824 100644 --- a/public/app/features/alerting/unified/utils/receiver-form.test.ts +++ b/public/app/features/alerting/unified/utils/receiver-form.test.ts @@ -1,5 +1,3 @@ -import 'core-js/stable/structured-clone'; - import { NotifierDTO } from 'app/types'; import { Receiver } from '../../../../plugins/datasource/alertmanager/types'; diff --git a/public/test/setupTests.ts b/public/test/setupTests.ts index ca3d498dad9..242236ece98 100644 --- a/public/test/setupTests.ts +++ b/public/test/setupTests.ts @@ -1,3 +1,5 @@ +// `structuredClone` is not yet in jsdom https://github.com/jsdom/jsdom/issues/3363 +import 'core-js/stable/structured-clone'; import 'whatwg-fetch'; import '@testing-library/jest-dom'; import { configure } from '@testing-library/react';