Skip to content
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

[Enterprise Search] Allow jest script to run on individual files #96589

Merged
merged 4 commits into from
Apr 12, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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