[Enterprise Search] Jest config & handy Jest script (#84839)

* Update Jest config to automatically report coverage

- No more super intricate yarn commands! Hooray

* Add handy shell script for running tests & coverage on specific folders/subdirectories
This commit is contained in:
Constance 2020-12-17 08:19:33 -08:00 committed by GitHub
parent 885c868717
commit 694bbd42dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View file

@ -31,8 +31,21 @@ To debug Kea state in-browser, Kea recommends [Redux Devtools](https://kea.js.or
Documentation: https://www.elastic.co/guide/en/kibana/current/development-tests.html#_unit_testing
Jest tests can be run directly from the `x-pack/plugins/enterprise_search` folder. This also works for any subfolders or subcomponents.
```bash
yarn test:jest
yarn test:jest --watch
```
yarn test:jest x-pack/plugins/enterprise_search --watch
Unfortunately coverage collection does not work as automatically, and requires using our handy jest.sh script if you want to run tests on a specific folder and only get coverage numbers for that folder:
```bash
# Running the jest.sh script from the `x-pack/plugins/enterprise_search` folder (vs. kibana root)
# will save you time and allow you to Tab to complete folder dir names
sh jest.sh {YOUR_COMPONENT_DIR}
sh jest.sh public/applications/shared/kibana
sh jest.sh server/routes/app_search
```
### E2E tests

View file

@ -8,4 +8,11 @@ module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/plugins/enterprise_search'],
collectCoverage: true,
coverageReporters: ['text'],
collectCoverageFrom: [
'<rootDir>/x-pack/plugins/enterprise_search/**/*.{ts,tsx}',
'!<rootDir>/x-pack/plugins/enterprise_search/public/*.ts',
'!<rootDir>/x-pack/plugins/enterprise_search/server/*.ts',
],
};

View file

@ -0,0 +1,18 @@
#! /bin/bash
# Whether to run Jest on the entire enterprise_search plugin or a specific component/folder
FOLDER="${1:-all}"
if [[ $FOLDER && $FOLDER != "all" ]]
then
FOLDER=${FOLDER%/} # Strip any trailing slash
FOLDER="${FOLDER}/ --collectCoverageFrom='<rootDir>/x-pack/plugins/enterprise_search/${FOLDER}/**/*.{ts,tsx}'"
else
FOLDER=''
fi
# Pass all remaining arguments (e.g., ...rest) from the 2nd arg onwards
# as an open-ended string. Appends onto to the end the Jest CLI command
# @see https://jestjs.io/docs/en/cli#options
ARGS="${*:2}"
yarn test:jest $FOLDER $ARGS