-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
docs: Add test file location -> test runner table #34986
Changes from 5 commits
3b9ad4c
0b17e3e
5cdcdf4
4b6074c
bf89d8d
82c54af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,19 +327,35 @@ macOS users on a machine with a discrete graphics card may see significant speed | |
`yarn debug` will start the server with Node's inspect flag. Kibana's development mode will start three processes on ports `9229`, `9230`, and `9231`. Chrome's developer tools need to be configured to connect to all three connections. Add `localhost:<port>` for each Kibana process in Chrome's developer tools connection tab. | ||
|
||
### Unit testing frameworks | ||
Kibana is migrating unit testing from Mocha to Jest. Legacy unit tests still exist in Mocha but all new unit tests should be written in Jest. | ||
|
||
#### Mocha (legacy) | ||
Mocha tests are contained in `__tests__` directories. | ||
|
||
#### Jest | ||
Jest tests are stored in the same directory as source code files with the `.test.js` suffix. | ||
|
||
### Running Jest Unit Tests | ||
|
||
```bash | ||
node scripts/jest | ||
``` | ||
Kibana is migrating unit testing from Mocha to Jest. Legacy unit tests still | ||
exist in Mocha but all new unit tests should be written in Jest. Mocha tests | ||
are contained in `__tests__` directories. Whereas Jest tests are stored in | ||
the same directory as source code files with the `.test.js` suffix. | ||
|
||
### Running specific Kibana tests | ||
|
||
The following table outlines possible test file locations and how to invoke them: | ||
|
||
| Test runner | Test location | Runner command (working directory is kibana root) | | ||
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | | ||
| Jest | `src/**/*.test.js`<br>`src/**/*.test.ts` | `yarn test:jest -t regexp [test path]` | | ||
| Jest (integration) | `**/integration_tests/**/*.test.js` | `node scripts/jest_integration -t regexp [test path]` | | ||
| Mocha | `src/**/__tests__/**/*.js`<br>`packages/kbn-datemath/test/**/*.js`<br>`packages/kbn-dev-utils/src/**/__tests__/**/*.js`<br>`tasks/**/__tests__/**/*.js` | `node scripts/mocha --grep=regexp [test path]` | | ||
| Functional | `test/*integration/**/config.js`<br>`test/*functional/**/config.js` | `node scripts/functional_tests --config test/[directory]/config.js --grep=regexp` | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this will run the tests, I am concerned folks will use this for debugging which takes a large amount of time to start Kibana/ES each time. We have details here regarding how to run for development: https://www.elastic.co/guide/en/kibana/current/development-functional-tests.html#_running_functional_tests I would suggest we update this command to outline the two:
|
||
|
||
For X-Pack tests located in `x-pack/` see [X-Pack Testing](x-pack/README.md#testing) | ||
|
||
Test runner arguments: | ||
- Where applicable, the optional arguments `-t=regexp` or `--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. | ||
|
||
Examples: | ||
- Run the entire elasticsearch_service test suite with yarn: | ||
`yarn test:jest src/core/server/elasticsearch/elasticsearch_service.test.ts` | ||
- Run the jest test case whose description matches 'stops both admin and data clients': | ||
`yarn test:jest -t 'stops both admin and data clients' src/core/server/elasticsearch/elasticsearch_service.test.ts` | ||
- Run the x-pack api integration test case whose description matches the given string: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove this X-Pack example since you included in the X-Pack docs |
||
`node scripts/functional_tests --config x-pack/test/api_integration/config.js --grep='apis Monitoring Beats list with restarted beat instance should load multiple clusters'` | ||
|
||
### Debugging Unit Tests | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,21 @@ Elasticsearch will run with a basic license. To run with a trial license, includ | |
Example: `yarn es snapshot --license trial --password changeme` | ||
|
||
# Testing | ||
## Running specific tests | ||
| Test runner | Test location | Runner command (working directory is kibana/x-pack) | | ||
| ------------ | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | | ||
| Jest | `x-pack/**/*.test.js`<br>`x-pack/**/*.test.ts` | `cd x-pack && yarn test:jest -t regexp [test path]` | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same feedback as for Kibana - use |
||
| Functional | `x-pack/test/*integration/**/config.js`<br>`x-pack/test/*functional/config.js` | `node scripts/functional_tests --config test/[directory]/config.js --grep=regexp` | | ||
|
||
## Running unit tests_bundle | ||
Examples: | ||
- Run the jest test case whose description matches 'filtering should skip values of null': | ||
`cd x-pack && yarn test:jest -t 'filtering should skip values of null' plugins/ml/public/explorer/explorer_charts/explorer_charts_container_service.test.js` | ||
- Run the x-pack api integration test case whose description matches the given string: | ||
`node scripts/functional_tests --config x-pack/test/api_integration/config.js --grep='apis Monitoring Beats list with restarted beat instance should load multiple clusters'` | ||
|
||
In addition to to providing a regular expression argument, specific tests can also be run by appeding `.only` to an `it` or `describe` function block. E.g. `describe(` to `describe.only(`. | ||
|
||
## Running all tests | ||
|
||
You can run unit tests by running: | ||
|
||
|
@@ -28,15 +41,6 @@ If you want to run tests only for a specific plugin (to save some time), you can | |
yarn test --plugins <plugin>[,<plugin>]* # where <plugin> is "reporting", etc. | ||
``` | ||
|
||
#### Running single test file | ||
Edit test file, changing top level `describe` to `describe.only`. Run tests with normal commands. | ||
|
||
#### Running Jest Unit Tests | ||
```bash | ||
# from x-pack folder | ||
node scripts/jest | ||
``` | ||
|
||
#### Debugging browser tests | ||
``` | ||
yarn test:browser:dev | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update this to
node scripts/jest