Skip to content

Commit

Permalink
[Enterprise Search] Allow jest script to run on individual files (#96589
Browse files Browse the repository at this point in the history
) (#96852)

Co-authored-by: Jason Stoltzfus <[email protected]>
  • Loading branch information
kibanamachine and JasonStoltz authored Apr 12, 2021
1 parent 3129413 commit 3afc091
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion x-pack/plugins/enterprise_search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ yarn test:jest
yarn test:jest --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:
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 file or folder and only get coverage numbers for that file or 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
# When testing an individual file, remember to pass the path of the test file, not the source file.
sh jest.sh public/applications/shared/flash_messages/flash_messages_logic.test.ts
```

### E2E tests
Expand Down
20 changes: 14 additions & 6 deletions x-pack/plugins/enterprise_search/jest.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#! /bin/bash

# Whether to run Jest on the entire enterprise_search plugin or a specific component/folder
FOLDER="${1:-all}"
if [[ $FOLDER && $FOLDER != "all" ]]

TARGET="${1:-all}"
if [[ $TARGET && $TARGET != "all" ]]
then
FOLDER=${FOLDER%/} # Strip any trailing slash
FOLDER="${FOLDER}/ --collectCoverageFrom='<rootDir>/x-pack/plugins/enterprise_search/${FOLDER}/**/*.{ts,tsx}'"
# If this is a file
if [[ "$TARGET" == *".ts"* ]]; then
PATH_WITHOUT_EXTENSION=${1%%.*}
TARGET="${TARGET} --collectCoverageFrom='<rootDir>/x-pack/plugins/enterprise_search/${PATH_WITHOUT_EXTENSION}.{ts,tsx}'"
# If this is a folder
else
TARGET=${TARGET%/} # Strip any trailing slash
TARGET="${TARGET}/ --collectCoverageFrom='<rootDir>/x-pack/plugins/enterprise_search/${TARGET}/**/*.{ts,tsx}'"
fi
else
FOLDER=''
TARGET=''
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
yarn test:jest $TARGET $ARGS

0 comments on commit 3afc091

Please sign in to comment.