Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] [Fleet] [Cloud Security] Add Testing Library ESLint for handlin…
…g waitFor (#198735) (#199067) # Backport This will backport the following commits from `main` to `8.x`: - [[Fleet] [Cloud Security] Add Testing Library ESLint for handling waitFor (#198735)](#198735) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Paulo Silva","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-05T22:34:18Z","message":"[Fleet] [Cloud Security] Add Testing Library ESLint for handling waitFor (#198735)\n\n## Summary\r\n\r\nThis PR aims to fix Flaky tests related to agentless detected by\r\nhttps://github.com//issues/189038 and\r\nhttps://github.com//issues/192126 by adding proper\r\nhandling of the `waitFor` methods.\r\n\r\nIt was also detected with\r\nhttps://github.com/elastic/security-team/issues/10979 that some other\r\nmethods were not proper handled by `waitFor`, leading to the assertions\r\ninside those unhandled `waitFor` being skipped by Jest.\r\n\r\nThis PR also introduces ESLint to enforce proper handling of waitFor\r\nmethods in tests files for Fleet and Cloud Security plugins.\r\n\r\nAdditional note: These changes should also unblock the failing tests on\r\nthe [React18 use waitFor with assertion callbacks in place of\r\nwaitForNextUpdate](#195087) PR\r\n\r\n\r\n**Fleet changes**\r\n\r\n- ESLint rule added to enforce handling `waitFor` on React Testing\r\nLibrary.\r\n- `useSetupTechnology` hook tests reviewed and updated to handle the\r\nwaitFor. Fixed issue identified when reviewing the tests.\r\n- step_define_package_policy.test.tsx: Added package policy vars to the\r\nmock to proper handle the use cases\r\n- step_select_hosts.test.tsx: Handled waitFor, identified outdated test\r\n- step_edit_hosts.test.tsx: Handled waitFor, identified outdated test\r\nWith the introduction of the ESLint rule other tests were triggering\r\nESLint errors, I attempted to fix them while retaining the same\r\nintention, let me know if more changes are needed.\r\n\r\n**Cloud Security changes**\r\n\r\n- ESLint rule added to enforce handling `waitFor` on React Testing\r\nLibrary.\r\n- Updated cloud security posture version to include agentless global\r\ntags on End to End tests\r\n\r\n**@elastic/kibana-operations changes**\r\n\r\n- Added\r\n[eslint-plugin-testing-library](https://testing-library.com/docs/ecosystem-eslint-plugin-testing-library/)\r\nan ESLint plugin for Testing Library that helps users to follow best\r\npractices and anticipate common mistakes when writing tests.\r\n- The adoption and enablement of the rules are opt-in.","sha":"5ab59fba401a189c290e55b3f73fd4fd23106e13","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","Team:Cloud Security","v8.16.0","backport:version","v8.17.0"],"number":198735,"url":"https://github.com/elastic/kibana/pull/198735","mergeCommit":{"message":"[Fleet] [Cloud Security] Add Testing Library ESLint for handling waitFor (#198735)\n\n## Summary\r\n\r\nThis PR aims to fix Flaky tests related to agentless detected by\r\nhttps://github.com//issues/189038 and\r\nhttps://github.com//issues/192126 by adding proper\r\nhandling of the `waitFor` methods.\r\n\r\nIt was also detected with\r\nhttps://github.com/elastic/security-team/issues/10979 that some other\r\nmethods were not proper handled by `waitFor`, leading to the assertions\r\ninside those unhandled `waitFor` being skipped by Jest.\r\n\r\nThis PR also introduces ESLint to enforce proper handling of waitFor\r\nmethods in tests files for Fleet and Cloud Security plugins.\r\n\r\nAdditional note: These changes should also unblock the failing tests on\r\nthe [React18 use waitFor with assertion callbacks in place of\r\nwaitForNextUpdate](#195087) PR\r\n\r\n\r\n**Fleet changes**\r\n\r\n- ESLint rule added to enforce handling `waitFor` on React Testing\r\nLibrary.\r\n- `useSetupTechnology` hook tests reviewed and updated to handle the\r\nwaitFor. Fixed issue identified when reviewing the tests.\r\n- step_define_package_policy.test.tsx: Added package policy vars to the\r\nmock to proper handle the use cases\r\n- step_select_hosts.test.tsx: Handled waitFor, identified outdated test\r\n- step_edit_hosts.test.tsx: Handled waitFor, identified outdated test\r\nWith the introduction of the ESLint rule other tests were triggering\r\nESLint errors, I attempted to fix them while retaining the same\r\nintention, let me know if more changes are needed.\r\n\r\n**Cloud Security changes**\r\n\r\n- ESLint rule added to enforce handling `waitFor` on React Testing\r\nLibrary.\r\n- Updated cloud security posture version to include agentless global\r\ntags on End to End tests\r\n\r\n**@elastic/kibana-operations changes**\r\n\r\n- Added\r\n[eslint-plugin-testing-library](https://testing-library.com/docs/ecosystem-eslint-plugin-testing-library/)\r\nan ESLint plugin for Testing Library that helps users to follow best\r\npractices and anticipate common mistakes when writing tests.\r\n- The adoption and enablement of the rules are opt-in.","sha":"5ab59fba401a189c290e55b3f73fd4fd23106e13"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198735","number":198735,"mergeCommit":{"message":"[Fleet] [Cloud Security] Add Testing Library ESLint for handling waitFor (#198735)\n\n## Summary\r\n\r\nThis PR aims to fix Flaky tests related to agentless detected by\r\nhttps://github.com//issues/189038 and\r\nhttps://github.com//issues/192126 by adding proper\r\nhandling of the `waitFor` methods.\r\n\r\nIt was also detected with\r\nhttps://github.com/elastic/security-team/issues/10979 that some other\r\nmethods were not proper handled by `waitFor`, leading to the assertions\r\ninside those unhandled `waitFor` being skipped by Jest.\r\n\r\nThis PR also introduces ESLint to enforce proper handling of waitFor\r\nmethods in tests files for Fleet and Cloud Security plugins.\r\n\r\nAdditional note: These changes should also unblock the failing tests on\r\nthe [React18 use waitFor with assertion callbacks in place of\r\nwaitForNextUpdate](#195087) PR\r\n\r\n\r\n**Fleet changes**\r\n\r\n- ESLint rule added to enforce handling `waitFor` on React Testing\r\nLibrary.\r\n- `useSetupTechnology` hook tests reviewed and updated to handle the\r\nwaitFor. Fixed issue identified when reviewing the tests.\r\n- step_define_package_policy.test.tsx: Added package policy vars to the\r\nmock to proper handle the use cases\r\n- step_select_hosts.test.tsx: Handled waitFor, identified outdated test\r\n- step_edit_hosts.test.tsx: Handled waitFor, identified outdated test\r\nWith the introduction of the ESLint rule other tests were triggering\r\nESLint errors, I attempted to fix them while retaining the same\r\nintention, let me know if more changes are needed.\r\n\r\n**Cloud Security changes**\r\n\r\n- ESLint rule added to enforce handling `waitFor` on React Testing\r\nLibrary.\r\n- Updated cloud security posture version to include agentless global\r\ntags on End to End tests\r\n\r\n**@elastic/kibana-operations changes**\r\n\r\n- Added\r\n[eslint-plugin-testing-library](https://testing-library.com/docs/ecosystem-eslint-plugin-testing-library/)\r\nan ESLint plugin for Testing Library that helps users to follow best\r\npractices and anticipate common mistakes when writing tests.\r\n- The adoption and enablement of the rules are opt-in.","sha":"5ab59fba401a189c290e55b3f73fd4fd23106e13"}},{"branch":"8.16","label":"v8.16.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
- Loading branch information