[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:
parent
885c868717
commit
694bbd42dd
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
],
|
||||
};
|
||||
|
|
18
x-pack/plugins/enterprise_search/jest.sh
Normal file
18
x-pack/plugins/enterprise_search/jest.sh
Normal 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
|
Loading…
Reference in a new issue