From 3b9ad4c95b9c274a8bb64ecec817fb37f6fc9a02 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 12 Apr 2019 14:33:59 +0200 Subject: [PATCH 1/6] docs: Add test file location -> test runner table --- CONTRIBUTING.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0c69b3b7dc87ad..32aca44179fdb2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -335,11 +335,18 @@ 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 -``` +### Running Kibana tests + +The following table outlines possible test file locations and how to invoke them: + +| Test location | Runner command (working directory is kibana root) | +| ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | +| `src/**/*.test.js`
`src/**/*.test.ts` | `yarn test:jest -t=regexp [test path]` | +| `src/**/__tests__/**/*.js`
`packages/kbn-datemath/test/**/*.js`
`packages/kbn-dev-utils/src/**/__tests__/**/*.js`
`tasks/**/__tests__/**/*.js` | `yarn test:mocha --grep=regexp [test path]` | +| `**/integration_tests/**/*.test.js` | `node scripts/jest_integration -t=regexp [test path]` | +| `test/*integration/**/config.js`
`test/*functional/**/config.js`
`x-pack/test/*integration/**/config.js`
`x-pack/test/*functional/config.js` | `node scripts/functional_tests --config test/[directory]/config.js --grep=regexp` | +| `x-pack/**/*.test.js`
`x-pack/**/*.test.ts` | `cd x-pack && yarn test:jest -t=regexp [test path]` | +| `x-pack/test/*integration/**/config.ts` | ?? | ### Debugging Unit Tests From 0b17e3ebc6bc93aa05df796158510f3503329d4e Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 12 Apr 2019 16:03:58 +0200 Subject: [PATCH 2/6] Use scripts/mocha instead of if yarn test:mocha and clarify arguments --- CONTRIBUTING.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 32aca44179fdb2..3b89c876c2beb2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -341,13 +341,17 @@ The following table outlines possible test file locations and how to invoke them | Test location | Runner command (working directory is kibana root) | | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | -| `src/**/*.test.js`
`src/**/*.test.ts` | `yarn test:jest -t=regexp [test path]` | -| `src/**/__tests__/**/*.js`
`packages/kbn-datemath/test/**/*.js`
`packages/kbn-dev-utils/src/**/__tests__/**/*.js`
`tasks/**/__tests__/**/*.js` | `yarn test:mocha --grep=regexp [test path]` | -| `**/integration_tests/**/*.test.js` | `node scripts/jest_integration -t=regexp [test path]` | +| `src/**/*.test.js`
`src/**/*.test.ts` | `yarn test:jest -t regexp [test path]` | +| `src/**/__tests__/**/*.js`
`packages/kbn-datemath/test/**/*.js`
`packages/kbn-dev-utils/src/**/__tests__/**/*.js`
`tasks/**/__tests__/**/*.js` | `node scripts/mocha --grep=regexp [test path]` | +| `**/integration_tests/**/*.test.js` | `node scripts/jest_integration -t regexp [test path]` | | `test/*integration/**/config.js`
`test/*functional/**/config.js`
`x-pack/test/*integration/**/config.js`
`x-pack/test/*functional/config.js` | `node scripts/functional_tests --config test/[directory]/config.js --grep=regexp` | -| `x-pack/**/*.test.js`
`x-pack/**/*.test.ts` | `cd x-pack && yarn test:jest -t=regexp [test path]` | +| `x-pack/**/*.test.js`
`x-pack/**/*.test.ts` | `cd x-pack && yarn test:jest -t regexp [test path]` | | `x-pack/test/*integration/**/config.ts` | ?? | +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. + ### 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. From 5cdcdf448a0f64d3b1b1ad1cff7bee4784774af8 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 12 Apr 2019 16:42:55 +0200 Subject: [PATCH 3/6] docs: add some examples of running tests suites with grep patterns --- CONTRIBUTING.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3b89c876c2beb2..895d474a5a9afc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -352,6 +352,14 @@ 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: + `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 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. From 4b6074c1d63c913e342ec61e404ad011dc388adc Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 16 Apr 2019 15:13:47 +0200 Subject: [PATCH 4/6] Split out x-pack testing docs, add test runner column --- x-pack/README.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/x-pack/README.md b/x-pack/README.md index c8faf8a6a00052..45bb27e664e5cc 100644 --- a/x-pack/README.md +++ b/x-pack/README.md @@ -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`
`x-pack/**/*.test.ts` | `cd x-pack && yarn test:jest -t regexp [test path]` | +| Functional | `x-pack/test/*integration/**/config.js`
`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 [,]* # where 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 From bf89d8d3c4728bc20181dbe260cbd100ec78492f Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 16 Apr 2019 16:25:02 +0200 Subject: [PATCH 5/6] Split out x-pack testing docs, add test runner column #2 --- CONTRIBUTING.md | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 895d474a5a9afc..f1c2c80f4938c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -327,26 +327,23 @@ 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:` 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. +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. -#### 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 Kibana tests +### Running specific Kibana tests The following table outlines possible test file locations and how to invoke them: -| Test location | Runner command (working directory is kibana root) | -| ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | -| `src/**/*.test.js`
`src/**/*.test.ts` | `yarn test:jest -t regexp [test path]` | -| `src/**/__tests__/**/*.js`
`packages/kbn-datemath/test/**/*.js`
`packages/kbn-dev-utils/src/**/__tests__/**/*.js`
`tasks/**/__tests__/**/*.js` | `node scripts/mocha --grep=regexp [test path]` | -| `**/integration_tests/**/*.test.js` | `node scripts/jest_integration -t regexp [test path]` | -| `test/*integration/**/config.js`
`test/*functional/**/config.js`
`x-pack/test/*integration/**/config.js`
`x-pack/test/*functional/config.js` | `node scripts/functional_tests --config test/[directory]/config.js --grep=regexp` | -| `x-pack/**/*.test.js`
`x-pack/**/*.test.ts` | `cd x-pack && yarn test:jest -t regexp [test path]` | -| `x-pack/test/*integration/**/config.ts` | ?? | +| Test runner | Test location | Runner command (working directory is kibana root) | +| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | +| Jest | `src/**/*.test.js`
`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`
`packages/kbn-datemath/test/**/*.js`
`packages/kbn-dev-utils/src/**/__tests__/**/*.js`
`tasks/**/__tests__/**/*.js` | `node scripts/mocha --grep=regexp [test path]` | +| Functional | `test/*integration/**/config.js`
`test/*functional/**/config.js` | `node scripts/functional_tests --config test/[directory]/config.js --grep=regexp` | + +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. From 82c54afa8291cd1aabf21c26ac2779658b328f98 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 18 Apr 2019 22:15:36 +0200 Subject: [PATCH 6/6] Use node scripts for jest and split functional runner/server --- CONTRIBUTING.md | 13 +++++++------ x-pack/README.md | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f1c2c80f4938c1..ca9246619cea20 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -338,10 +338,10 @@ 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`
`src/**/*.test.ts` | `yarn test:jest -t regexp [test path]` | +| Jest | `src/**/*.test.js`
`src/**/*.test.ts` | `node scripts/jest -t regexp [test path]` | | Jest (integration) | `**/integration_tests/**/*.test.js` | `node scripts/jest_integration -t regexp [test path]` | | Mocha | `src/**/__tests__/**/*.js`
`packages/kbn-datemath/test/**/*.js`
`packages/kbn-dev-utils/src/**/__tests__/**/*.js`
`tasks/**/__tests__/**/*.js` | `node scripts/mocha --grep=regexp [test path]` | -| Functional | `test/*integration/**/config.js`
`test/*functional/**/config.js` | `node scripts/functional_tests --config test/[directory]/config.js --grep=regexp` | +| Functional | `test/*integration/**/config.js`
`test/*functional/**/config.js` | `node scripts/functional_tests_server --config test/[directory]/config.js`
`node scripts/functional_test_runner --config test/[directory]/config.js --grep=regexp` | For X-Pack tests located in `x-pack/` see [X-Pack Testing](x-pack/README.md#testing) @@ -351,11 +351,12 @@ Test runner arguments: Examples: - Run the entire elasticsearch_service test suite with yarn: - `yarn test:jest src/core/server/elasticsearch/elasticsearch_service.test.ts` + `node scripts/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: - `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'` + `node scripts/jest -t 'stops both admin and data clients' src/core/server/elasticsearch/elasticsearch_service.test.ts` + - Run the api integration test case whose description matches the given string: + `node scripts/functional_tests_server --config test/api_integration/config.js` + `node scripts/functional_tests_runner --config test/api_integration/config.js --grep='should return 404 if id does not match any sample data sets'` ### Debugging Unit Tests diff --git a/x-pack/README.md b/x-pack/README.md index 45bb27e664e5cc..eb4e44e42d5a04 100644 --- a/x-pack/README.md +++ b/x-pack/README.md @@ -16,14 +16,15 @@ Example: `yarn es snapshot --license trial --password changeme` ## Running specific tests | Test runner | Test location | Runner command (working directory is kibana/x-pack) | | ------------ | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | -| Jest | `x-pack/**/*.test.js`
`x-pack/**/*.test.ts` | `cd x-pack && yarn test:jest -t regexp [test path]` | -| Functional | `x-pack/test/*integration/**/config.js`
`x-pack/test/*functional/config.js` | `node scripts/functional_tests --config test/[directory]/config.js --grep=regexp` | +| Jest | `x-pack/**/*.test.js`
`x-pack/**/*.test.ts` | `cd x-pack && node scripts/jest -t regexp [test path]` | +| Functional | `x-pack/test/*integration/**/config.js`
`x-pack/test/*functional/config.js` | `node scripts/functional_tests_server --config x-pack/test/[directory]/config.js`
`node scripts/functional_test_runner --config x-pack/test/[directory]/config.js --grep=regexp` | 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'` + `node scripts/functional_tests_server --config x-pack/test/api_integration/config.js` + `node scripts/functional_test_runner --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(`.