From 5b82af6319c2e88cb6431c4472ad761a264f1ecd Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Thu, 8 Apr 2021 11:02:56 -0400 Subject: [PATCH] Allow jest script to run on individual files This allows the jest test script for the enterprise_search plugin to run on files, and well as directories. Previously, a trailing slash was always appended, whether it was a file name, or a directory. It now maintains whatever a user originally inputted. --- x-pack/plugins/enterprise_search/jest.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/enterprise_search/jest.sh b/x-pack/plugins/enterprise_search/jest.sh index d7aa0b07fb89..65838b90ae16 100644 --- a/x-pack/plugins/enterprise_search/jest.sh +++ b/x-pack/plugins/enterprise_search/jest.sh @@ -1,11 +1,19 @@ #! /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='/x-pack/plugins/enterprise_search/${FOLDER}/**/*.{ts,tsx}'" + # If this is a file + if [[ "$FOLDER" == *".ts"* ]]; then + PATH_WITHOUT_EXTENSION=${1%%.*} + FOLDER="${FOLDER} --collectCoverageFrom='/x-pack/plugins/enterprise_search/${PATH_WITHOUT_EXTENSION}.{ts,tsx}'" + # If this is a folder + else + FOLDER=${FOLDER%/} # Strip any trailing slash + FOLDER="${FOLDER}/ --collectCoverageFrom='/x-pack/plugins/enterprise_search/${FOLDER}/**/*.{ts,tsx}'" + fi else FOLDER='' fi