Created
November 29, 2023 01:39
-
-
Save M1nhNV/1a8b3b1944c0da965e6783aca32c458e to your computer and use it in GitHub Desktop.
Find all test case, open terminal and run script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTotalScriptRunning { | |
processName="chromedriver" | |
processIds=$(pgrep "$processName") | |
count=$(echo "$processIds" | wc -w) | |
echo "$count" | |
} | |
function closeAllTerminal { | |
echo "Closed all terminal" | |
pgrep "Terminal" | xargs kill -15 | |
} | |
function runAllScript { | |
SOURCE_PATH="~/code/source_test" | |
TEST_CASE_PATH="./src/resources/test-cases" | |
# Default webdriver running concurrent | |
CONCURRENT_DRIVER_RUNNING_LIMIT=5 | |
if [ -f .env ]; then | |
source .env | |
if [ -n "$APP_PATH" ]; then | |
SOURCE_PATH=$APP_PATH | |
fi | |
if [ -n "$CONCURRENT_DRIVER_RUNNING_LIMIT" ]; then | |
CONCURRENT_DRIVER_RUNNING_LIMIT=$CONCURRENT_DRIVER_RUNNING_LIMIT | |
fi | |
fi | |
filesList=$(find "$TEST_CASE_PATH" -type f -name "*.spec.js") | |
# read file and find describe in file | |
results=() | |
for file in $filesList; do | |
describe_content=$(awk "/describe\(/,/\)/" "$file") | |
if [ -n "$describe_content" ]; then | |
results+=("$describe_content") | |
fi | |
done | |
index=0 | |
totalTestCase=${#results[@]} | |
echo "=== start ===" | |
echo "Total test case: ${totalTestCase}" | |
echo "Limit concurrent webdriver: ${CONCURRENT_DRIVER_RUNNING_LIMIT}" | |
while [ "$totalTestCase" -gt 0 ]; do | |
# total of process is running | |
total=$(getTotalScriptRunning) | |
if [[ $total -lt CONCURRENT_DRIVER_RUNNING_LIMIT ]]; then | |
echo "--------------------------------------------" | |
pattern="[\'\"](.*)[\'\"]" | |
currentResult="${results[$index]}" | |
((index++)) | |
if [[ "$currentResult" =~ $pattern ]]; then | |
runScript "${BASH_REMATCH[1]}" | |
# wait for app open | |
sleep 3 | |
echo "=> Run test case number - ${index}: ${BASH_REMATCH[1]}" | |
fi | |
((totalTestCase--)) | |
fi | |
done | |
echo "=== end ===" | |
closeAllTerminal | |
} | |
function runScript { | |
osascript -e "tell application \"Terminal\" to do script \"cd $SOURCE_PATH && yarn test --g $1; exit \"" | |
} | |
runAllScript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment