[IM] Remove axios dependency in tests#128171
Conversation
| const status = error ? error.status || 400 : 200; | ||
| const body = error ? error.body : response; | ||
|
|
||
| server.respondWith('GET', `${API_BASE_PATH}/index_templates/:id`, [ |
There was a problem hiding this comment.
With sinon fake server we could use wildcards for url params, that is no longer allowed with HttpSetup mock. So we need to directly specify the full url when mocking api endpoints. For this particular case would look something like:
const setLoadTemplateResponse = (
templateId: string,
response?: HttpResponse,
error?: ResponseError
) => mockResponse('GET', `${API_BASE_PATH}/index_templates/${templateId}`, response, error);|
Pinging @elastic/platform-deployment-management (Team:Deployment Management) |
|
@elasticmachine merge upstream |
|
expected head sha didn’t match current head ref. |
alisonelizabeth
left a comment
There was a problem hiding this comment.
Great work with this @sabarasaba! That was a lot of tests 😅 . I left a few comments. Let me know what you think.
| JSON.stringify(body), | ||
| ]); | ||
| }; | ||
| const registerHttpRequestMockHelpers = ( |
There was a problem hiding this comment.
Starting here to L56 seems to be the same code across the test refactoring PRs. Does it make sense to try to centralize it somewhere so it can be reused?
There was a problem hiding this comment.
If you agree, I think this can be done as a separate PR
There was a problem hiding this comment.
I've suggested also to put this somewhere in kbn-test (see this thread), but we ended up agreeing on keeping separate implementations per app for now. I'll create a new issue after on our side to update this later on after I finish updating all the tests.
x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts
Show resolved
Hide resolved
| const { find, exists, actions, component } = testBed; | ||
|
|
||
| // Composable templates | ||
| httpRequestsMockHelpers.setLoadTemplateResponse(templates[0].name, templates[0]); |
There was a problem hiding this comment.
can you explain why this wasn't needed previously?
There was a problem hiding this comment.
When an index flyout is opened a new api request for getting details for that index is called. With the sinon route for mocking the setLoadTemplateResponse we had a wildcard that would load the same payload for any templateId. So the top level mock we have set up at the beginning of the describe was working just fine. But since we now have to directly specify for each templateId, we need to specify each request.
There was a problem hiding this comment.
👍 got it. Makes sense.
x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts
Show resolved
Hide resolved
x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts
Show resolved
Hide resolved
x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts
Show resolved
Hide resolved
x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts
Show resolved
Hide resolved
|
|
||
| component.update(); | ||
|
|
||
| find('indexTableIndexNameLink').at(0).simulate('click'); |
There was a problem hiding this comment.
can you explain why this wasn't needed before?
There was a problem hiding this comment.
Since the testBed instance does't get re-initialized in a top levelbeforeEach, this test was wrongly depending on the testBed instance that is initialized in the previous describe. So we need to specifically declare it in its own describe scope.
...s/index_management/__jest__/client_integration/index_template_wizard/template_clone.test.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.test.ts
Show resolved
Hide resolved
|
Thanks for the review @alisonelizabeth, I know it was a lot of things! I think i've addressed your feedback, let me know what you think :) |
alisonelizabeth
left a comment
There was a problem hiding this comment.
Latest LGTM. Awesome work!
|
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: cc @sabarasaba |
(cherry picked from commit 00f58ad) # Conflicts: # x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/home/home.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts # x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_clone.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_create.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_edit.helpers.ts # x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_create.helpers.ts # x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_details.helpers.ts # x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_edit.helpers.ts
* [IM] Remove `axios` dependency in tests (#128171) (cherry picked from commit 00f58ad) # Conflicts: # x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/home/home.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/home/indices_tab.test.ts # x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_clone.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_create.helpers.ts # x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_edit.helpers.ts # x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_create.helpers.ts # x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_details.helpers.ts # x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/component_template_edit.helpers.ts * Fix linter issues * Fix broken tests
Partially addresses #127966
Summary
In order to upgrade the axios dependency in kibana(see: #111655) we need to switch the tests from this app to use HttpSetup mock instead of axios + sinon server mock, which is technically incorrect but axios just happened to have methods signature similar to HttpSetup.
Note: There's a bunch of CIT's for
component_templatesthat live inx-pack/plugins/index_management/public/application/components/component_templates/__jest__, ideally thesetup_environment.tsandhttp_request.tsfiles could be refactored into just one. I've created an issue for dealing with that #128376