kibana/docs/developer/contributing/development-tests.asciidoc
Gerard Soldevila 6a7c904f92
SKA: Relocate "platform" packages that remain on /packages (#208704)
## Summary

The `/packages` folder at the root of the Kibana repository used to
contain a lot of packages.
In the context of SKA, they have been gradually moved to various
locations:
* `src/platform/packages`
* `x-pack/platform/packages`
* `src/core/packages`

Currently, only `devOnly: true` packages are left in this folder. This
comprises libraries for CLI scripts as well as testing utilities.

With this PR, we are moving ~half of these packages under
`src/platform/packages/(private|shared)/`.
In particular, we are moving those packages that are being used from
platform and/or solutions.

Since they are `"devOnly": true`, this means they are ONLY used from
tests, cypress tests, storybook configs, ./scripts/ folders inside some
modules, or other non-prod-time logic. Nonetheless, they are effectively
referenced from platform and/or solutions code, hence I decided they
should be placed under `platform` folders.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-02-24 11:03:30 +00:00

119 lines
No EOL
4.4 KiB
Text

[[development-tests]]
== Testing
[discrete]
=== Running specific {kib} tests
The following table outlines possible test file locations and how to
invoke them:
[width="100%",cols="7%,59%,34%",options="header",]
|===
|Test runner |Test location |Runner command (working directory is {kib}
root)
|Jest |`**/*.test.{js,mjs,ts,tsx}`
|`yarn test:jest [test path]`
|Jest (integration) |`**/integration_tests/**/*.test.{js,mjs,ts,tsx}`
|`yarn test:jest_integration [test path]`
|Functional
|`test/**/config.js` `x-pack/test/**/config.js`
|`node scripts/functional_tests_server --config [directory]/config.js` `node scripts/functional_test_runner --config [directory]/config.js --grep=regexp`
|===
Test runner arguments: - Where applicable, the optional arguments
`--grep=regexp` will only run tests or test suites
whose descriptions matches the regular expression. - `[test path]` is
the relative path to the test file.
=== Unit Testing
Kibana primarily uses Jest for unit testing. Each plugin or package defines a `jest.config.js` that extends link:{kib-repo}tree/{branch}/src/platform/packages/shared/kbn-test/jest-preset.js[a preset] provided by the link:{kib-repo}tree/{branch}/src/platform/packages/shared/kbn-test[`@kbn/test`] package. Unless you intend to run all unit tests within the project, it's most efficient to provide the Jest configuration file for the plugin or package you're testing.
[source,bash]
----
yarn jest --config src/platform/plugins/shared/dashboard/jest.config.js
----
A script is available to provide a better user experience when testing while navigating throughout the repository. To run the tests within your current working directory, use `yarn test:jest`. Like the Jest CLI, you can also supply a path to determine which tests to run.
[source,bash]
----
kibana/src/platform/plugins/shared/dashboard/server$ yarn test:jest #or
kibana/src/platform/plugins/shared/dashboard$ yarn test:jest server #or
kibana$ yarn test:jest src/platform/plugins/shared/dashboard/server
----
Any additional options supplied to `test:jest` will be passed onto the Jest CLI with the resulting Jest command always being outputted.
[source,bash]
----
kibana/src/platform/plugins/shared/dashboard/server$ yarn test:jest --coverage
# is equivalent to
yarn jest --coverage --verbose --config /home/tyler/elastic/kibana/src/platform/plugins/shared/dashboard/jest.config.js server
----
You can generate code coverage report for a single plugin.
[source,bash]
----
yarn jest --coverage --config src/platform/plugins/shared/console/jest.config.js
----
Html report is available in target/kibana-coverage/jest/path/to/plugin
[discrete]
=== Running browser automation tests
Check out <<development-functional-tests>> to learn more about how you can run
and develop functional tests for {kib} core and plugins.
You can also look into the {kib-repo}tree/{branch}/scripts/README.md[Scripts README.md]
to learn more about using the node scripts we provide for building
{kib}, running integration tests, and starting up {kib} and
{es} while you develop.
[discrete]
==== More testing information:
* <<development-functional-tests>>
* <<development-unit-tests>>
* <<development-accessibility-tests>>
* <<development-package-tests>>
include::development-functional-tests.asciidoc[leveloffset=+1]
include::development-unit-tests.asciidoc[leveloffset=+1]
include::development-accessibility-tests.asciidoc[leveloffset=+1]
include::development-package-tests.asciidoc[leveloffset=+1]
[discrete]
=== Cross-browser compatibility
**Testing IE on OS X**
**Note:** IE11 is not supported from 7.9 onwards.
* http://www.vmware.com/products/fusion/fusion-evaluation.html[Download
VMWare Fusion].
* https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/#downloads[Download
IE virtual machines] for VMWare.
* Open VMWare and go to Window > Virtual Machine Library. Unzip the
virtual machine and drag the .vmx file into your Virtual Machine
Library.
* Right-click on the virtual machine you just added to your library and
select "`Snapshots…`", and then click the "`Take`" button in the modal
that opens. You can roll back to this snapshot when the VM expires in 90
days.
* In System Preferences > Sharing, change your computer name to be
something simple, e.g. "`computer`".
* Run {kib} with `yarn start --host=computer.local` (substituting
your computer name).
* Now you can run your VM, open the browser, and navigate to
`http://computer.local:5601` to test {kib}.
* Alternatively you can use browserstack