Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Fixing jest warnings and errors #86532

Merged
merged 7 commits into from
Dec 21, 2020

Conversation

stephmilovic
Copy link
Contributor

@stephmilovic stephmilovic commented Dec 18, 2020

Summary

Another round of jest error/warning fixes. Fixes detailed in the files.

There were 2 warnings I gave up on clearing if anyone wants to take a crack at them. Same warning on 2 files.

  • management/pages/endpoint_hosts/view/index.test.tsx
  • common/components/query_bar/index.test.tsx
The warning/error:
 console.error
    Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
        in QueryStringInputUI (created by EnhancedType)
        in EnhancedType (created by QueryBarTopRow)
        in div (created by EuiFlexItem)
        in EuiFlexItem (created by QueryBarTopRow)
        in div (created by EuiFlexGroup)
        in EuiFlexGroup (created by QueryBarTopRow)
        in QueryBarTopRow (created by SearchBarUI)
        in div (created by SearchBarUI)
        in SearchBarUI (created by EnhancedType)
        in EnhancedType (created by InjectIntl(EnhancedType))
        in InjectIntl(EnhancedType) (created by WrappedSearchBar)
        in Suspense (created by WrappedSearchBar)
        in WrappedSearchBar (created by EnhancedType)
        in EnhancedType (created by InjectIntl(EnhancedType))
        in InjectIntl(EnhancedType)
        in Unknown (created by Proxy)
        in Provider (created by App)
        in App (created by ErrorBoundary)
        in ErrorBoundary (created by DragDropContext)
        in DragDropContext (created by TestProvidersComponent)
        in ThemeProvider (created by TestProvidersComponent)
        in Provider (created by TestProvidersComponent)
        in ApolloProvider (created by TestProvidersComponent)
        in Provider
        in Unknown (created by TestProvidersComponent)
        in PseudoLocaleWrapper (created by I18nProvider)
        in IntlProvider (created by I18nProvider)
        in I18nProvider (created by TestProvidersComponent)
        in TestProvidersComponent (created by Proxy)
        in Proxy

      144 |
      145 |     if (!currentAbortController.signal.aborted) {
    > 146 |       this.setState({
          |            ^
      147 |         indexPatterns: [...objectPatterns, ...objectPatternsFromStrings],
      148 |       });
      149 |

      at warningWithoutStack (node_modules/react-dom/cjs/react-dom.development.js:530:32)
      at warnAboutUpdateOnUnmountedFiberInDEV (node_modules/react-dom/cjs/react-dom.development.js:25738:5)
      at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:23679:5)
      at Object.enqueueSetState (node_modules/react-dom/cjs/react-dom.development.js:13994:5)
      at QueryStringInputUI.setState (node_modules/react/cjs/react.development.js:325:16)
      at QueryStringInputUI.<anonymous> (src/plugins/data/public/ui/query_string_input/query_string_input.tsx:146:12)

Checklist

Delete any items that are not applicable to this PR.

