From 069de587cd02270530c4844ea06fbcd37a38b325 Mon Sep 17 00:00:00 2001 From: MariaAga Date: Tue, 9 Jul 2024 12:11:38 +0100 Subject: [PATCH 1/3] Fixes #37636 - remove "@theforeman/test" imports --- webpack/assets/javascripts/react_app/common/HOC.test.js | 2 +- .../react_app/common/IntegrationTestHelper.js | 2 +- .../assets/javascripts/react_app/common/testHelpers.js | 5 ++--- .../BreadcrumbBar/__tests__/BreadcrumbBar.test.js | 1 - .../react_app/components/ChartBox/ChartBox.test.js | 2 +- .../components/ConfigReports/ConfigReports.test.js | 2 +- .../ConfigReports/DiffModal/__tests__/DiffModal.test.js | 2 +- .../components/ConfirmModal/integration.test.js | 2 +- .../react_app/components/Editor/__tests__/Editor.test.js | 2 +- .../Editor/components/__tests__/EditorNavbar.test.js | 2 +- .../Editor/components/__tests__/EditorOptions.test.js | 2 +- .../ExternalLogout/__tests__/ExternalLogout.test.js | 2 +- .../subcomponents/SubmitOrCancel/SubmitOrCancel.test.js | 2 +- .../subcomponents/__tests__/ForemanModalFooter.test.js | 2 +- .../subcomponents/__tests__/ForemanModalHeader.test.js | 2 +- .../components/ImpersonateIcon/ImpersonateIcon.test.js | 2 +- .../Layout/components/Toolbar/HeaderToolbar.test.js | 2 +- .../__tests__/MemoryAllocationInput.test.js | 2 +- .../components/PF4/Bookmarks/__tests__/Bookmarks.test.js | 1 - .../PF4/DocumentationLink/DocumentationLink.test.js | 2 +- .../PasswordStrength/__tests__/PasswordStrength.test.js | 2 +- .../__tests__/SettingRecordsReducer.test.js | 2 +- .../__tests__/SettingRecordsSelectors.test.js | 2 +- .../SettingUpdateModal/SettingUpdateModal.test.js | 2 +- .../components/SettingValueField.test.js | 2 +- .../SettingsTable/__tests__/SettingsTable.test.js | 2 +- .../components/__tests__/SettingCell.test.js | 2 +- .../components/__tests__/SettingName.test.js | 2 +- .../components/ToastsList/__tests__/integration.test.js | 2 +- .../common/ActionButtons/ActionButtons.test.js | 2 +- .../react_app/components/common/Alert/AlertBody.test.js | 2 +- .../react_app/components/common/Alert/AlertLink.test.js | 2 +- .../common/ComponentWrapper/ComponentWrapper.test.js | 2 +- .../DateTimePicker/DateComponents/DateInput.test.js | 2 +- .../common/DateTimePicker/DateComponents/Day.test.js | 2 +- .../DateTimePicker/DateComponents/DecadeView.test.js | 2 +- .../DateComponents/DecadeViewHeader.test.js | 2 +- .../DateComponents/DecadeViewTable.test.js | 2 +- .../common/DateTimePicker/DateComponents/Header.test.js | 2 +- .../DateTimePicker/DateComponents/MonthView.test.js | 2 +- .../DateTimePicker/DateComponents/TodayButton.test.js | 2 +- .../DateTimePicker/DateComponents/YearView.test.js | 2 +- .../components/common/DateTimePicker/DatePicker.test.js | 2 +- .../common/DateTimePicker/DateTimePicker.test.js | 2 +- .../DateTimePicker/TimeComponents/PickTimeClock.test.js | 2 +- .../DateTimePicker/TimeComponents/PickTimeTable.test.js | 2 +- .../DateTimePicker/TimeComponents/TimeInput.test.js | 2 +- .../components/common/DateTimePicker/TimePicker.test.js | 2 +- .../common/DocumentationLink/DocumentationLink.test.js | 2 +- .../components/common/Fill/__tests__/FillReducer.test.js | 2 +- .../react_app/components/common/Loader/Loader.test.js | 2 +- .../components/common/MessageBox/MessageBox.test.js | 2 +- .../ModalProgressBar/__tests__/ModalProgressBar.test.js | 2 +- .../RedirectCancelButton/RedirectCancelButton.test.js | 2 +- .../components/common/SearchInput/SearchInput.test.js | 2 +- .../common/SkeletonLoader/SkeletonLoader.test.js | 2 +- .../components/common/charts/BarChart/BarChart.test.js | 2 +- .../common/charts/DonutChart/DonutChart.test.js | 2 +- .../components/common/charts/LineChart/LineChart.test.js | 2 +- .../react_app/components/common/dates/IsoDate.test.js | 2 +- .../components/common/dates/LongDateTime.test.js | 2 +- .../components/common/dates/RelativeDateTime.test.js | 2 +- .../components/common/dates/ShortDateTime.test.js | 2 +- .../react_app/components/common/forms/Actions.test.js | 2 +- .../react_app/components/common/forms/CommonForm.test.js | 2 +- .../forms/CounterInput/__tests__/CounterInput.test.js | 2 +- .../common/forms/ForemanForm/ForemanForm.test.js | 2 +- .../common/forms/ForemanForm/integration.test.js | 2 +- .../react_app/components/common/forms/Form.test.js | 2 +- .../OrderableSelect/__tests__/OrderableSelect.test.js | 2 +- .../forms/RadioButtonGroup/RadioButtonGroup.test.js | 2 +- .../react_app/components/common/forms/Select.test.js | 9 ++++----- .../common/table/actions/selectionActions.test.js | 2 +- .../table/components/__tests__/DeleteButton.test.js | 2 +- .../table/components/__tests__/HostsCountCell.test.js | 2 +- .../common/table/components/__tests__/NameCell.test.js | 2 +- .../table/components/__tests__/SortableHeader.test.js | 2 +- .../components/__tests__/TableSelectionCell.test.js | 2 +- .../__tests__/TableSelectionHeaderCell.test.js | 2 +- .../common/table/reducers/selectionReducer.test.js | 2 +- .../hosts/powerStatus/__tests__/PowerStatus.test.js | 2 +- .../hosts/storage/vmware/controller/controller.test.js | 2 +- .../hosts/storage/vmware/controller/disk/disk.test.js | 2 +- webpack/assets/javascripts/react_app/mockRequests.js | 2 +- .../RegistrationCommandsPage/__tests__/helpers.test.js | 2 +- .../javascripts/react_app/routes/__test__/Routes.test.js | 2 +- .../components/ExportButton/ExportButton.test.js | 2 +- .../javascripts/services/charts/LineChartService.test.js | 2 +- 88 files changed, 90 insertions(+), 94 deletions(-) diff --git a/webpack/assets/javascripts/react_app/common/HOC.test.js b/webpack/assets/javascripts/react_app/common/HOC.test.js index ab6d9614251..6727eff09f2 100644 --- a/webpack/assets/javascripts/react_app/common/HOC.test.js +++ b/webpack/assets/javascripts/react_app/common/HOC.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { callOnMount, withRenderHandler, callOnPopState } from './HOC'; diff --git a/webpack/assets/javascripts/react_app/common/IntegrationTestHelper.js b/webpack/assets/javascripts/react_app/common/IntegrationTestHelper.js index 501f64966cc..6625f928b3f 100644 --- a/webpack/assets/javascripts/react_app/common/IntegrationTestHelper.js +++ b/webpack/assets/javascripts/react_app/common/IntegrationTestHelper.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { Provider } from 'react-redux'; import { applyMiddleware, combineReducers, createStore } from 'redux'; import thunk from 'redux-thunk'; diff --git a/webpack/assets/javascripts/react_app/common/testHelpers.js b/webpack/assets/javascripts/react_app/common/testHelpers.js index ecb0c97268d..5b63970ef16 100644 --- a/webpack/assets/javascripts/react_app/common/testHelpers.js +++ b/webpack/assets/javascripts/react_app/common/testHelpers.js @@ -1,7 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; - -jest.useFakeTimers(); +import { shallow } from 'enzyme'; export default { mockStorage: () => { @@ -80,6 +78,7 @@ const resolveDispatch = async (action, depth) => { if (depth && typeof action === 'function') { const dispatch = jest.fn(); await action(dispatch); + jest.useFakeTimers(); jest.runOnlyPendingTimers(); return Promise.all( diff --git a/webpack/assets/javascripts/react_app/components/BreadcrumbBar/__tests__/BreadcrumbBar.test.js b/webpack/assets/javascripts/react_app/components/BreadcrumbBar/__tests__/BreadcrumbBar.test.js index a86dfd49f0d..ddf0d33a9fb 100644 --- a/webpack/assets/javascripts/react_app/components/BreadcrumbBar/__tests__/BreadcrumbBar.test.js +++ b/webpack/assets/javascripts/react_app/components/BreadcrumbBar/__tests__/BreadcrumbBar.test.js @@ -1,6 +1,5 @@ import React from 'react'; import { render, fireEvent, screen, act } from '@testing-library/react'; -import { mount } from '@theforeman/test'; import { testComponentSnapshotsWithFixtures } from '../../../common/testHelpers'; diff --git a/webpack/assets/javascripts/react_app/components/ChartBox/ChartBox.test.js b/webpack/assets/javascripts/react_app/components/ChartBox/ChartBox.test.js index b81fbcecfb5..c26c8334c76 100644 --- a/webpack/assets/javascripts/react_app/components/ChartBox/ChartBox.test.js +++ b/webpack/assets/javascripts/react_app/components/ChartBox/ChartBox.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import ChartBox from './ChartBox'; import { classFunctionUnitTest } from '../../common/testHelpers'; diff --git a/webpack/assets/javascripts/react_app/components/ConfigReports/ConfigReports.test.js b/webpack/assets/javascripts/react_app/components/ConfigReports/ConfigReports.test.js index 1a17f7e0cc1..48ac9b38a97 100644 --- a/webpack/assets/javascripts/react_app/components/ConfigReports/ConfigReports.test.js +++ b/webpack/assets/javascripts/react_app/components/ConfigReports/ConfigReports.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import ConfigReports from './ConfigReports'; diff --git a/webpack/assets/javascripts/react_app/components/ConfigReports/DiffModal/__tests__/DiffModal.test.js b/webpack/assets/javascripts/react_app/components/ConfigReports/DiffModal/__tests__/DiffModal.test.js index 5fcbeb65bd1..56e809898fe 100644 --- a/webpack/assets/javascripts/react_app/components/ConfigReports/DiffModal/__tests__/DiffModal.test.js +++ b/webpack/assets/javascripts/react_app/components/ConfigReports/DiffModal/__tests__/DiffModal.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { testComponentSnapshotsWithFixtures } from '../../../../common/testHelpers'; import DiffModal from '../DiffModal'; diff --git a/webpack/assets/javascripts/react_app/components/ConfirmModal/integration.test.js b/webpack/assets/javascripts/react_app/components/ConfirmModal/integration.test.js index 479bf90bb00..52ed9ecaed7 100644 --- a/webpack/assets/javascripts/react_app/components/ConfirmModal/integration.test.js +++ b/webpack/assets/javascripts/react_app/components/ConfirmModal/integration.test.js @@ -1,6 +1,6 @@ import React from 'react'; import { Provider } from 'react-redux'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { Button } from '@patternfly/react-core'; import store from '../../redux'; import ConfirmModal, { openConfirmModal } from './index'; diff --git a/webpack/assets/javascripts/react_app/components/Editor/__tests__/Editor.test.js b/webpack/assets/javascripts/react_app/components/Editor/__tests__/Editor.test.js index 2e0d6d67e67..30513634beb 100644 --- a/webpack/assets/javascripts/react_app/components/Editor/__tests__/Editor.test.js +++ b/webpack/assets/javascripts/react_app/components/Editor/__tests__/Editor.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { testComponentSnapshotsWithFixtures } from '../../../common/testHelpers'; import Editor from '../Editor'; import { editorOptions } from '../Editor.fixtures'; diff --git a/webpack/assets/javascripts/react_app/components/Editor/components/__tests__/EditorNavbar.test.js b/webpack/assets/javascripts/react_app/components/Editor/components/__tests__/EditorNavbar.test.js index 527243a1f92..04ca650440c 100644 --- a/webpack/assets/javascripts/react_app/components/Editor/components/__tests__/EditorNavbar.test.js +++ b/webpack/assets/javascripts/react_app/components/Editor/components/__tests__/EditorNavbar.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { testComponentSnapshotsWithFixtures } from '../../../../common/testHelpers'; import EditorNavbar from '../EditorNavbar'; diff --git a/webpack/assets/javascripts/react_app/components/Editor/components/__tests__/EditorOptions.test.js b/webpack/assets/javascripts/react_app/components/Editor/components/__tests__/EditorOptions.test.js index de6300d14f0..d7b31e68a5a 100644 --- a/webpack/assets/javascripts/react_app/components/Editor/components/__tests__/EditorOptions.test.js +++ b/webpack/assets/javascripts/react_app/components/Editor/components/__tests__/EditorOptions.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { testComponentSnapshotsWithFixtures } from '../../../../common/testHelpers'; import EditorOptions from '../EditorOptions'; diff --git a/webpack/assets/javascripts/react_app/components/ExternalLogout/__tests__/ExternalLogout.test.js b/webpack/assets/javascripts/react_app/components/ExternalLogout/__tests__/ExternalLogout.test.js index d63b7c29888..eab80f58f7e 100644 --- a/webpack/assets/javascripts/react_app/components/ExternalLogout/__tests__/ExternalLogout.test.js +++ b/webpack/assets/javascripts/react_app/components/ExternalLogout/__tests__/ExternalLogout.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import ExternalLogout from '../ExternalLogout'; import { props } from '../ExternalLogout.fixtures'; diff --git a/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/SubmitOrCancel/SubmitOrCancel.test.js b/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/SubmitOrCancel/SubmitOrCancel.test.js index abaf2ab3882..e32de925747 100644 --- a/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/SubmitOrCancel/SubmitOrCancel.test.js +++ b/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/SubmitOrCancel/SubmitOrCancel.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import SubmitOrCancel from './SubmitOrCancel'; diff --git a/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/__tests__/ForemanModalFooter.test.js b/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/__tests__/ForemanModalFooter.test.js index 8a41647362d..05c5699d75a 100644 --- a/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/__tests__/ForemanModalFooter.test.js +++ b/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/__tests__/ForemanModalFooter.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import { Button, Modal } from 'patternfly-react'; import ForemanModalFooter from '../ForemanModalFooter'; import * as ModalContext from '../../ForemanModalHooks'; // so enzyme test works diff --git a/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/__tests__/ForemanModalHeader.test.js b/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/__tests__/ForemanModalHeader.test.js index 1f3ce92b434..3c6f2c83393 100644 --- a/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/__tests__/ForemanModalHeader.test.js +++ b/webpack/assets/javascripts/react_app/components/ForemanModal/subcomponents/__tests__/ForemanModalHeader.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import { Modal } from 'patternfly-react'; import ForemanModalHeader from '../ForemanModalHeader'; import * as ModalContext from '../../ForemanModalHooks'; // so enzyme test works diff --git a/webpack/assets/javascripts/react_app/components/Layout/components/ImpersonateIcon/ImpersonateIcon.test.js b/webpack/assets/javascripts/react_app/components/Layout/components/ImpersonateIcon/ImpersonateIcon.test.js index d5132cdac71..2f79b894c50 100644 --- a/webpack/assets/javascripts/react_app/components/Layout/components/ImpersonateIcon/ImpersonateIcon.test.js +++ b/webpack/assets/javascripts/react_app/components/Layout/components/ImpersonateIcon/ImpersonateIcon.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import ImpersonateIcon from './ImpersonateIcon'; diff --git a/webpack/assets/javascripts/react_app/components/Layout/components/Toolbar/HeaderToolbar.test.js b/webpack/assets/javascripts/react_app/components/Layout/components/Toolbar/HeaderToolbar.test.js index 6c029c077d8..3896865c879 100644 --- a/webpack/assets/javascripts/react_app/components/Layout/components/Toolbar/HeaderToolbar.test.js +++ b/webpack/assets/javascripts/react_app/components/Layout/components/Toolbar/HeaderToolbar.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import { hasTaxonomiesMock } from '../../Layout.fixtures'; import { noop } from '../../../../common/helpers'; diff --git a/webpack/assets/javascripts/react_app/components/MemoryAllocationInput/__tests__/MemoryAllocationInput.test.js b/webpack/assets/javascripts/react_app/components/MemoryAllocationInput/__tests__/MemoryAllocationInput.test.js index 556e25a393b..9ad986357ef 100644 --- a/webpack/assets/javascripts/react_app/components/MemoryAllocationInput/__tests__/MemoryAllocationInput.test.js +++ b/webpack/assets/javascripts/react_app/components/MemoryAllocationInput/__tests__/MemoryAllocationInput.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { Provider } from 'react-redux'; import { MEGABYTES } from '../constants'; import MemoryAllocationInput from '../'; diff --git a/webpack/assets/javascripts/react_app/components/PF4/Bookmarks/__tests__/Bookmarks.test.js b/webpack/assets/javascripts/react_app/components/PF4/Bookmarks/__tests__/Bookmarks.test.js index 0f3f43cf44a..e5cacded619 100644 --- a/webpack/assets/javascripts/react_app/components/PF4/Bookmarks/__tests__/Bookmarks.test.js +++ b/webpack/assets/javascripts/react_app/components/PF4/Bookmarks/__tests__/Bookmarks.test.js @@ -1,4 +1,3 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; import React from 'react'; import { Provider } from 'react-redux'; import store from '../../../../redux'; diff --git a/webpack/assets/javascripts/react_app/components/PF4/DocumentationLink/DocumentationLink.test.js b/webpack/assets/javascripts/react_app/components/PF4/DocumentationLink/DocumentationLink.test.js index 7cee3c80b15..905392e36bf 100644 --- a/webpack/assets/javascripts/react_app/components/PF4/DocumentationLink/DocumentationLink.test.js +++ b/webpack/assets/javascripts/react_app/components/PF4/DocumentationLink/DocumentationLink.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import Link from './index'; diff --git a/webpack/assets/javascripts/react_app/components/PasswordStrength/__tests__/PasswordStrength.test.js b/webpack/assets/javascripts/react_app/components/PasswordStrength/__tests__/PasswordStrength.test.js index 71d49e69a78..718a094bcaf 100644 --- a/webpack/assets/javascripts/react_app/components/PasswordStrength/__tests__/PasswordStrength.test.js +++ b/webpack/assets/javascripts/react_app/components/PasswordStrength/__tests__/PasswordStrength.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { testComponentSnapshotsWithFixtures } from '../../../common/testHelpers'; diff --git a/webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecordsReducer.test.js b/webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecordsReducer.test.js index 90c20d94482..ae91beb47aa 100644 --- a/webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecordsReducer.test.js +++ b/webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecordsReducer.test.js @@ -1,4 +1,4 @@ -import { testReducerSnapshotWithFixtures } from '@theforeman/test'; +import { testReducerSnapshotWithFixtures } from 'foremanReact/common/testHelpers'; import { default as reducer, initialState } from '../SettingRecordsReducer'; diff --git a/webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecordsSelectors.test.js b/webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecordsSelectors.test.js index 706b83f1a14..9f32648a377 100644 --- a/webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecordsSelectors.test.js +++ b/webpack/assets/javascripts/react_app/components/SettingRecords/__tests__/SettingRecordsSelectors.test.js @@ -1,4 +1,4 @@ -import { testSelectorsSnapshotWithFixtures } from '@theforeman/test'; +import { testSelectorsSnapshotWithFixtures } from 'foremanReact/common/testHelpers'; import { selectSettings, diff --git a/webpack/assets/javascripts/react_app/components/SettingUpdateModal/SettingUpdateModal.test.js b/webpack/assets/javascripts/react_app/components/SettingUpdateModal/SettingUpdateModal.test.js index 605749ac0e6..d359f0f10db 100644 --- a/webpack/assets/javascripts/react_app/components/SettingUpdateModal/SettingUpdateModal.test.js +++ b/webpack/assets/javascripts/react_app/components/SettingUpdateModal/SettingUpdateModal.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import { arraySetting } from '../SettingRecords/__tests__/SettingRecords.fixtures'; diff --git a/webpack/assets/javascripts/react_app/components/SettingUpdateModal/components/SettingValueField.test.js b/webpack/assets/javascripts/react_app/components/SettingUpdateModal/components/SettingValueField.test.js index c76bf679b65..978be53736d 100644 --- a/webpack/assets/javascripts/react_app/components/SettingUpdateModal/components/SettingValueField.test.js +++ b/webpack/assets/javascripts/react_app/components/SettingUpdateModal/components/SettingValueField.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import SettingValueField from './SettingValueField'; diff --git a/webpack/assets/javascripts/react_app/components/SettingsTable/__tests__/SettingsTable.test.js b/webpack/assets/javascripts/react_app/components/SettingsTable/__tests__/SettingsTable.test.js index 68799862484..9cf4dea3c16 100644 --- a/webpack/assets/javascripts/react_app/components/SettingsTable/__tests__/SettingsTable.test.js +++ b/webpack/assets/javascripts/react_app/components/SettingsTable/__tests__/SettingsTable.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import { groupedSettings } from '../../SettingRecords/__tests__/SettingRecords.fixtures'; diff --git a/webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/SettingCell.test.js b/webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/SettingCell.test.js index e6cd0b73c83..d766a4b7ee3 100644 --- a/webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/SettingCell.test.js +++ b/webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/SettingCell.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import { rootPass, diff --git a/webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/SettingName.test.js b/webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/SettingName.test.js index 19c16153c59..fca1311af45 100644 --- a/webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/SettingName.test.js +++ b/webpack/assets/javascripts/react_app/components/SettingsTable/components/__tests__/SettingName.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import { rootPass, diff --git a/webpack/assets/javascripts/react_app/components/ToastsList/__tests__/integration.test.js b/webpack/assets/javascripts/react_app/components/ToastsList/__tests__/integration.test.js index 92c109172ed..d3a7448a5f0 100644 --- a/webpack/assets/javascripts/react_app/components/ToastsList/__tests__/integration.test.js +++ b/webpack/assets/javascripts/react_app/components/ToastsList/__tests__/integration.test.js @@ -1,6 +1,6 @@ import React from 'react'; import { Provider } from 'react-redux'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import store from '../../../redux'; import ToastsList, { addToast, deleteToast } from '../index' diff --git a/webpack/assets/javascripts/react_app/components/common/ActionButtons/ActionButtons.test.js b/webpack/assets/javascripts/react_app/components/common/ActionButtons/ActionButtons.test.js index 45c04779b24..3c97cdd4237 100644 --- a/webpack/assets/javascripts/react_app/components/common/ActionButtons/ActionButtons.test.js +++ b/webpack/assets/javascripts/react_app/components/common/ActionButtons/ActionButtons.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import { ActionButtons } from './ActionButtons'; import { buttons } from './ActionButtons.fixtures'; diff --git a/webpack/assets/javascripts/react_app/components/common/Alert/AlertBody.test.js b/webpack/assets/javascripts/react_app/components/common/Alert/AlertBody.test.js index 27031e8690e..e7dce609455 100644 --- a/webpack/assets/javascripts/react_app/components/common/Alert/AlertBody.test.js +++ b/webpack/assets/javascripts/react_app/components/common/Alert/AlertBody.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import AlertBody from './AlertBody'; diff --git a/webpack/assets/javascripts/react_app/components/common/Alert/AlertLink.test.js b/webpack/assets/javascripts/react_app/components/common/Alert/AlertLink.test.js index faf02a01cde..c2a759c04cd 100644 --- a/webpack/assets/javascripts/react_app/components/common/Alert/AlertLink.test.js +++ b/webpack/assets/javascripts/react_app/components/common/Alert/AlertLink.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import AlertLink from './AlertLink'; diff --git a/webpack/assets/javascripts/react_app/components/common/ComponentWrapper/ComponentWrapper.test.js b/webpack/assets/javascripts/react_app/components/common/ComponentWrapper/ComponentWrapper.test.js index eb2c9f6d045..858281cda00 100644 --- a/webpack/assets/javascripts/react_app/components/common/ComponentWrapper/ComponentWrapper.test.js +++ b/webpack/assets/javascripts/react_app/components/common/ComponentWrapper/ComponentWrapper.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import componentRegistry from '../../componentRegistry'; import ComponentWrapper from './ComponentWrapper'; diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DateInput.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DateInput.test.js index 98c4b6ab193..2a4a564196e 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DateInput.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DateInput.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow, mount } from '@theforeman/test'; +import { shallow, mount } from 'enzyme'; import DateInput from './DateInput'; test('DateInput is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/Day.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/Day.test.js index 962e50a3c7e..ccee6ef4d7d 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/Day.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/Day.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import Day from './Day'; test('Day is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeView.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeView.test.js index 051d8a830f4..a45612aec9e 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeView.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeView.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow, mount } from '@theforeman/test'; +import { shallow, mount } from 'enzyme'; import DecadeView from './DecadeView'; test('DecadeView is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeViewHeader.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeViewHeader.test.js index d193691add4..0fba60bfb15 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeViewHeader.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeViewHeader.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import { DecadeViewHeader } from './DecadeViewHeader'; test('DecadeViewHeader is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeViewTable.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeViewTable.test.js index 20a72bae885..74dbd93fa9b 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeViewTable.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/DecadeViewTable.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import { DecadeViewTable } from './DecadeViewTable'; test('DecadeViewTable is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/Header.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/Header.test.js index cc50df728a5..f88d12f8786 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/Header.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/Header.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import Header from './Header'; test('Header is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/MonthView.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/MonthView.test.js index ca5bf935ed3..23703b6dddb 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/MonthView.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/MonthView.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import MonthView from './MonthView'; test('MonthView is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/TodayButton.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/TodayButton.test.js index c8a2a7aa963..0d7a4358a93 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/TodayButton.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/TodayButton.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import TodayButton from './TodayButton'; const mockedDate = new Date('2/21/2019 , 3:22:31 PM'); diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/YearView.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/YearView.test.js index 5cd7c691551..92382a3f846 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/YearView.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateComponents/YearView.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import YearView from './YearView'; test('YearView is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DatePicker.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DatePicker.test.js index 3c8964fcbc7..971498ad680 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DatePicker.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DatePicker.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import DatePicker from './DatePicker'; describe('DatePicker', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateTimePicker.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateTimePicker.test.js index 5b8e713b3e4..b9a0435edd1 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateTimePicker.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/DateTimePicker.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import DateTimePicker from './DateTimePicker'; describe('DateTimePicker', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/PickTimeClock.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/PickTimeClock.test.js index 766a2f3e501..b98ac585b97 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/PickTimeClock.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/PickTimeClock.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow, mount } from '@theforeman/test'; +import { shallow, mount } from 'enzyme'; import PickTimeClock from './PickTimeClock'; import { MINUTE, HOUR } from './TimeConstants'; diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/PickTimeTable.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/PickTimeTable.test.js index cc0f79e9fda..9cbd183db0c 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/PickTimeTable.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/PickTimeTable.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import PickTimeTable from './PickTimeTable'; import { MINUTE, HOUR } from './TimeConstants'; diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/TimeInput.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/TimeInput.test.js index ff463a6bc5b..221fe4803e3 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/TimeInput.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimeComponents/TimeInput.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow, mount } from '@theforeman/test'; +import { shallow, mount } from 'enzyme'; import TimeInput from './TimeInput'; test('TimeInput is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimePicker.test.js b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimePicker.test.js index e4511a84ebb..11c1d4aec25 100644 --- a/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimePicker.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DateTimePicker/TimePicker.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import TimePicker from './TimePicker'; test('TimePicker is working properly', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/DocumentationLink/DocumentationLink.test.js b/webpack/assets/javascripts/react_app/components/common/DocumentationLink/DocumentationLink.test.js index b47e90902bf..aff30ed02ec 100644 --- a/webpack/assets/javascripts/react_app/components/common/DocumentationLink/DocumentationLink.test.js +++ b/webpack/assets/javascripts/react_app/components/common/DocumentationLink/DocumentationLink.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import Link from './index'; diff --git a/webpack/assets/javascripts/react_app/components/common/Fill/__tests__/FillReducer.test.js b/webpack/assets/javascripts/react_app/components/common/Fill/__tests__/FillReducer.test.js index 4f19db384f1..3eda8463764 100644 --- a/webpack/assets/javascripts/react_app/components/common/Fill/__tests__/FillReducer.test.js +++ b/webpack/assets/javascripts/react_app/components/common/Fill/__tests__/FillReducer.test.js @@ -1,4 +1,4 @@ -import { testReducerSnapshotWithFixtures } from '@theforeman/test'; +import { testReducerSnapshotWithFixtures } from 'foremanReact/common/testHelpers'; import Immutable from 'seamless-immutable'; import reducer from '../FillReducer'; import { REMOVE_FILLED_COMPONENT } from '../FillConstants'; diff --git a/webpack/assets/javascripts/react_app/components/common/Loader/Loader.test.js b/webpack/assets/javascripts/react_app/components/common/Loader/Loader.test.js index 67981863262..370f1d7966c 100644 --- a/webpack/assets/javascripts/react_app/components/common/Loader/Loader.test.js +++ b/webpack/assets/javascripts/react_app/components/common/Loader/Loader.test.js @@ -1,4 +1,4 @@ -import { shallow, mount } from '@theforeman/test'; +import { shallow, mount } from 'enzyme'; import React from 'react'; import { STATUS } from '../../../constants'; diff --git a/webpack/assets/javascripts/react_app/components/common/MessageBox/MessageBox.test.js b/webpack/assets/javascripts/react_app/components/common/MessageBox/MessageBox.test.js index a695222ba9f..3887b509b9a 100644 --- a/webpack/assets/javascripts/react_app/components/common/MessageBox/MessageBox.test.js +++ b/webpack/assets/javascripts/react_app/components/common/MessageBox/MessageBox.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import MessageBox from './index'; diff --git a/webpack/assets/javascripts/react_app/components/common/ModalProgressBar/__tests__/ModalProgressBar.test.js b/webpack/assets/javascripts/react_app/components/common/ModalProgressBar/__tests__/ModalProgressBar.test.js index 6573b1ecd70..acdd062e93c 100644 --- a/webpack/assets/javascripts/react_app/components/common/ModalProgressBar/__tests__/ModalProgressBar.test.js +++ b/webpack/assets/javascripts/react_app/components/common/ModalProgressBar/__tests__/ModalProgressBar.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import ModalProgressBar from '../ModalProgressBar'; describe('ModalProgressBar', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/RedirectCancelButton/RedirectCancelButton.test.js b/webpack/assets/javascripts/react_app/components/common/RedirectCancelButton/RedirectCancelButton.test.js index 211a92a5fbc..f6a523afb8d 100644 --- a/webpack/assets/javascripts/react_app/components/common/RedirectCancelButton/RedirectCancelButton.test.js +++ b/webpack/assets/javascripts/react_app/components/common/RedirectCancelButton/RedirectCancelButton.test.js @@ -1,6 +1,6 @@ import React from 'react'; -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import RedirectCancelButton from './RedirectCancelButton'; diff --git a/webpack/assets/javascripts/react_app/components/common/SearchInput/SearchInput.test.js b/webpack/assets/javascripts/react_app/components/common/SearchInput/SearchInput.test.js index 74a4fa0a154..d2788a082b3 100644 --- a/webpack/assets/javascripts/react_app/components/common/SearchInput/SearchInput.test.js +++ b/webpack/assets/javascripts/react_app/components/common/SearchInput/SearchInput.test.js @@ -1,4 +1,4 @@ -import { shallow, mount } from '@theforeman/test'; +import { shallow, mount } from 'enzyme'; import React from 'react'; import SearchInput from './'; diff --git a/webpack/assets/javascripts/react_app/components/common/SkeletonLoader/SkeletonLoader.test.js b/webpack/assets/javascripts/react_app/components/common/SkeletonLoader/SkeletonLoader.test.js index 18957adc4ba..0b37bf7713b 100644 --- a/webpack/assets/javascripts/react_app/components/common/SkeletonLoader/SkeletonLoader.test.js +++ b/webpack/assets/javascripts/react_app/components/common/SkeletonLoader/SkeletonLoader.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import SkeletonLoader from '.'; import { STATUS } from '../../../constants'; const fixtures = { diff --git a/webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.test.js b/webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.test.js index 847f6cfbca1..560dbaa9555 100644 --- a/webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.test.js +++ b/webpack/assets/javascripts/react_app/components/common/charts/BarChart/BarChart.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import BarChart from './'; import * as chartService from '../../../../../services/charts/BarChartService'; diff --git a/webpack/assets/javascripts/react_app/components/common/charts/DonutChart/DonutChart.test.js b/webpack/assets/javascripts/react_app/components/common/charts/DonutChart/DonutChart.test.js index f82921cb624..33bda555cf8 100644 --- a/webpack/assets/javascripts/react_app/components/common/charts/DonutChart/DonutChart.test.js +++ b/webpack/assets/javascripts/react_app/components/common/charts/DonutChart/DonutChart.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import { mockData, emptyData } from './DonutChart.fixtures'; import DonutChart from './'; diff --git a/webpack/assets/javascripts/react_app/components/common/charts/LineChart/LineChart.test.js b/webpack/assets/javascripts/react_app/components/common/charts/LineChart/LineChart.test.js index 9262129308d..df6e5b5751a 100644 --- a/webpack/assets/javascripts/react_app/components/common/charts/LineChart/LineChart.test.js +++ b/webpack/assets/javascripts/react_app/components/common/charts/LineChart/LineChart.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import { data, timeseriesData } from './LineChart.fixtures'; import LineChart from './index'; diff --git a/webpack/assets/javascripts/react_app/components/common/dates/IsoDate.test.js b/webpack/assets/javascripts/react_app/components/common/dates/IsoDate.test.js index 8e48da64bb5..5afa3a6e377 100644 --- a/webpack/assets/javascripts/react_app/components/common/dates/IsoDate.test.js +++ b/webpack/assets/javascripts/react_app/components/common/dates/IsoDate.test.js @@ -1,6 +1,6 @@ /* eslint-disable promise/prefer-await-to-then */ // Configure Enzyme -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import React from 'react'; import IsoDate from './IsoDate'; import { i18nProviderWrapperFactory } from '../../../common/i18nProviderWrapperFactory'; diff --git a/webpack/assets/javascripts/react_app/components/common/dates/LongDateTime.test.js b/webpack/assets/javascripts/react_app/components/common/dates/LongDateTime.test.js index c4f096b10e9..8c5096f24b6 100644 --- a/webpack/assets/javascripts/react_app/components/common/dates/LongDateTime.test.js +++ b/webpack/assets/javascripts/react_app/components/common/dates/LongDateTime.test.js @@ -1,6 +1,6 @@ /* eslint-disable promise/prefer-await-to-then */ // Configure Enzyme -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import React from 'react'; import LongDateTime from './LongDateTime'; import { i18nProviderWrapperFactory } from '../../../common/i18nProviderWrapperFactory'; diff --git a/webpack/assets/javascripts/react_app/components/common/dates/RelativeDateTime.test.js b/webpack/assets/javascripts/react_app/components/common/dates/RelativeDateTime.test.js index 8a8b0f406d9..5bb5c2d8449 100644 --- a/webpack/assets/javascripts/react_app/components/common/dates/RelativeDateTime.test.js +++ b/webpack/assets/javascripts/react_app/components/common/dates/RelativeDateTime.test.js @@ -1,6 +1,6 @@ /* eslint-disable promise/prefer-await-to-then */ // Configure Enzyme -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import React from 'react'; import RelativeDateTime from './RelativeDateTime'; import { i18nProviderWrapperFactory } from '../../../common/i18nProviderWrapperFactory'; diff --git a/webpack/assets/javascripts/react_app/components/common/dates/ShortDateTime.test.js b/webpack/assets/javascripts/react_app/components/common/dates/ShortDateTime.test.js index d1f9c23e95d..ede7e7f046a 100644 --- a/webpack/assets/javascripts/react_app/components/common/dates/ShortDateTime.test.js +++ b/webpack/assets/javascripts/react_app/components/common/dates/ShortDateTime.test.js @@ -1,6 +1,6 @@ /* eslint-disable promise/prefer-await-to-then */ // Configure Enzyme -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import React from 'react'; import ShortDateTime from './ShortDateTime'; import { i18nProviderWrapperFactory } from '../../../common/i18nProviderWrapperFactory'; diff --git a/webpack/assets/javascripts/react_app/components/common/forms/Actions.test.js b/webpack/assets/javascripts/react_app/components/common/forms/Actions.test.js index c59a8f79871..631e557dc73 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/Actions.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/Actions.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import Actions from './Actions'; diff --git a/webpack/assets/javascripts/react_app/components/common/forms/CommonForm.test.js b/webpack/assets/javascripts/react_app/components/common/forms/CommonForm.test.js index 499d62a5050..7ced1ba0862 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/CommonForm.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/CommonForm.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import { FieldLevelHelp } from 'patternfly-react'; diff --git a/webpack/assets/javascripts/react_app/components/common/forms/CounterInput/__tests__/CounterInput.test.js b/webpack/assets/javascripts/react_app/components/common/forms/CounterInput/__tests__/CounterInput.test.js index c4c5f7ad739..0804dd8ae32 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/CounterInput/__tests__/CounterInput.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/CounterInput/__tests__/CounterInput.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import CounterInput from '../'; diff --git a/webpack/assets/javascripts/react_app/components/common/forms/ForemanForm/ForemanForm.test.js b/webpack/assets/javascripts/react_app/components/common/forms/ForemanForm/ForemanForm.test.js index 69376501234..9ffe1032921 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/ForemanForm/ForemanForm.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/ForemanForm/ForemanForm.test.js @@ -1,7 +1,7 @@ import { testComponentSnapshotsWithFixtures, testSelectorsSnapshotWithFixtures, -} from '@theforeman/test'; +} from 'foremanReact/common/testHelpers'; import * as Yup from 'yup'; import { prepareErrors } from '../../../../redux/actions/common/forms'; diff --git a/webpack/assets/javascripts/react_app/components/common/forms/ForemanForm/integration.test.js b/webpack/assets/javascripts/react_app/components/common/forms/ForemanForm/integration.test.js index 8f2aac4a75e..0cb262d0b42 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/ForemanForm/integration.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/ForemanForm/integration.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { IntegrationTestHelper } from '@theforeman/test'; +import IntegrationTestHelper from 'foremanReact/common/IntegrationTestHelper'; import { submitForm } from '../../../../redux/actions/common/forms'; diff --git a/webpack/assets/javascripts/react_app/components/common/forms/Form.test.js b/webpack/assets/javascripts/react_app/components/common/forms/Form.test.js index 104c6bca864..7e119ef5704 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/Form.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/Form.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import Form from './Form'; diff --git a/webpack/assets/javascripts/react_app/components/common/forms/OrderableSelect/__tests__/OrderableSelect.test.js b/webpack/assets/javascripts/react_app/components/common/forms/OrderableSelect/__tests__/OrderableSelect.test.js index 8e6d3370bee..c56603d92b5 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/OrderableSelect/__tests__/OrderableSelect.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/OrderableSelect/__tests__/OrderableSelect.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import { act } from 'react-dom/test-utils'; import { DndProvider } from 'react-dnd'; import TestBackend from 'react-dnd-test-backend/dist/cjs/TestBackend'; diff --git a/webpack/assets/javascripts/react_app/components/common/forms/RadioButtonGroup/RadioButtonGroup.test.js b/webpack/assets/javascripts/react_app/components/common/forms/RadioButtonGroup/RadioButtonGroup.test.js index fa976d91cad..465df746196 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/RadioButtonGroup/RadioButtonGroup.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/RadioButtonGroup/RadioButtonGroup.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import RadioButtonGroup from './RadioButtonGroup'; const radios = [ diff --git a/webpack/assets/javascripts/react_app/components/common/forms/Select.test.js b/webpack/assets/javascripts/react_app/components/common/forms/Select.test.js index 34bee4e78c6..962810eaaf4 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/Select.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/Select.test.js @@ -1,16 +1,15 @@ import 'select2'; -import { mount } from '@theforeman/test'; +import { mount } from 'enzyme'; import React from 'react'; import Select from './Select'; jest.unmock('jquery'); -beforeEach(() => { - document.body.innerHTML = '
\n \n
'; -}); - describe('Select', () => { + beforeEach(() => { + document.body.innerHTML = '
\n \n
'; + }); it('onChange called exactly once even after update', () => { const options = { one: '1', two: '2' }; const onChangeMock = jest.fn(); diff --git a/webpack/assets/javascripts/react_app/components/common/table/actions/selectionActions.test.js b/webpack/assets/javascripts/react_app/components/common/table/actions/selectionActions.test.js index 1a86916c2e1..a0062be8fc6 100644 --- a/webpack/assets/javascripts/react_app/components/common/table/actions/selectionActions.test.js +++ b/webpack/assets/javascripts/react_app/components/common/table/actions/selectionActions.test.js @@ -1,4 +1,4 @@ -import { testActionSnapshotWithFixtures } from '@theforeman/test'; +import { testActionSnapshotWithFixtures } from 'foremanReact/common/testHelpers'; import { selectPage, selectAllRows, diff --git a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/DeleteButton.test.js b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/DeleteButton.test.js index 6f3d3cf0451..74f77175333 100644 --- a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/DeleteButton.test.js +++ b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/DeleteButton.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import DeleteButton from '../DeleteButton'; const baseProps = { diff --git a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/HostsCountCell.test.js b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/HostsCountCell.test.js index 9abb4b68c56..39b2dbe2319 100644 --- a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/HostsCountCell.test.js +++ b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/HostsCountCell.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import HostsCountCell from '../HostsCountCell'; describe('HostsCountCell', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/NameCell.test.js b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/NameCell.test.js index 16abf01ce5b..97e1c4aff30 100644 --- a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/NameCell.test.js +++ b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/NameCell.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import NameCell from '../NameCell'; const fixtures = { diff --git a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/SortableHeader.test.js b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/SortableHeader.test.js index c71bc99a951..ef99b250276 100644 --- a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/SortableHeader.test.js +++ b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/SortableHeader.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import SortalbeHeader from '../SortableHeader'; describe('SortalbeHeader', () => { diff --git a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/TableSelectionCell.test.js b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/TableSelectionCell.test.js index 33cc20505fa..036069e352a 100644 --- a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/TableSelectionCell.test.js +++ b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/TableSelectionCell.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import TableSelectionCell from '../TableSelectionCell'; diff --git a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/TableSelectionHeaderCell.test.js b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/TableSelectionHeaderCell.test.js index c1156239134..a8670b93e09 100644 --- a/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/TableSelectionHeaderCell.test.js +++ b/webpack/assets/javascripts/react_app/components/common/table/components/__tests__/TableSelectionHeaderCell.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import TableSelectionHeaderCell from '../TableSelectionHeaderCell'; diff --git a/webpack/assets/javascripts/react_app/components/common/table/reducers/selectionReducer.test.js b/webpack/assets/javascripts/react_app/components/common/table/reducers/selectionReducer.test.js index 1969d7b5739..9ebd4dfb038 100644 --- a/webpack/assets/javascripts/react_app/components/common/table/reducers/selectionReducer.test.js +++ b/webpack/assets/javascripts/react_app/components/common/table/reducers/selectionReducer.test.js @@ -1,5 +1,5 @@ import Immutable from 'seamless-immutable'; -import { testReducerSnapshotWithFixtures } from '@theforeman/test'; +import { testReducerSnapshotWithFixtures } from 'foremanReact/common/testHelpers'; import { SELECT_ROWS, UNSELECT_ROWS, diff --git a/webpack/assets/javascripts/react_app/components/hosts/powerStatus/__tests__/PowerStatus.test.js b/webpack/assets/javascripts/react_app/components/hosts/powerStatus/__tests__/PowerStatus.test.js index 9d675419380..b7d77304916 100644 --- a/webpack/assets/javascripts/react_app/components/hosts/powerStatus/__tests__/PowerStatus.test.js +++ b/webpack/assets/javascripts/react_app/components/hosts/powerStatus/__tests__/PowerStatus.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import PowerStatus from '../PowerStatus'; import { pendingProps, diff --git a/webpack/assets/javascripts/react_app/components/hosts/storage/vmware/controller/controller.test.js b/webpack/assets/javascripts/react_app/components/hosts/storage/vmware/controller/controller.test.js index 17047e500aa..1104d403c1d 100644 --- a/webpack/assets/javascripts/react_app/components/hosts/storage/vmware/controller/controller.test.js +++ b/webpack/assets/javascripts/react_app/components/hosts/storage/vmware/controller/controller.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import { props } from './controller.fixtures'; diff --git a/webpack/assets/javascripts/react_app/components/hosts/storage/vmware/controller/disk/disk.test.js b/webpack/assets/javascripts/react_app/components/hosts/storage/vmware/controller/disk/disk.test.js index 684aa44e7fb..91357e83526 100644 --- a/webpack/assets/javascripts/react_app/components/hosts/storage/vmware/controller/disk/disk.test.js +++ b/webpack/assets/javascripts/react_app/components/hosts/storage/vmware/controller/disk/disk.test.js @@ -1,4 +1,4 @@ -import { shallow } from '@theforeman/test'; +import { shallow } from 'enzyme'; import React from 'react'; import { props } from './disk.fixtures'; diff --git a/webpack/assets/javascripts/react_app/mockRequests.js b/webpack/assets/javascripts/react_app/mockRequests.js index 954b7cb8518..19cd5b61721 100644 --- a/webpack/assets/javascripts/react_app/mockRequests.js +++ b/webpack/assets/javascripts/react_app/mockRequests.js @@ -1,5 +1,5 @@ import axios from 'axios'; -import { MockAdapter } from '@theforeman/test'; +import MockAdapter from 'axios-mock-adapter'; export const mock = () => new MockAdapter(axios); const methods = { diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/helpers.test.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/helpers.test.js index 5f7134be1e2..d7ed1810840 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/helpers.test.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/helpers.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow, render } from '@theforeman/test'; +import { shallow, render } from 'enzyme' import { FormSelectOption } from '@patternfly/react-core'; import { emptyOption, validatedOS, osHelperText } from '../RegistrationCommandsPageHelpers' diff --git a/webpack/assets/javascripts/react_app/routes/__test__/Routes.test.js b/webpack/assets/javascripts/react_app/routes/__test__/Routes.test.js index 386cb612b81..413e2cd5d3c 100644 --- a/webpack/assets/javascripts/react_app/routes/__test__/Routes.test.js +++ b/webpack/assets/javascripts/react_app/routes/__test__/Routes.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import AppSwitcher from '../'; import { children } from './ForemanSwitcher.fixtures' diff --git a/webpack/assets/javascripts/react_app/routes/common/PageLayout/components/ExportButton/ExportButton.test.js b/webpack/assets/javascripts/react_app/routes/common/PageLayout/components/ExportButton/ExportButton.test.js index d9178abcb93..903bf388f25 100644 --- a/webpack/assets/javascripts/react_app/routes/common/PageLayout/components/ExportButton/ExportButton.test.js +++ b/webpack/assets/javascripts/react_app/routes/common/PageLayout/components/ExportButton/ExportButton.test.js @@ -1,4 +1,4 @@ -import { testComponentSnapshotsWithFixtures } from '@theforeman/test'; +import { testComponentSnapshotsWithFixtures } from 'foremanReact/common/testHelpers'; import ExportButton from './ExportButton'; diff --git a/webpack/assets/javascripts/services/charts/LineChartService.test.js b/webpack/assets/javascripts/services/charts/LineChartService.test.js index 60d51c31a9a..55962aca57d 100644 --- a/webpack/assets/javascripts/services/charts/LineChartService.test.js +++ b/webpack/assets/javascripts/services/charts/LineChartService.test.js @@ -1,4 +1,4 @@ -import { testActionSnapshotWithFixtures } from '@theforeman/test'; +import { testActionSnapshotWithFixtures } from 'foremanReact/common/testHelpers'; import { getLineChartConfig } from './LineChartService'; import { From 229eae30f190b4d1684cee663a8745a33abb794a Mon Sep 17 00:00:00 2001 From: MariaAga Date: Tue, 9 Jul 2024 19:39:18 +0100 Subject: [PATCH 2/3] Fixes #37637 - Test plugins from foreman core --- .eslintrc | 6 +- .github/workflows/plugins_react_tests.yml | 30 +++- babel.config.js | 3 + package-exclude.json | 1 + package.json | 23 ++- script/npm_test_plugin.js | 140 ++++++++++++++++++ script/plugin_webpack_directories.js | 18 +++ .../TemplateGeneratorActions.test.js | 12 +- webpack/{test_setup.js => core_test_setup.js} | 7 + webpack/global_test_setup.js | 19 +++ webpack/jest.config.js | 79 ++++++++++ webpack/resolveNodeModule.js | 61 ++++++++ webpack/theforeman_test_dependencies.js | 36 +++++ 13 files changed, 421 insertions(+), 14 deletions(-) create mode 100644 babel.config.js create mode 100755 script/npm_test_plugin.js rename webpack/{test_setup.js => core_test_setup.js} (73%) create mode 100644 webpack/global_test_setup.js create mode 100644 webpack/jest.config.js create mode 100644 webpack/resolveNodeModule.js create mode 100644 webpack/theforeman_test_dependencies.js diff --git a/.eslintrc b/.eslintrc index 0de7f9bd00b..fd4ccd83cf5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -24,6 +24,7 @@ "auditable", "Autocompletion", "autogenerated", + "axios", "bool", "bootable", "Borderless", @@ -107,6 +108,7 @@ "noopener", "noreferrer", "nowrap", + "npx", "num", "numpad", "operatingsystem", @@ -159,6 +161,7 @@ "textarea", "textfield", "tfm", + "theforeman", "timepicker", "timerdelay", "timeseries", @@ -192,6 +195,7 @@ "minLength": 3 } ], - "@theforeman/rules/require-ouiaid": ["error"] + "@theforeman/rules/require-ouiaid": ["error"], + "import/no-extraneous-dependencies": "off", } } diff --git a/.github/workflows/plugins_react_tests.yml b/.github/workflows/plugins_react_tests.yml index 7d0f7184b7c..551b3e9c710 100644 --- a/.github/workflows/plugins_react_tests.yml +++ b/.github/workflows/plugins_react_tests.yml @@ -16,6 +16,9 @@ concurrency: group: ${{ github.ref_name }}-${{ github.workflow }} cancel-in-progress: true +env: + BUNDLE_WITHOUT: "console:development:journald:libvirt" + jobs: setup_matrix: name: Setup matrix @@ -45,11 +48,11 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - # We could update the postinstall action for foreman to look for an environment variable for plugin webpack dirs - # before kicking off the ruby script to find them, this would eliminate the ruby dep and running `npm install` in plugins. - - uses: ruby/setup-ruby@v1 + - name: "Set up Ruby ${{ matrix.ruby }}" + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} + bundler-cache: true - name: Checkout Foreman uses: actions/checkout@v4 with: @@ -65,12 +68,29 @@ jobs: with: repository: ${{ matrix.plugin }} path: ${{ github.workspace }}/projects/plugin + - name: store plugin name + run: echo "PLUGIN_NAME=$(echo ${{ matrix.plugin }} | awk -F'/' '{print $NF}')" >> "${GITHUB_ENV}" + - name: Set up plugin in Foreman + run: | + echo "gemspec name: '$PLUGIN_NAME', path: '${{ github.workspace }}/projects/plugin'" > "bundler.d/$PLUGIN_NAME.local.rb" + if [ -d $PLUGIN_NAME/gemfile.d ] ; then + cat $PLUGIN_NAME/gemfile.d/*.rb >> bundler.d/$PLUGIN_NAME.local.rb + fi + working-directory: ${{ github.workspace }}/projects/foreman - name: Generate ${{ matrix.plugin }} npm dependencies package-lock run: npm install --package-lock-only --no-audit --legacy-peer-deps working-directory: ${{ github.workspace }}/projects/plugin - name: Install ${{ matrix.plugin }} npm dependencies run: npm ci --no-audit --legacy-peer-deps working-directory: ${{ github.workspace }}/projects/plugin + - run: sudo apt-get update + - run: sudo apt-get -qq -y install build-essential libcurl4-openssl-dev zlib1g-dev libpq-dev libvirt-dev + - name: Install gems + run: bundle install + working-directory: ${{ github.workspace }}/projects/foreman + - name: Run plugin webpack dir to test + run: ./script/plugin_webpack_directories.rb + working-directory: ${{ github.workspace }}/projects/foreman - name: Run ${{ matrix.plugin }} tests - run: npm test - working-directory: ${{ github.workspace }}/projects/plugin + run: npm run test:plugins $(echo ${{ matrix.plugin }} | awk -F'/' '{print $NF}') + working-directory: ${{ github.workspace }}/projects/foreman diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 00000000000..773205911e8 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + presets: [require.resolve('@theforeman/builder/babel')], +}; diff --git a/package-exclude.json b/package-exclude.json index 3b9dabad042..747d37d055f 100644 --- a/package-exclude.json +++ b/package-exclude.json @@ -1,5 +1,6 @@ { "EXCLUDE_NPM_PACKAGES": [ + "@apollo/react-testing", "@sheerun/mutationobserver-shim", "@theforeman/env", "@theforeman/eslint-plugin-foreman", diff --git a/package.json b/package.json index 7ae5676471f..ab646babe27 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,10 @@ "lint:custom": "eslint ./webpack", "foreman-js:link": "./script/npm_link_foreman_js.sh", "postlint": "./script/npm_lint_plugins.js", - "test": "tfm-test", + "test": "npx jest --setupFilesAfterEnv ./global_test_setup.js ./core_test_setup.js --testPathIgnorePatterns '/node_modules/' '/.+fixtures.+' --config ./webpack/jest.config.js", "test:watch": "tfm-test --watchAll", "test:current": "tfm-test --watch", + "test:plugins": "./script/npm_test_plugin.js", "publish-coverage": "tfm-publish-coverage", "postinstall": "./script/npm_install_plugins.js", "analyze": "./script/webpack-analyze" @@ -29,28 +30,45 @@ "react-intl": "^2.8.0" }, "devDependencies": { + "@apollo/react-testing": "^4.0.0", "@babel/core": "^7.7.0", + "@testing-library/jest-dom": "^5.3.0", + "@testing-library/react": "^10.0.2", + "@testing-library/react-hooks": "^3.4.2", "@theforeman/builder": "^13.1.0", "@theforeman/eslint-plugin-foreman": "^13.1.0", "@theforeman/eslint-plugin-rules": "^13.1.0", - "@theforeman/test": "^13.1.0", + "@theforeman/vendor-core": "^13.1.0", "@theforeman/vendor-dev": "^13.1.0", "@types/jest": "<27.0.0", "argv-parse": "^1.0.1", + "axios-mock-adapter": "^1.1.7", "babel-eslint": "^10.0.0", + "babel-jest": "^26.3.0", "babel-loader": "^8.0.0", "buffer": "^5.7.1", + "cheerio": "1.0.0-rc.10", "compression-webpack-plugin": "^10.0.0", "cross-env": "^5.2.0", "css-loader": "^6.8.1", "dotenv": "^5.0.0", + "enzyme": "^3.11.0", + "enzyme-adapter-react-16": "^1.15.2", + "enzyme-to-json": "^3.4.3", "eslint": "^6.7.2", "eslint-plugin-spellcheck": "0.0.17", "graphql": "^15.5.0", + "identity-obj-proxy": "^3.0.0", + "jest": "^26.4.0", + "jest-prop-type-error": "^1.1.0", + "jest-svg-transformer": "^1.0.0", + "jest-transform-graphql": "^2.1.0", "path-browserify": "^1.0.1", "prettier": "^1.19.1", "pretty-format": "26.6.2", "react-dnd-test-backend": "^9.4.0", + "react-redux-test-utils": "^0.2.0", + "react-test-renderer": "^17.0.1", "redux-mock-store": "^1.2.2", "sass": "~1.60.0", "sass-loader": "^13.3.2", @@ -59,6 +77,7 @@ "stylelint-config-standard": "^18.0.0", "tabbable": "~5.2.0", "victory-core": "~36.8.6", + "victory-legend": "~36.8.6", "victory-pie": "~36.8.6", "webpack": "^5.75.0", "webpack-bundle-analyzer": "^4.5.0", diff --git a/script/npm_test_plugin.js b/script/npm_test_plugin.js new file mode 100755 index 00000000000..cf3f59a7a3a --- /dev/null +++ b/script/npm_test_plugin.js @@ -0,0 +1,140 @@ +#!/usr/bin/env node +/* eslint-disable import/no-dynamic-require */ +/* eslint-disable no-console */ +/* eslint-disable no-var */ + +/* This script is used to run tests for all plugins that have a `lint` script defined in their package.json + To run tests for an individual plugin, pass the plugin name as the first argument to the script + For example, to run tests for the `foreman-tasks` plugin, run: `npm run test-plugin foreman-tasks` + To pass arguments to jest, pass them after the plugin name like so: `npm run test-plugin foreman-tasks -- --debug` +*/ + +var fs = require('fs'); +var path = require('path'); +var lodash = require('lodash'); +var childProcess = require('child_process'); +var { packageJsonDirsObject } = require('./plugin_webpack_directories'); + +const passedArgs = process.argv.slice(2); +const coreConfigPath = path.resolve(__dirname, '../webpack/jest.config.js'); +const coreConfig = require(coreConfigPath); + +function runChildProcess(args, pluginPath) { + return new Promise((resolve, reject) => { + const child = childProcess.spawn('npx', args, { + shell: true, + }); + // this is needed to make sure the output is not cut + let stdoutBuffer = ''; + child.stdout.on('data', data => { + stdoutBuffer += data.toString(); + const lines = stdoutBuffer.split('\n'); + stdoutBuffer = lines.pop(); + }); + + let stderrBuffer = `${pluginPath}: \n`; + child.stderr.on('data', data => { + stderrBuffer += data.toString(); + const lines = stderrBuffer.split('\n'); + stderrBuffer = lines.pop(); + lines.forEach(line => console.error(line)); + }); + child.on('close', code => { + if (stdoutBuffer) console.log(stdoutBuffer); + if (stderrBuffer) console.error(stderrBuffer); + if (code === 0) { + resolve(); + } else { + reject(new Error(`Child process exited with code ${code}`)); + } + }); + }); +} +const runTests = async () => { + var dirs = packageJsonDirsObject(); + var dirsKeys = Object.keys(dirs); + function pluginDefinesLint(pluginPath) { + var packageHasNodeModules = fs.existsSync(`${pluginPath}/node_modules`); // skip gems + var packageData = JSON.parse(fs.readFileSync(`${pluginPath}/package.json`)); + + return ( + packageHasNodeModules && packageData.scripts && packageData.scripts.lint + ); + } + if (passedArgs[0] && passedArgs[0][0] !== '-') { + // if the argument is --debug and not a plugin name npm test:plugins katello --debug + dirsKeys = dirsKeys.filter(dir => dir.endsWith(passedArgs[0])); + passedArgs.shift(); + } + function customizer(objValue, srcValue) { + if (lodash.isArray(objValue)) { + return lodash.uniq(objValue.concat(srcValue)); + } + return undefined; + } + // eslint-disable-next-line no-unused-vars + for (const dirsKey of dirsKeys) { + const pluginPath = dirs[dirsKey]; + if (pluginDefinesLint(pluginPath)) { + const testSetupFiles = [ + path.resolve(__dirname, '../webpack/global_test_setup.js'), + ]; + const testSetupPath = path.join(pluginPath, 'webpack', 'test_setup.js'); + if (fs.existsSync(testSetupPath)) { + testSetupFiles.unshift(testSetupPath); + } + const pluginConfigPath = path.join(pluginPath, 'jest.config.js'); + const combinedConfigPath = path.join( + pluginPath, + 'combined.jest.config.js' + ); + + if (fs.existsSync(pluginConfigPath)) { + // eslint-disable-next-line global-require + const pluginConfig = require(pluginConfigPath); + + const combinedConfig = lodash.mergeWith( + pluginConfig, + { + ...coreConfig, + setupFilesAfterEnv: [ + path.resolve(__dirname, '../webpack/global_test_setup.js'), + ], + }, + customizer + ); + combinedConfig.snapshotSerializers = coreConfig.snapshotSerializers; + fs.writeFileSync( + combinedConfigPath, + `module.exports = ${JSON.stringify(combinedConfig, null, 2)};`, + 'utf8' + ); + } + const pluginConfigOverride = fs.existsSync(pluginConfigPath); + const configPath = pluginConfigOverride + ? combinedConfigPath + : coreConfigPath; + const corePath = path.resolve(__dirname, '../'); + const args = [ + 'jest', + '--roots', + pluginPath, + corePath, + `--config=${configPath}`, + pluginConfigOverride + ? '' + : `--setupFilesAfterEnv ${testSetupFiles.join(' ')}`, + '--color', + ...passedArgs, + ]; + + // eslint-disable-next-line no-await-in-loop + await runChildProcess(args, pluginPath); // Run every plugin test in a separate process + if (fs.existsSync(combinedConfigPath)) { + fs.unlinkSync(combinedConfigPath); + } + } + } +}; + +runTests(); diff --git a/script/plugin_webpack_directories.js b/script/plugin_webpack_directories.js index 08d006e9c10..32bbed9a7aa 100644 --- a/script/plugin_webpack_directories.js +++ b/script/plugin_webpack_directories.js @@ -15,6 +15,19 @@ var sanitizeWebpackDirs = pluginDirs => { return splitDirs.length > 2 ? splitDirs[1] : pluginDirs; }; +var pluginPathObject = file => pluginsObj => { + var paths = {}; + Object.keys(pluginsObj.plugins).forEach(entryKey => { + if (!entryKey.includes(':')) { + const pluginPath = pluginsObj.plugins[entryKey].root; + if (fs.existsSync(path.join(pluginPath, file))) { + paths[entryKey] = pluginPath; + } + } + }); + return paths; +}; + // Get paths that have a specific file or folder var pluginPath = file => pluginsObj => { var paths = []; @@ -53,11 +66,16 @@ var getPluginDirs = stderr => var packageJsonDirs = stderr => pluginPath('package.json')(getPluginDirs(stderr)).map(path.dirname); +// Get plugin paths with the plugin name, dont assume the plugin path will have the plugin name +var packageJsonDirsObject = stderr => + pluginPathObject('package.json')(getPluginDirs(stderr)); + module.exports = { getPluginDirs, pluginNodeModules: pluginPath('node_modules'), aliasPlugins, packageJsonDirs, + packageJsonDirsObject, sanitizeWebpackDirs, pluginPath, }; diff --git a/webpack/assets/javascripts/react_app/components/TemplateGenerator/__tests__/TemplateGeneratorActions.test.js b/webpack/assets/javascripts/react_app/components/TemplateGenerator/__tests__/TemplateGeneratorActions.test.js index a3554f42fdb..05e8fba8f40 100644 --- a/webpack/assets/javascripts/react_app/components/TemplateGenerator/__tests__/TemplateGeneratorActions.test.js +++ b/webpack/assets/javascripts/react_app/components/TemplateGenerator/__tests__/TemplateGeneratorActions.test.js @@ -21,15 +21,16 @@ import * as actions from '../TemplateGeneratorActions'; jest.mock('file-saver'); jest.mock('../../../redux/API'); -beforeEach(() => { - API.post.mockImplementation(async () => scheduleResponse); - API.get.mockImplementation(async () => noContentResponse); -}); - describe('TemplateGeneratorActions', () => { + beforeAll(() => { + jest.useFakeTimers(); + }); beforeEach(() => { API.post.mockClear(); API.get.mockClear(); + + API.post.mockImplementation(async () => scheduleResponse); + API.get.mockImplementation(async () => noContentResponse); }); describe('generateTemplate', () => { @@ -55,7 +56,6 @@ describe('TemplateGeneratorActions', () => { API.get .mockImplementationOnce(async () => noContentResponse) .mockImplementationOnce(async () => generatedReportResponse); - runActionInDepth(() => actions.generateTemplate(), 3).then(callTree => { const successAction = callTree[1][1][1]; expect(successAction).toHaveProperty('type', TEMPLATE_GENERATE_SUCCESS); diff --git a/webpack/test_setup.js b/webpack/core_test_setup.js similarity index 73% rename from webpack/test_setup.js rename to webpack/core_test_setup.js index c7158276891..d22b70ab381 100644 --- a/webpack/test_setup.js +++ b/webpack/core_test_setup.js @@ -6,13 +6,20 @@ ace.config.set('themePath', ''); jest.mock('jed'); jest.mock('./assets/javascripts/react_app/Root/Context/ForemanContext', () => ({ + getForemanContext: () => ({ + context: { metadata: { version: 'mocked_version' } }, + }), + useForemanContext: () => ({ metadata: { version: 'mocked_version' } }), + useForemanSetContext: () => {}, useForemanVersion: () => 'mocked_version', useForemanSettings: () => ({ perPage: 5 }), useForemanDocUrl: () => '/url', useForemanLocation: () => ({ title: 'location' }), useForemanOrganization: () => ({ title: 'organization' }), + useForemanUser: () => ({ login: 'user' }), getHostsPageUrl: displayNewHostsPage => displayNewHostsPage ? '/new/hosts' : '/hosts', + useForemanHostsPageUrl: () => '/hosts', })); jest.mock('./assets/javascripts/react_app/common/I18n'); jest.mock('./assets/javascripts/foreman_tools', () => ({ diff --git a/webpack/global_test_setup.js b/webpack/global_test_setup.js new file mode 100644 index 00000000000..de6724309e2 --- /dev/null +++ b/webpack/global_test_setup.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line import/no-unresolved, import/extensions +import 'core-js/shim'; +// eslint-disable-next-line import/no-extraneous-dependencies +import 'regenerator-runtime/runtime'; + +const { configure } = require('enzyme'); +const Adapter = require('enzyme-adapter-react-16'); + +configure({ adapter: new Adapter() }); + +// https://github.com/facebook/jest/issues/6121 +// eslint-disable-next-line no-console +const { error } = console; +// eslint-disable-next-line no-console +console.error = (message, ...args) => { + error.apply(console, args); // keep default behaviour + const err = message instanceof Error ? message : new Error(message); + throw err; +}; diff --git a/webpack/jest.config.js b/webpack/jest.config.js new file mode 100644 index 00000000000..b1c5e8a4b80 --- /dev/null +++ b/webpack/jest.config.js @@ -0,0 +1,79 @@ +/* eslint-disable spellcheck/spell-checker */ +const fs = require('fs'); +const path = require('path'); + +const nodeModules = path.resolve(__dirname, '..', 'node_modules'); +const packageJsonPath = path.resolve(__dirname, '..', 'package.json'); +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); +const vendorCorePackageJsonPath = path.resolve( + nodeModules, + '@theforeman/vendor-core', + 'package.json' +); +const vendorCorePackageJson = JSON.parse( + fs.readFileSync(vendorCorePackageJsonPath, 'utf8') +); + +const dependencies = { + ...packageJson.dependencies, + ...packageJson.devDependencies, + ...vendorCorePackageJson.dependencies, + '@apollo/client/testing': '@apollo/client/testing', +}; // Use shared dependencies from foreman node_modules and not plugin node_modules to avoid jest errors due to multiple instances of same package + +const moduleNameMapper = {}; +Object.keys(dependencies).forEach(dep => { + moduleNameMapper[`^${dep}$`] = path.resolve(nodeModules, dep); +}); + +const foremanReactFull = path.resolve( + __dirname, + 'assets/javascripts/react_app' +); +const foremanTest = path.resolve(__dirname, 'theforeman_test_dependencies.js'); + +module.exports = { + verbose: true, + logHeapUsage: true, + maxWorkers: 2, + collectCoverage: true, + coverageReporters: ['lcov'], + coverageDirectory: `../coverage`, + setupFiles: [require.resolve('jest-prop-type-error')], + testRegex: '.*\\.test\\.js$', + testPathIgnorePatterns: [ + '/node_modules/', + '/foreman/', + '/.+fixtures.+', + 'foreman/webpack', // dont test foreman core in plugins + ], + moduleDirectories: [ + `node_modules`, + `/node_modules/@theforeman/vendor-core/node_modules`, + `node_modules/@theforeman/vendor-core/node_modules`, + '/node_modules', + ], + transform: { + '^.+\\.js?$': 'babel-jest', + '\\.(gql|graphql)$': require.resolve('jest-transform-graphql'), // for graphql-tag + }, + snapshotSerializers: [require.resolve('enzyme-to-json/serializer')], + moduleNameMapper: { + '^.+\\.(png|gif|css|scss)$': 'identity-obj-proxy', + ...moduleNameMapper, + '^dnd-core$': `${nodeModules}/dnd-core/dist/cjs`, + '^react-dnd$': `${nodeModules}/react-dnd/dist/cjs`, + '^react-dnd-html5-backend$': `${nodeModules}/react-dnd-html5-backend/dist/cjs`, + '^react-dnd-touch-backend$': `${nodeModules}/react-dnd-touch-backend/dist/cjs`, + '^react-dnd-test-backend$': `${nodeModules}/react-dnd-test-backend/dist/cjs`, + '^react-dnd-test-utils$': `${nodeModules}/react-dnd-test-utils/dist/cjs`, + '^foremanReact(.*)$': `${foremanReactFull}/$1`, + '^@theforeman/test$': foremanTest, + '^victory(.*)$': `${nodeModules}/victory$1`, + }, + globals: { + __testing__: true, + URL_PREFIX: '', + }, + resolver: require.resolve('./resolveNodeModule'), +}; diff --git a/webpack/resolveNodeModule.js b/webpack/resolveNodeModule.js new file mode 100644 index 00000000000..8acba3b6474 --- /dev/null +++ b/webpack/resolveNodeModule.js @@ -0,0 +1,61 @@ +const { modules } = require('@theforeman/vendor-core'); + +const isRequestedByVendorCore = currentFileDirectory => + (currentFileDirectory.includes('foreman-js/packages/vendor-core') || + currentFileDirectory.includes('@theforeman/vendor-core')) && + !currentFileDirectory.includes( + 'foreman-js/packages/vendor-core/node_modules' + ) && + !currentFileDirectory.includes('@theforeman/vendor-core/node_modules'); + +const getModuleToResolve = ({ sourcePath, currentFileDirectory }) => { + // map the custom foreman js module to the correct path + const requestPath = sourcePath === '.' ? './index' : sourcePath; + const sourcePathSplit = sourcePath.split('/'); + const name = sourcePathSplit[sourcePathSplit.length - 1]; + const vendorModule = modules.find(m => m.name === name); + const requestedByVendorCore = isRequestedByVendorCore(currentFileDirectory); + + const shouldResolveCustomVendorModule = modules.find( + m => m.name === name && m.hasCustomPath && !requestedByVendorCore + ); + + return shouldResolveCustomVendorModule ? vendorModule.path : requestPath; +}; + +/** + * resolve a import/require of a node module + * this method should be calld by the jest-resolver + * to resolve every require statement + * This cannot be done with changing the paths with moduleNameMapper + */ + +const resolveNodeModule = (sourcePath, currentFile) => { + const { basedir, rootDir } = currentFile; + const moduleToResolve = getModuleToResolve({ + sourcePath, + currentFileDirectory: basedir, + }); + if (sourcePath.includes('theforeman_test_dependencies')) { + console.warn( + 'import from @theforeman/test is deprecated, please remove the package and import from enzyme, axios-mock-adapter, foremanReact/testHelpers, foremanReact/common/IntegrationTestHelper directly instead.' + ); + } + let results; + try { + results = require.resolve(moduleToResolve, { + paths: [basedir], + }); + } catch (error) { + results = currentFile.defaultResolver(moduleToResolve, currentFile); + } + + return rootDir + ? results.replace( + /.*\/foreman-js\/packages/, + `${rootDir}/node_modules/@theforeman` + ) + : results; +}; + +module.exports = resolveNodeModule; diff --git a/webpack/theforeman_test_dependencies.js b/webpack/theforeman_test_dependencies.js new file mode 100644 index 00000000000..eb747effd53 --- /dev/null +++ b/webpack/theforeman_test_dependencies.js @@ -0,0 +1,36 @@ +// replaces @theforeman/test.js +import { shallow, mount, render, configure } from 'enzyme'; +import MockAdapter from 'axios-mock-adapter'; + +import { + mockWindowLocation, + classFunctionUnitTest, + shallowRenderComponentWithFixtures, + testComponentSnapshotsWithFixtures, + runActionInDepth, + testActionSnapshot, + testActionSnapshotWithFixtures, + testReducerSnapshotWithFixtures, + testSelectorsSnapshotWithFixtures, + initMockStore, +} from './assets/javascripts/react_app/common/testHelpers'; +import IntegrationTestHelper from './assets/javascripts/react_app/common/IntegrationTestHelper'; + +export { + mockWindowLocation, + classFunctionUnitTest, + shallowRenderComponentWithFixtures, + testComponentSnapshotsWithFixtures, + runActionInDepth, + testActionSnapshot, + testActionSnapshotWithFixtures, + testReducerSnapshotWithFixtures, + testSelectorsSnapshotWithFixtures, + initMockStore, + IntegrationTestHelper, + shallow, + mount, + render, + configure, + MockAdapter, +}; From 2f92ad0ac30aa59b6355d094d4c1204e4666cbd5 Mon Sep 17 00:00:00 2001 From: MariaAga Date: Fri, 13 Sep 2024 15:24:58 +0100 Subject: [PATCH 3/3] Fixes #37639 - Use own lint instead of @theforeman --- .eslintrc | 201 ---------------- .eslintrc.js | 21 ++ .github/workflows/js_tests.yml | 2 - package.json | 11 +- .../@foreman/eslint-plugin-custom/index.js | 7 + .../eslint-plugin-custom/require-ouiaid.js | 84 +++++++ script/lint/link-eslint-plugin.js | 33 +++ script/lint/lint_core_config.js | 214 ++++++++++++++++++ script/lint/lint_generic_config.js | 66 ++++++ script/lint/plugin-lint.js | 32 +++ webpack/resolveNodeModule.js | 2 +- 11 files changed, 465 insertions(+), 208 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.js create mode 100644 script/lint/@foreman/eslint-plugin-custom/index.js create mode 100644 script/lint/@foreman/eslint-plugin-custom/require-ouiaid.js create mode 100644 script/lint/link-eslint-plugin.js create mode 100644 script/lint/lint_core_config.js create mode 100644 script/lint/lint_generic_config.js create mode 100644 script/lint/plugin-lint.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index fd4ccd83cf5..00000000000 --- a/.eslintrc +++ /dev/null @@ -1,201 +0,0 @@ -{ - "plugins": [ - "@theforeman/foreman", - "spellcheck", - "@theforeman/rules" - ], - "extends": "plugin:@theforeman/foreman/core", - "rules": { - "spellcheck/spell-checker": [ - "warn", - { - "comments": false, - "identifiers": false, - "strings": true, - "lang": "en_US", - "ignoreRequire": false, - "skipWords": [ - "2xl", - "45vh", - "4xl", - "ampm", - "Ansible", - "ascii", - "auditable", - "Autocompletion", - "autogenerated", - "axios", - "bool", - "bootable", - "Borderless", - "btns", - "candlepin", - "centos", - "checkbox", - "clearbutton", - "clearfix", - "comms", - "consts", - "cpu", - "csrf", - "csv", - "datacenter", - "datastore", - "datastores", - "datepicker", - "datetime", - "datetimepicker", - "debian", - "decrement", // should be removed once https://github.com/aotaduy/eslint-plugin-spellcheck/issues/67 is resolved. - "devs", - "dgettext", - "dngettext", - "donut", - "dow", - "dropdown", - "dropdowns", - "ec2", - "erb", - "fieldset", - "fnc", - "formatter", - "fqdn", - "func", - "gettext", - "glyphicon", - "gpg", - "graphql", - "gridster", - "hostdetails", - "hostgroup", - "hostgroups", - "href", - "hypervisor", - "i386", - "internets", - "ip6", - "IPv4", - "IPv6", - "javascript", - "javascripts", - "jed", - "katello", - "keybind", - "keydown", - "keypress", - "klasses", - "labelledby", - "lang", - "ldap", - "loc", - "locs", - "lsi", - "matcher", - "menuitem", - "monokai", - "mousedown", - "mouseup", - "msg", - "nailgun", - "nat", - "navitem", - "netgroups", - "networksurl", - "ngettext", - "nic", - "nfs", - "nonpersistent", - "noopener", - "noreferrer", - "nowrap", - "npx", - "num", - "numpad", - "operatingsystem", - "operatingsystems", - "orderable", - "orgs", - "ownfield", - "paravirtual", - "patternfly", - "pficon", - "poolsurl", - "popstate", - "pqr", - "ptable", - "puppetclass", - "puppetclasses", - "pxe_loader", - "Pv", - "qcow2", - "rbt", - "readonly", - "redhat", - "redux", - "refetches", - "rendering", - "repo", - "resize", - "rex", - "rhel", - "safemode", - "sbs", - "scrollable", - "scsi", - "securityfailure", - "sizex", - "sizey", - "Solaris", - "sparc", - "storages", - "stringified", - "subcomponent", - "subcomponents", - "subnav", - "subnet", - "subnets", - "substate", - "svg", - "testoption", - "testoption", - "textarea", - "textfield", - "tfm", - "theforeman", - "timepicker", - "timerdelay", - "timeseries", - "tlv", - "tooltip", - "turbolinks", - "twipsy", - "txt", - "typeahead", - "ubuntu", - "uncheck", - "unencrypted", - "unmount", - "unordered", - "unprocessable", - "unselect", - "unstyled", - "virtualization", - "vms", - "vmware", - "vnc", - "vnic", - "webpack", - "wss", - "x86_64", - "xml", - "xpi", - "xyz", - "yaml" - ], - "minLength": 3 - } - ], - "@theforeman/rules/require-ouiaid": ["error"], - "import/no-extraneous-dependencies": "off", - } -} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000000..f3452815619 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,21 @@ +const lintCoreConfig = require('./script/lint/lint_core_config.js'); +const lintGenericConfig = require('./script/lint/lint_generic_config.js'); + +const combinedConfig = { + ...lintCoreConfig, + ...lintGenericConfig, + rules: { + ...lintCoreConfig.rules, + ...lintGenericConfig.rules, + }, + plugins: [ + ...(lintCoreConfig.plugins || []), + ...(lintGenericConfig.plugins || []), + ], + extends: [ + ...(lintCoreConfig.extends || []), + ...(lintGenericConfig.extends || []), + ], +}; + +module.exports = combinedConfig; diff --git a/.github/workflows/js_tests.yml b/.github/workflows/js_tests.yml index 7501009fb3e..cddfe11b63e 100644 --- a/.github/workflows/js_tests.yml +++ b/.github/workflows/js_tests.yml @@ -52,8 +52,6 @@ jobs: run: npm ci --no-audit - name: Run linter run: npm run lint - - name: Run custom eslint rules Spellcheck (only warnings) and missing ouia-ids - run: npm run lint:custom - name: Run tests run: npm run test - name: Publish Coveralls diff --git a/package.json b/package.json index ab646babe27..eb6d9740d1f 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "node": ">=14.0.0 <21.0.0" }, "scripts": { - "lint": "tfm-lint", - "lint:custom": "eslint ./webpack", + "lint": "eslint ./webpack ./script", + "prelint": "node ./script/lint/link-eslint-plugin.js", "foreman-js:link": "./script/npm_link_foreman_js.sh", "postlint": "./script/npm_lint_plugins.js", "test": "npx jest --setupFilesAfterEnv ./global_test_setup.js ./core_test_setup.js --testPathIgnorePatterns '/node_modules/' '/.+fixtures.+' --config ./webpack/jest.config.js", @@ -36,8 +36,6 @@ "@testing-library/react": "^10.0.2", "@testing-library/react-hooks": "^3.4.2", "@theforeman/builder": "^13.1.0", - "@theforeman/eslint-plugin-foreman": "^13.1.0", - "@theforeman/eslint-plugin-rules": "^13.1.0", "@theforeman/vendor-core": "^13.1.0", "@theforeman/vendor-dev": "^13.1.0", "@types/jest": "<27.0.0", @@ -57,12 +55,17 @@ "enzyme-to-json": "^3.4.3", "eslint": "^6.7.2", "eslint-plugin-spellcheck": "0.0.17", + "eslint-plugin-patternfly-react": "0.2.0", + "eslint-plugin-jquery": "^1.5.1", + "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-react-hooks": "^2.1.1", "graphql": "^15.5.0", "identity-obj-proxy": "^3.0.0", "jest": "^26.4.0", "jest-prop-type-error": "^1.1.0", "jest-svg-transformer": "^1.0.0", "jest-transform-graphql": "^2.1.0", + "jsx-ast-utils": "^3.3.3", "path-browserify": "^1.0.1", "prettier": "^1.19.1", "pretty-format": "26.6.2", diff --git a/script/lint/@foreman/eslint-plugin-custom/index.js b/script/lint/@foreman/eslint-plugin-custom/index.js new file mode 100644 index 00000000000..337fc704241 --- /dev/null +++ b/script/lint/@foreman/eslint-plugin-custom/index.js @@ -0,0 +1,7 @@ +const requireOuiaidRule = require('./require-ouiaid'); + +module.exports = { + rules: { + 'require-ouiaid': requireOuiaidRule, + }, +}; diff --git a/script/lint/@foreman/eslint-plugin-custom/require-ouiaid.js b/script/lint/@foreman/eslint-plugin-custom/require-ouiaid.js new file mode 100644 index 00000000000..2254b202a99 --- /dev/null +++ b/script/lint/@foreman/eslint-plugin-custom/require-ouiaid.js @@ -0,0 +1,84 @@ +const getProp = require('jsx-ast-utils/getProp'); + +module.exports = { + create(context) { + const patternflyImports = new Set(); + const options = context.options.length + ? context.options + : [ + 'Alert', + 'Breadcrumb', + 'Button', + 'Card', + 'Checkbox', + 'Chip', + 'ChipGroup', + 'ContextSelector', + 'Dropdown', + 'DropdownItem', + 'DropdownSeparator', + 'DropdownToggle', + 'DropdownToggleCheckbox', + 'FormSelect', + 'Menu', + 'Modal', + 'ModalBoxCloseButton', + 'ModalContent', + 'Nav', + 'NavExpandable', + 'NavItem', + 'OptionsMenu', + 'Pagination', + 'Radio', + 'RowWrapper', + 'Select', + 'Switch', + 'TabButton', + 'TabContent', + 'Tab', + 'Tabs', + 'Text', + 'TextInput', + 'Title', + 'Toolbar', + 'Table', + 'TableComposable', + 'Tr', + ]; + + function addPatternflyImport(node) { + if ( + node.type === 'ImportDeclaration' && + node.source.value.startsWith('@patternfly/react') + ) { + node.specifiers.forEach(specifier => { + if (specifier.type === 'ImportSpecifier') { + patternflyImports.add(specifier.local.name); + } + }); + } + } + + function checkPatternflyComponent(node) { + if (!options.includes(node.name.name)) { + return; + } + if ( + node.type === 'JSXOpeningElement' && + patternflyImports.has(node.name.name) + ) { + const ouiaIdProp = getProp(node.attributes, 'ouiaId'); + if (!ouiaIdProp) { + context.report({ + node, + message: `ouiaId property is missing in PatternFly component '${node.name.name}'`, + }); + } + } + } + return { + ImportDeclaration: addPatternflyImport, + JSXOpeningElement: checkPatternflyComponent, + }; + }, +}; diff --git a/script/lint/link-eslint-plugin.js b/script/lint/link-eslint-plugin.js new file mode 100644 index 00000000000..c196235f9ad --- /dev/null +++ b/script/lint/link-eslint-plugin.js @@ -0,0 +1,33 @@ +/* eslint-disable no-console */ +const fs = require('fs'); +const path = require('path'); + +function linkEslintPlugin(runPath = process.cwd()) { + // instead of creating an npm package for the custom eslint plugin, we symlink it + // eslint will only search for plugins in node_modules, so we need to symlink it there + const sourceDir = path.join(__dirname, '@foreman'); + const destinationDir = path.join(runPath, 'node_modules', '@foreman'); + function createSymlink() { + fs.symlink(sourceDir, destinationDir, 'dir', err => { + if (err) { + console.error('Error creating symlink:', err); + } + }); + } + + // Check if the symlink exists and remove it if it does + fs.lstat(destinationDir, (err, stats) => { + if (!err && stats.isSymbolicLink()) { + fs.unlink(destinationDir, unlinkErr => { + if (unlinkErr) { + console.error('Error removing existing symlink:', unlinkErr); + return; + } + createSymlink(); + }); + } else { + createSymlink(); + } + }); +} +linkEslintPlugin(); diff --git a/script/lint/lint_core_config.js b/script/lint/lint_core_config.js new file mode 100644 index 00000000000..c95dde0a92b --- /dev/null +++ b/script/lint/lint_core_config.js @@ -0,0 +1,214 @@ +module.exports = { + plugins: ['spellcheck'], + rules: { + 'spellcheck/spell-checker': [ + 'warn', + { + comments: false, + identifiers: false, + strings: true, + lang: 'en_US', + ignoreRequire: false, + skipWords: [ + '2xl', + '45vh', + '4xl', + 'ampm', + 'Ansible', + 'ascii', + 'auditable', + 'Autocompletion', + 'autogenerated', + 'axios', + 'bool', + 'bootable', + 'Borderless', + 'btns', + 'candlepin', + 'centos', + 'checkbox', + 'clearbutton', + 'clearfix', + 'comms', + 'Composable', + 'consts', + 'cpu', + 'csrf', + 'csv', + 'datacenter', + 'datastore', + 'datastores', + 'datepicker', + 'datetime', + 'datetimepicker', + 'debian', + 'decrement', // should be removed once https://github.com/aotaduy/eslint-plugin-spellcheck/issues/67 is resolved. + 'devs', + 'dgettext', + 'dngettext', + 'donut', + 'dow', + 'dropdown', + 'dropdowns', + 'ec2', + 'erb', + 'fieldset', + 'fnc', + 'formatter', + 'fqdn', + 'func', + 'gettext', + 'glyphicon', + 'gpg', + 'graphql', + 'gridster', + 'hostdetails', + 'hostgroup', + 'hostgroups', + 'href', + 'hypervisor', + 'i386', + 'internets', + 'ip6', + 'IPv4', + 'IPv6', + 'javascript', + 'javascripts', + 'jed', + 'katello', + 'keybind', + 'keydown', + 'keypress', + 'klasses', + 'labelledby', + 'lang', + 'ldap', + 'loc', + 'locs', + 'lsi', + 'matcher', + 'menuitem', + 'monokai', + 'mousedown', + 'mouseup', + 'msg', + 'nailgun', + 'nat', + 'navitem', + 'netgroups', + 'networksurl', + 'ngettext', + 'nic', + 'nfs', + 'nonpersistent', + 'noopener', + 'noreferrer', + 'nowrap', + 'npx', + 'num', + 'numpad', + 'operatingsystem', + 'operatingsystems', + 'orderable', + 'orgs', + 'ouia', + 'ouiaid', + 'ownfield', + 'paravirtual', + 'patternfly', + 'pficon', + 'poolsurl', + 'popstate', + 'pqr', + 'ptable', + 'puppetclass', + 'puppetclasses', + 'pxe_loader', + 'Pv', + 'qcow2', + 'rbt', + 'readonly', + 'redhat', + 'redux', + 'refetches', + 'rendering', + 'repo', + 'resize', + 'rex', + 'rhel', + 'safemode', + 'sbs', + 'scrollable', + 'scsi', + 'securityfailure', + 'sizex', + 'sizey', + 'Solaris', + 'sparc', + 'storages', + 'stringified', + 'subcomponent', + 'subcomponents', + 'subnav', + 'subnet', + 'subnets', + 'substate', + 'svg', + 'symlink', + 'Symlink', + 'testoption', + 'testoption', + 'textarea', + 'textfield', + 'tfm', + 'theforeman', + 'timepicker', + 'timerdelay', + 'timeseries', + 'tlv', + 'tooltip', + 'turbolinks', + 'twipsy', + 'txt', + 'typeahead', + 'ubuntu', + 'uncheck', + 'unencrypted', + 'unmount', + 'unordered', + 'unprocessable', + 'unselect', + 'unstyled', + 'utf8', + 'virtualization', + 'vms', + 'vmware', + 'vnc', + 'vnic', + 'webpack', + 'wss', + 'x86_64', + 'xml', + 'xpi', + 'xyz', + 'yaml', + ], + minLength: 3, + }, + ], + + 'import/no-extraneous-dependencies': 'off', + 'import/no-unresolved': [ + 'error', + { + ignore: ['foremanReact/.*'], + }, + ], + 'import/extensions': [ + 'error', + { + ignore: ['foremanReact/.*'], + }, + ], + }, +}; diff --git a/script/lint/lint_generic_config.js b/script/lint/lint_generic_config.js new file mode 100644 index 00000000000..cfe331566d1 --- /dev/null +++ b/script/lint/lint_generic_config.js @@ -0,0 +1,66 @@ +module.exports = { + plugins: [ + 'patternfly-react', + 'promise', + 'jquery', + 'react-hooks', + '@foreman/custom', + ], + extends: [ + 'plugin:patternfly-react/recommended', + require.resolve('@theforeman/vendor-dev/eslint.extends.js'), + 'plugin:jquery/deprecated', + ], + rules: { + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', + 'max-lines': [ + 'error', + { + max: 300, + skipBlankLines: true, + skipComments: true, + }, + ], + 'no-restricted-syntax': [ + 'error', + { + selector: 'ForInStatement', + message: + 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.', + }, + { + selector: 'LabeledStatement', + message: + 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.', + }, + { + selector: 'WithStatement', + message: + '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', + }, + ], + 'promise/prefer-await-to-then': 'error', + 'prettier/prettier': [ + 'error', + { + singleQuote: true, + trailingComma: 'es5', + }, + ], + 'import/no-unresolved': [ + 'error', + { + ignore: ['foremanReact/.*'], + }, + ], + 'import/extensions': [ + 'error', + { + ignore: ['foremanReact/.*'], + }, + ], + 'import/no-extraneous-dependencies': 'off', + '@foreman/custom/require-ouiaid': 'error', + }, +}; diff --git a/script/lint/plugin-lint.js b/script/lint/plugin-lint.js new file mode 100644 index 00000000000..d5924572ed4 --- /dev/null +++ b/script/lint/plugin-lint.js @@ -0,0 +1,32 @@ +/* eslint-disable no-console */ +// This script is used to lint the plugin codebase using the generic eslint configuration. +// usage in package.json: +// "scripts": { +// "lint": "node ../foreman/script/lint/plugin-lint.js" +// }, +// or in a custom script with @theforeman/find-foreman + +const { spawn, execSync } = require('child_process'); +const path = require('path'); + +try { + const sciptPath = path.join(__dirname, 'link-eslint-plugin.js'); + execSync(`node ${sciptPath}`, { stdio: 'inherit' }); +} catch (error) { + console.error(`Error: ${error.message}`); +} + +const eslintConfigPath = path.join(__dirname, '/lint_generic_config.js'); +const eslint = spawn('npx', ['eslint', './webpack', '-c', eslintConfigPath], { + stdio: 'inherit', +}); + +eslint.on('error', error => { + console.error(`Error: ${error.message}`); +}); + +eslint.on('close', code => { + if (code !== 0) { + console.error(`ESLint process exited with code ${code}`); + } +}); diff --git a/webpack/resolveNodeModule.js b/webpack/resolveNodeModule.js index 8acba3b6474..686554588f9 100644 --- a/webpack/resolveNodeModule.js +++ b/webpack/resolveNodeModule.js @@ -39,7 +39,7 @@ const resolveNodeModule = (sourcePath, currentFile) => { if (sourcePath.includes('theforeman_test_dependencies')) { console.warn( 'import from @theforeman/test is deprecated, please remove the package and import from enzyme, axios-mock-adapter, foremanReact/testHelpers, foremanReact/common/IntegrationTestHelper directly instead.' - ); + ); // eslint-disable-line no-console } let results; try {