kibana/docs/developer/contributing/development-unit-tests.asciidoc
Pierre Gayvallet 19de8b4950
[8.x] Sustainable Kibana Architecture: Move modules owned by @elastic/kibana-data-discovery (#205267)
**Manual backport of https://github.com/elastic/kibana/pull/203152**

## Summary

This PR aims at relocating some of the Kibana modules (plugins and
packages) into a new folder structure, according to the _Sustainable
Kibana Architecture_ initiative.

> [!IMPORTANT]
> * We kindly ask you to:
> * Manually fix the errors in the error section below (if there are
any).
> * Search for the `packages[\/\\]` and `plugins[\/\\]` patterns in the
source code (Babel and Eslint config files), and update them
appropriately.
> * Manually review
`.buildkite/scripts/pipelines/pull_request/pipeline.ts` to ensure that
any CI pipeline customizations continue to be correctly applied after
the changed path names
> * Review all of the updated files, specially the `.ts` and `.js` files
listed in the sections below, as some of them contain relative paths
that have been updated.
> * Think of potential impact of the move, including tooling and
configuration files that can be pointing to the relocated modules. E.g.:
>     * customised eslint rules
>     * docs pointing to source code

> [!NOTE]
> * This PR has been auto-generated.
> * Any manual contributions will be lost if the 'relocate' script is
re-run.
> * Try to obtain the missing reviews / approvals before applying manual
fixes, and/or keep your changes in a .patch / git stash.
> * Please use
[#sustainable_kibana_architecture](https://elastic.slack.com/archives/C07TCKTA22E)
Slack channel for feedback.

Are you trying to rebase this PR to solve merge conflicts? Please follow
the steps describe
[here](https://elastic.slack.com/archives/C07TCKTA22E/p1734019532879269?thread_ts=1734019339.935419&cid=C07TCKTA22E).

#### 12 plugin(s) are going to be relocated:

| Id | Target folder |
| -- | ------------- |
| `@kbn/data-view-editor-plugin` |
`src/platform/plugins/shared/data_view_editor` |
| `@kbn/data-view-field-editor-plugin` |
`src/platform/plugins/shared/data_view_field_editor` |
| `@kbn/data-view-management-plugin` |
`src/platform/plugins/shared/data_view_management` |
| `@kbn/data-views-plugin` | `src/platform/plugins/shared/data_views` |
| `@kbn/discover-enhanced-plugin` |
`x-pack/platform/plugins/private/discover_enhanced` |
| `@kbn/discover-plugin` | `src/platform/plugins/shared/discover` |
| `@kbn/discover-shared-plugin` |
`src/platform/plugins/shared/discover_shared` |
| `@kbn/field-formats-plugin` |
`src/platform/plugins/shared/field_formats` |
| `@kbn/saved-objects-finder-plugin` |
`src/platform/plugins/shared/saved_objects_finder` |
| `@kbn/saved-search-plugin` |
`src/platform/plugins/shared/saved_search` |
| `@kbn/unified-doc-viewer-plugin` |
`src/platform/plugins/shared/unified_doc_viewer` |
| `@kbn/unified-histogram-plugin` |
`src/platform/plugins/shared/unified_histogram` |




#### 18 packages(s) are going to be relocated:

| Id | Target folder |
| -- | ------------- |
| `@kbn/content-management-utils` |
`src/platform/packages/shared/kbn-content-management-utils` |
| `@kbn/data-view-utils` |
`src/platform/packages/shared/kbn-data-view-utils` |
| `@kbn/datemath` | `src/platform/packages/shared/kbn-datemath` |
| `@kbn/deeplinks-analytics` |
`src/platform/packages/shared/deeplinks/analytics` |
| `@kbn/default-nav-analytics` |
`src/platform/packages/private/default-nav/analytics` |
| `@kbn/discover-utils` |
`src/platform/packages/shared/kbn-discover-utils` |
| `@kbn/es-query` | `src/platform/packages/shared/kbn-es-query` |
| `@kbn/field-types` | `src/platform/packages/shared/kbn-field-types` |
| `@kbn/field-utils` | `src/platform/packages/shared/kbn-field-utils` |
| `@kbn/react-field` | `src/platform/packages/shared/kbn-react-field` |
| `@kbn/resizable-layout` |
`src/platform/packages/shared/kbn-resizable-layout` |
| `@kbn/search-errors` |
`src/platform/packages/shared/kbn-search-errors` |
| `@kbn/search-response-warnings` |
`src/platform/packages/shared/kbn-search-response-warnings` |
| `@kbn/search-types` | `src/platform/packages/shared/kbn-search-types`
|
| `@kbn/unified-data-table` |
`src/platform/packages/shared/kbn-unified-data-table` |
| `@kbn/unified-doc-viewer` |
`src/platform/packages/shared/kbn-unified-doc-viewer` |
| `@kbn/unified-field-list` |
`src/platform/packages/shared/kbn-unified-field-list` |
| `@kbn/unsaved-changes-badge` |
`src/platform/packages/private/kbn-unsaved-changes-badge` |


<details >
<summary>Updated relative paths</summary>

```
src/platform/packages/private/default-nav/analytics/jest.config.js:12
src/platform/packages/private/default-nav/analytics/tsconfig.json:2
src/platform/packages/private/default-nav/analytics/tsconfig.type_check.json:2
src/platform/packages/private/default-nav/analytics/tsconfig.type_check.json:22
src/platform/packages/private/default-nav/analytics/tsconfig.type_check.json:25
src/platform/packages/private/default-nav/analytics/tsconfig.type_check.json:28
src/platform/packages/private/kbn-unsaved-changes-badge/jest.config.js:12
src/platform/packages/private/kbn-unsaved-changes-badge/tsconfig.json:2
src/platform/packages/private/kbn-unsaved-changes-badge/tsconfig.type_check.json:2
src/platform/packages/private/kbn-unsaved-changes-badge/tsconfig.type_check.json:21
src/platform/packages/shared/deeplinks/analytics/jest.config.js:12
src/platform/packages/shared/deeplinks/analytics/tsconfig.json:2
src/platform/packages/shared/deeplinks/analytics/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-content-management-utils/jest.config.js:12
src/platform/packages/shared/kbn-content-management-utils/tsconfig.json:2
src/platform/packages/shared/kbn-content-management-utils/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-content-management-utils/tsconfig.type_check.json:22
src/platform/packages/shared/kbn-content-management-utils/tsconfig.type_check.json:43
src/platform/packages/shared/kbn-data-view-utils/jest.config.js:12
src/platform/packages/shared/kbn-data-view-utils/tsconfig.json:2
src/platform/packages/shared/kbn-data-view-utils/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-data-view-utils/tsconfig.type_check.json:22
src/platform/packages/shared/kbn-data-view-utils/tsconfig.type_check.json:25
src/platform/packages/shared/kbn-datemath/jest.config.js:22
src/platform/packages/shared/kbn-datemath/tsconfig.json:2
src/platform/packages/shared/kbn-datemath/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-discover-utils/jest.config.js:12
src/platform/packages/shared/kbn-discover-utils/tsconfig.json:2
src/platform/packages/shared/kbn-discover-utils/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-discover-utils/tsconfig.type_check.json:26
src/platform/packages/shared/kbn-discover-utils/tsconfig.type_check.json:35
src/platform/packages/shared/kbn-discover-utils/tsconfig.type_check.json:44
src/platform/packages/shared/kbn-discover-utils/tsconfig.type_check.json:47
src/platform/packages/shared/kbn-discover-utils/tsconfig.type_check.json:53
src/platform/packages/shared/kbn-es-query/jest.config.js:12
src/platform/packages/shared/kbn-es-query/tsconfig.json:2
src/platform/packages/shared/kbn-es-query/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-field-types/jest.config.js:12
src/platform/packages/shared/kbn-field-types/tsconfig.json:2
src/platform/packages/shared/kbn-field-types/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-field-utils/jest.config.js:12
src/platform/packages/shared/kbn-field-utils/tsconfig.json:2
src/platform/packages/shared/kbn-field-utils/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-field-utils/tsconfig.type_check.json:21
src/platform/packages/shared/kbn-field-utils/tsconfig.type_check.json:30
src/platform/packages/shared/kbn-field-utils/tsconfig.type_check.json:36
src/platform/packages/shared/kbn-react-field/jest.config.js:12
src/platform/packages/shared/kbn-react-field/tsconfig.json:2
src/platform/packages/shared/kbn-react-field/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-resizable-layout/jest.config.js:12
src/platform/packages/shared/kbn-resizable-layout/tsconfig.json:2
src/platform/packages/shared/kbn-resizable-layout/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-search-errors/jest.config.js:12
src/platform/packages/shared/kbn-search-errors/tsconfig.json:2
src/platform/packages/shared/kbn-search-errors/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-search-errors/tsconfig.type_check.json:25
src/platform/packages/shared/kbn-search-errors/tsconfig.type_check.json:28
src/platform/packages/shared/kbn-search-errors/tsconfig.type_check.json:31
src/platform/packages/shared/kbn-search-response-warnings/jest.config.js:12
src/platform/packages/shared/kbn-search-response-warnings/tsconfig.json:2
src/platform/packages/shared/kbn-search-response-warnings/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-search-response-warnings/tsconfig.type_check.json:21
src/platform/packages/shared/kbn-search-response-warnings/tsconfig.type_check.json:24
src/platform/packages/shared/kbn-search-types/jest.config.js:12
src/platform/packages/shared/kbn-search-types/tsconfig.json:2
src/platform/packages/shared/kbn-search-types/tsconfig.type_check.json:18
src/platform/packages/shared/kbn-search-types/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-search-types/tsconfig.type_check.json:21
src/platform/packages/shared/kbn-unified-data-table/jest.config.js:12
src/platform/packages/shared/kbn-unified-data-table/tsconfig.json:2
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:22
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:31
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:34
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:49
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:52
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:58
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:61
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:67
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:70
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:73
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:76
src/platform/packages/shared/kbn-unified-data-table/tsconfig.type_check.json:79
src/platform/packages/shared/kbn-unified-doc-viewer/jest.config.js:12
src/platform/packages/shared/kbn-unified-doc-viewer/tsconfig.json:2
src/platform/packages/shared/kbn-unified-doc-viewer/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-unified-doc-viewer/tsconfig.type_check.json:25
src/platform/packages/shared/kbn-unified-doc-viewer/tsconfig.type_check.json:31
src/platform/packages/shared/kbn-unified-field-list/jest.config.js:12
src/platform/packages/shared/kbn-unified-field-list/tsconfig.json:2
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:102
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:108
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:2
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:21
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:24
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:39
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:42
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:48
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:51
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:54
src/platform/packages/shared/kbn-unified-field-list/tsconfig.type_check.json:75
src/platform/plugins/shared/data_view_editor/jest.config.js:12
src/platform/plugins/shared/data_view_editor/tsconfig.json:2
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:16
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:2
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:28
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:31
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:37
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:40
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:43
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:49
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:52
src/platform/plugins/shared/data_view_editor/tsconfig.type_check.json:55
src/platform/plugins/shared/data_view_field_editor/jest.config.js:12
src/platform/plugins/shared/data_view_field_editor/tsconfig.json:2
src/platform/plugins/shared/data_view_field_editor/tsconfig.json:7
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:2
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:20
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:32
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:38
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:41
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:47
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:50
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:53
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:56
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:59
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:62
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:65
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:68
src/platform/plugins/shared/data_view_field_editor/tsconfig.type_check.json:9
src/platform/plugins/shared/data_view_management/jest.config.js:12
src/platform/plugins/shared/data_view_management/tsconfig.json:2
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:104
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:107
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:110
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:113
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:116
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:119
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:122
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:125
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:131
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:17
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:2
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:23
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:47
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:50
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:59
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:62
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:65
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:68
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:71
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:74
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:77
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:80
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:83
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:86
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:89
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:92
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:95
src/platform/plugins/shared/data_view_management/tsconfig.type_check.json:98
src/platform/plugins/shared/data_views/jest.config.js:12
src/platform/plugins/shared/data_views/tsconfig.json:2
src/platform/plugins/shared/data_views/tsconfig.type_check.json:2
src/platform/plugins/shared/data_views/tsconfig.type_check.json:22
src/platform/plugins/shared/data_views/tsconfig.type_check.json:37
src/platform/plugins/shared/data_views/tsconfig.type_check.json:40
src/platform/plugins/shared/data_views/tsconfig.type_check.json:43
src/platform/plugins/shared/data_views/tsconfig.type_check.json:46
src/platform/plugins/shared/data_views/tsconfig.type_check.json:49
src/platform/plugins/shared/data_views/tsconfig.type_check.json:52
src/platform/plugins/shared/data_views/tsconfig.type_check.json:55
src/platform/plugins/shared/data_views/tsconfig.type_check.json:58
src/platform/plugins/shared/data_views/tsconfig.type_check.json:61
src/platform/plugins/shared/data_views/tsconfig.type_check.json:64
src/platform/plugins/shared/data_views/tsconfig.type_check.json:70
src/platform/plugins/shared/data_views/tsconfig.type_check.json:73
src/platform/plugins/shared/data_views/tsconfig.type_check.json:76
src/platform/plugins/shared/data_views/tsconfig.type_check.json:79
src/platform/plugins/shared/data_views/tsconfig.type_check.json:82
src/platform/plugins/shared/data_views/tsconfig.type_check.json:85
src/platform/plugins/shared/data_views/tsconfig.type_check.json:88
src/platform/plugins/shared/data_views/tsconfig.type_check.json:91
src/platform/plugins/shared/data_views/tsconfig.type_check.json:94
src/platform/plugins/shared/data_views/tsconfig.type_check.json:97
src/platform/plugins/shared/discover/jest.config.js:12
src/platform/plugins/shared/discover/public/application/context/context_app.scss:1
src/platform/plugins/shared/discover/public/application/main/components/layout/discover_layout.scss:1
src/platform/plugins/shared/discover/public/context_awareness/README.md:118
src/platform/plugins/shared/discover/public/context_awareness/README.md:119
src/platform/plugins/shared/discover/tsconfig.json:10
src/platform/plugins/shared/discover/tsconfig.json:2
src/platform/plugins/shared/discover/tsconfig.type_check.json:104
src/platform/plugins/shared/discover/tsconfig.type_check.json:107
src/platform/plugins/shared/discover/tsconfig.type_check.json:110
src/platform/plugins/shared/discover/tsconfig.type_check.json:113
src/platform/plugins/shared/discover/tsconfig.type_check.json:116
src/platform/plugins/shared/discover/tsconfig.type_check.json:119
src/platform/plugins/shared/discover/tsconfig.type_check.json:12
src/platform/plugins/shared/discover/tsconfig.type_check.json:122
src/platform/plugins/shared/discover/tsconfig.type_check.json:125
src/platform/plugins/shared/discover/tsconfig.type_check.json:128
src/platform/plugins/shared/discover/tsconfig.type_check.json:131
src/platform/plugins/shared/discover/tsconfig.type_check.json:134
src/platform/plugins/shared/discover/tsconfig.type_check.json:137
src/platform/plugins/shared/discover/tsconfig.type_check.json:140
src/platform/plugins/shared/discover/tsconfig.type_check.json:143
src/platform/plugins/shared/discover/tsconfig.type_check.json:146
src/platform/plugins/shared/discover/tsconfig.type_check.json:149
src/platform/plugins/shared/discover/tsconfig.type_check.json:152
src/platform/plugins/shared/discover/tsconfig.type_check.json:155
src/platform/plugins/shared/discover/tsconfig.type_check.json:158
src/platform/plugins/shared/discover/tsconfig.type_check.json:161
src/platform/plugins/shared/discover/tsconfig.type_check.json:164
src/platform/plugins/shared/discover/tsconfig.type_check.json:167
src/platform/plugins/shared/discover/tsconfig.type_check.json:170
src/platform/plugins/shared/discover/tsconfig.type_check.json:173
src/platform/plugins/shared/discover/tsconfig.type_check.json:179
src/platform/plugins/shared/discover/tsconfig.type_check.json:185
src/platform/plugins/shared/discover/tsconfig.type_check.json:188
src/platform/plugins/shared/discover/tsconfig.type_check.json:191
src/platform/plugins/shared/discover/tsconfig.type_check.json:197
src/platform/plugins/shared/discover/tsconfig.type_check.json:2
src/platform/plugins/shared/discover/tsconfig.type_check.json:20
src/platform/plugins/shared/discover/tsconfig.type_check.json:200
src/platform/plugins/shared/discover/tsconfig.type_check.json:203
src/platform/plugins/shared/discover/tsconfig.type_check.json:206
src/platform/plugins/shared/discover/tsconfig.type_check.json:209
src/platform/plugins/shared/discover/tsconfig.type_check.json:212
src/platform/plugins/shared/discover/tsconfig.type_check.json:215
src/platform/plugins/shared/discover/tsconfig.type_check.json:218
src/platform/plugins/shared/discover/tsconfig.type_check.json:221
src/platform/plugins/shared/discover/tsconfig.type_check.json:224
src/platform/plugins/shared/discover/tsconfig.type_check.json:227
src/platform/plugins/shared/discover/tsconfig.type_check.json:230
src/platform/plugins/shared/discover/tsconfig.type_check.json:233
src/platform/plugins/shared/discover/tsconfig.type_check.json:236
src/platform/plugins/shared/discover/tsconfig.type_check.json:239
src/platform/plugins/shared/discover/tsconfig.type_check.json:242
src/platform/plugins/shared/discover/tsconfig.type_check.json:245
src/platform/plugins/shared/discover/tsconfig.type_check.json:248
src/platform/plugins/shared/discover/tsconfig.type_check.json:251
src/platform/plugins/shared/discover/tsconfig.type_check.json:254
src/platform/plugins/shared/discover/tsconfig.type_check.json:257
src/platform/plugins/shared/discover/tsconfig.type_check.json:260
src/platform/plugins/shared/discover/tsconfig.type_check.json:263
src/platform/plugins/shared/discover/tsconfig.type_check.json:266
src/platform/plugins/shared/discover/tsconfig.type_check.json:269
src/platform/plugins/shared/discover/tsconfig.type_check.json:272
src/platform/plugins/shared/discover/tsconfig.type_check.json:275
src/platform/plugins/shared/discover/tsconfig.type_check.json:278
src/platform/plugins/shared/discover/tsconfig.type_check.json:281
src/platform/plugins/shared/discover/tsconfig.type_check.json:35
src/platform/plugins/shared/discover/tsconfig.type_check.json:38
src/platform/plugins/shared/discover/tsconfig.type_check.json:83
src/platform/plugins/shared/discover/tsconfig.type_check.json:89
src/platform/plugins/shared/discover/tsconfig.type_check.json:98
src/platform/plugins/shared/discover_shared/jest.config.js:12
src/platform/plugins/shared/discover_shared/tsconfig.json:10
src/platform/plugins/shared/discover_shared/tsconfig.json:2
src/platform/plugins/shared/discover_shared/tsconfig.type_check.json:12
src/platform/plugins/shared/discover_shared/tsconfig.type_check.json:19
src/platform/plugins/shared/discover_shared/tsconfig.type_check.json:2
src/platform/plugins/shared/discover_shared/tsconfig.type_check.json:22
src/platform/plugins/shared/discover_shared/tsconfig.type_check.json:25
src/platform/plugins/shared/field_formats/jest.config.js:12
src/platform/plugins/shared/field_formats/tsconfig.json:2
src/platform/plugins/shared/field_formats/tsconfig.type_check.json:2
src/platform/plugins/shared/field_formats/tsconfig.type_check.json:21
src/platform/plugins/shared/field_formats/tsconfig.type_check.json:24
src/platform/plugins/shared/field_formats/tsconfig.type_check.json:27
src/platform/plugins/shared/field_formats/tsconfig.type_check.json:30
src/platform/plugins/shared/field_formats/tsconfig.type_check.json:33
src/platform/plugins/shared/saved_objects_finder/jest.config.js:12
src/platform/plugins/shared/saved_objects_finder/tsconfig.json:2
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:18
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:2
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:24
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:30
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:33
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:36
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:42
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:45
src/platform/plugins/shared/saved_objects_finder/tsconfig.type_check.json:48
src/platform/plugins/shared/saved_search/jest.config.js:12
src/platform/plugins/shared/saved_search/tsconfig.json:2
src/platform/plugins/shared/saved_search/tsconfig.json:6
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:12
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:19
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:2
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:28
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:34
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:37
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:40
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:43
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:46
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:49
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:55
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:58
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:64
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:70
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:73
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:76
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:79
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:82
src/platform/plugins/shared/saved_search/tsconfig.type_check.json:85
src/platform/plugins/shared/unified_doc_viewer/jest.config.js:12
src/platform/plugins/shared/unified_doc_viewer/tsconfig.json:2
src/platform/plugins/shared/unified_doc_viewer/tsconfig.json:6
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:103
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:106
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:109
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:112
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:2
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:22
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:28
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:31
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:34
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:37
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:40
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:49
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:55
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:58
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:61
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:64
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:67
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:70
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:73
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:76
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:79
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:82
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:85
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:9
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:91
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:94
src/platform/plugins/shared/unified_doc_viewer/tsconfig.type_check.json:97
src/platform/plugins/shared/unified_histogram/jest.config.js:12
src/platform/plugins/shared/unified_histogram/tsconfig.json:2
src/platform/plugins/shared/unified_histogram/tsconfig.json:6
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:100
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:103
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:106
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:19
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:2
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:28
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:34
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:40
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:43
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:46
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:49
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:52
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:55
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:58
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:61
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:73
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:76
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:79
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:82
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:85
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:88
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:9
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:91
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:94
src/platform/plugins/shared/unified_histogram/tsconfig.type_check.json:97
x-pack/platform/plugins/private/discover_enhanced/jest.config.js:10
x-pack/platform/plugins/private/discover_enhanced/tsconfig.json:2
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:2
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:20
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:23
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:26
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:29
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:32
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:38
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:41
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:44
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:47
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:50
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:53
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:56
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:59
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:62
x-pack/platform/plugins/private/discover_enhanced/tsconfig.type_check.json:65
```

</details>
2024-12-30 13:03:12 -06:00

88 lines
No EOL
3.8 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[[development-unit-tests]]
== Unit testing frameworks
{kib} is doing unit testing doing `Jest`.
[discrete]
== Jest
Jest tests are stored in the same directory as source code files with the `.test.{js,mjs,ts,tsx}` suffix.
Each plugin and package contains it's own `jest.config.js` file to define its root, and any overrides
to the jest-preset provided by `@kbn/test`. When working on a single plugin or package, you will find
it's more efficient to supply the Jest configuration file when running.
["source","shell"]
-----------
yarn jest --config src/platform/plugins/shared/discover/jest.config.js
-----------
[discrete]
==== Writing Jest Unit Tests
In order to write those tests there are two main things you need to be aware of.
The first one is the different between `jest.mock` and `jest.doMock`
and the second one our `jest mocks file pattern`. As we are running `js` and `ts`
test files with `babel-jest` both techniques are needed
specially for the tests implemented on Typescript in order to benefit from the
auto-inference types feature.
[discrete]
==== Jest.mock vs Jest.doMock
Both methods are essentially the same on their roots however the `jest.mock`
calls will get hoisted to the top of the file and can only reference variables
prefixed with `mock`. On the other hand, `jest.doMock` won't be hoisted and can
reference pretty much any variable we want, however we have to assure those referenced
variables are instantiated at the time we need them which lead us to the next
section where we'll talk about our jest mock files pattern.
[discrete]
==== Jest Mock Files Pattern
Specially on typescript it is pretty common to have in unit tests
`jest.doMock` calls which reference for example imported types. Any error
will thrown from doing that however the test will fail. The reason behind that
is because despite the `jest.doMock` isn't being hoisted by `babel-jest` the
import with the types we are referencing will be hoisted to the top and at the
time we'll call the function that variable would not be defined.
In order to prevent that we develop a protocol that should be followed:
- Each module could provide a standard mock in `mymodule.mock.ts` in case
there are other tests that could benefit from using definitions here.
This file would not have any `jest.mock` calls, just dummy objects.
- Each test defines its mocks in `mymodule.test.mocks.ts`. This file
could import relevant mocks from the generalised module's mocks
file `(*.mock.ts)` and call `jest.mock` for each of them. If there is
any relevant dummy mock objects to generalise (and to be used by
other tests), the dummy objects could be defined directly on this file.
- Each test would import its mocks from the test mocks
file mymodule.test.mocks.ts. `mymodule.test.ts` has an import
like: `import * as Mocks from './mymodule.test.mocks'`,
`import { mockX } from './mymodule.test.mocks'`
or just `import './mymodule.test.mocks'` if there isn't anything
exported to be used.
[discrete]
[[debugging-unit-tests]]
=== Debugging Unit Tests
The standard `yarn test` task runs several sub tasks and can take
several minutes to complete, making debugging failures pretty painful.
In order to ease the pain specialized tasks provide alternate methods
for running the tests.
You could also add the `--debug` option so that `node` is run using
the `--inspect-brk` flag. Youll need to connect a remote debugger such
as https://github.com/node-inspector/node-inspector[`node-inspector`]
to proceed in this mode.
[discrete]
=== Unit Testing Plugins
Even when using
https://github.com/elastic/kibana/tree/main/packages/kbn-plugin-generator[Kibana
plugin generator] we do not enforce a way for unit testing your plugin. Please setup and you use
the tools of your choice. If the plugin will live inside the Kibana repo `Jest` must be used.