@stephmilovic stephmilovic added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.12.0 Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Dec 18, 2020
@@ -101,17 +101,17 @@ const CaseActionBarComponent: React.FC<CaseActionBarProps> = ({
<EuiDescriptionList compressed>
<EuiFlexGroup gutterSize="l" alignItems="center">
<EuiFlexItem>
<EuiDescriptionListTitle>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clears up the following error that showed in cases/components/case_view/index.test.tsx

Warning: validateDOMNesting(...): <dt> cannot appear as a descendant of <dd>.
  in dt (created by EuiDescriptionListTitle)
  in EuiDescriptionListTitle (created by CaseActionBarComponent)
  in dd (created by EuiDescriptionListDescription)
  in EuiDescriptionListDescription (created by CaseActionBarComponent)
  in div (created by EuiFlexItem)

<EventDetails {...alertsProps} />
</TestProviders>
) as ReactWrapper;
await waitFor(() => wrapper.update());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clears up the following error:

    Warning: An update to SummaryViewComponent inside a test was not wrapped in act(...).

    When testing, code that causes React state updates should be wrapped into act(...):

    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */

    This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
        in SummaryViewComponent (created by EventDetailsComponent)
        in div (created by EuiTabbedContent)
        in div (created by EuiTabbedContent)
        in EuiTabbedContent (created by Styled(EuiTabbedContent))
        in Styled(EuiTabbedContent) (created by EventDetailsComponent)
        in EventDetailsComponent

@@ -84,7 +91,7 @@ const eventsViewerDefaultProps = {
sort: [
{
columnId: 'foo',
sortDirection: 'none' as SortDirection,
sortDirection: 'asc' as SortDirection,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clears up the following error:

    Warning: Failed prop type: Invalid prop `sorting.columns[0].direction` of value `none` supplied to `EuiDataGridColumnSortingDraggable`, expected one of ["asc","desc"].
        in EuiDataGridColumnSortingDraggable (created by ColumnHeadersComponent)
        in ColumnHeadersComponent
        in ColumnHeadersComponent
        in div (created by styled.div)
        in styled.div
        in div (created by TimelineBody)
        in TimelineBody

const original = jest.requireActual('@elastic/eui');
return {
...original,
useDataGridColumnSorting: jest.fn(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clears up the following error:

    Warning: Failed prop type: The prop `display` is marked as required in `EuiDataGridColumnSortingDraggable`, but its value is `undefined`.
        in EuiDataGridColumnSortingDraggable (created by ColumnHeadersComponent)
        in ColumnHeadersComponent
        in ColumnHeadersComponent
        in div (created by styled.div)
        in styled.div
        in div (created by TimelineBody)
        in TimelineBody

@@ -25,6 +25,7 @@ import {
} from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
import { getFoundListSchemaMock } from '../../../../../../lists/common/schemas/response/found_list_schema.mock';
import { getEmptyValue } from '../../empty_value';
import { waitFor } from '@testing-library/dom';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the waitFors clear up a couple of these errors:

    Warning: An update to AutocompleteFieldMatchAny inside a test was not wrapped in act(...).

    When testing, code that causes React state updates should be wrapped into act(...):

    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */

    This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
        in AutocompleteFieldMatchAny (created by BuilderEntryItem)
        in div (created by EuiFlexItem)

@@ -8,12 +8,18 @@ import { mount } from 'enzyme';
import { I18nProvider } from '@kbn/i18n/react';

import { LastUpdatedAt } from './';
jest.mock('@kbn/i18n/react', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clears up the following warning:

  console.warn
    Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

    * Move data fetching code or side effects to componentDidUpdate.
    * If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
    * Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

    Please update the following components: FormattedRelative

@@ -71,7 +72,7 @@ describe('anomaly_scores', () => {
</TestProviders>
);
wrapper.find('[data-test-subj="anomaly-score-popover"]').first().simulate('click');
wrapper.update();
await waitFor(() => wrapper.update());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clears up the following warning:

    console.error
      Warning: An update to ExplorerLink inside a test was not wrapped in act(...).

      When testing, code that causes React state updates should be wrapped into act(...):

      act(() => {
        /* fire events that update state */
      });
      /* assert on the output */

      This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
          in ExplorerLink (created by AnomalyScoreComponent)
          in div (created by EuiFlexItem)
          in EuiFlexItem (created by AnomalyScoreComponent)
          in div (created by EuiFlexGroup)
          in EuiFlexGroup (created by AnomalyScoreComponent)

@@ -134,7 +135,7 @@ describe('anomaly_scores', () => {
</TestProviders>
);
wrapper.find('[data-test-subj="anomaly-score-popover"]').first().simulate('click');
wrapper.update();
await waitFor(() => wrapper.update());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clears up the following warning:

Warning: An update to ExplorerLink inside a test was not wrapped in act(...).

      When testing, code that causes React state updates should be wrapped into act(...):

      act(() => {
        /* fire events that update state */
      });
      /* assert on the output */

      This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
          in ExplorerLink (created by AnomalyScoreComponent)
          in div (created by EuiFlexItem)
          in EuiFlexItem (created by AnomalyScoreComponent)
          in div (created by EuiFlexGroup)
          in EuiFlexGroup (created by AnomalyScoreComponent)

@@ -10,6 +10,7 @@ import { mockAnomalies } from '../mock';
import { createDescriptionList } from './create_description_list';
import { EuiDescriptionList } from '@elastic/eui';
import { Anomaly } from '../types';
import { waitFor } from '@testing-library/dom';
Copy link
Contributor Author

@stephmilovic stephmilovic Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clears up the following error:

    Warning: An update to ExplorerLink inside a test was not wrapped in act(...).

    When testing, code that causes React state updates should be wrapped into act(...):

    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */

    This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
        in ExplorerLink
        in div (created by EuiFlexItem)
        in EuiFlexItem
        in div (created by EuiFlexGroup)
        in EuiFlexGroup
        in dd (created by EuiDescriptionListDescription)
        in EuiDescriptionListDescription (created by EuiDescriptionList)
        in dl (created by EuiDescriptionList)
        in EuiDescriptionList (created by WrapperComponent)

return outline ? (
<EuiButton data-test-subj={`${dataTestSubjPrefix}-with-border`} {...buttonProps}>
{title}
</EuiButton>
) : (
<EuiButtonEmpty data-test-subj={dataTestSubjPrefix} color="text" {...buttonProps}>
<EuiButtonEmpty data-test-subj={dataTestSubjPrefix} color="text" {...propsWithoutFill}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clears the following error from the test for this file:

    Warning: Received `true` for a non-boolean attribute `fill`.

    If you want to write it to the DOM, pass a string instead: fill="true" or fill={value.toString()}.
        in button (created by EuiButtonEmpty)
        in EuiButtonEmpty (created by WrapperComponent)
        in WrapperComponent

@@ -23,6 +23,7 @@ import {
getDataProviderFilter,
TIMELINE_FILTER_DROP_AREA,
} from './index';
import { waitFor } from '@testing-library/dom';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clears the following error:

Warning: An update to null inside a test was not wrapped in act(...).

    When testing, code that causes React state updates should be wrapped into act(...):

    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */

    This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
        in Unknown (created by Proxy)
        in Provider (created by App)
        in App (created by ErrorBoundary)
        in ErrorBoundary (created by DragDropContext)
        in DragDropContext (created by TestProvidersComponent)
        in ThemeProvider (created by TestProvidersComponent)
        in Provider (created by TestProvidersComponent)
        in ApolloProvider (created by TestProvidersComponent)
        in Provider
        in Unknown (created by TestProvidersComponent)
        in PseudoLocaleWrapper (created by I18nProvider)
        in IntlProvider (created by I18nProvider)
        in I18nProvider (created by TestProvidersComponent)
        in TestProvidersComponent (created by Proxy)
        in Proxy (created by WrapperComponent)
        in WrapperComponent

@stephmilovic stephmilovic requested review from yctercero, cnasikas and angorayc and removed request for yctercero December 18, 2020 20:57
@stephmilovic stephmilovic marked this pull request as ready for review December 18, 2020 20:57
@stephmilovic stephmilovic requested review from a team as code owners December 18, 2020 20:57
Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for doing this!! 🚀

@cnasikas
Copy link
Member

@elasticmachine merge upstream

Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 8.5MB 8.5MB +809.0B

Distributable file count

id before after diff
default 47142 47902 +760

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@stephmilovic stephmilovic merged commit 513138b into elastic:master Dec 21, 2020
@stephmilovic stephmilovic deleted the fixing-jest branch December 21, 2020 15:18
stephmilovic added a commit to stephmilovic/kibana that referenced this pull request Dec 21, 2020
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 23, 2020
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

8 similar comments
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

stephmilovic added a commit that referenced this pull request Jan 5, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants