2021-09-09 14:41:36 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Run package scripts
|
|
|
|
#
|
|
|
|
|
|
|
|
# Script help
|
|
|
|
usage() {
|
|
|
|
echo 'usage: npx wc-api-tests <script>'
|
|
|
|
echo 'scripts:'
|
2021-09-09 18:23:23 +00:00
|
|
|
echo ' test <group> - run API tests with the specified group'
|
2021-09-09 14:41:36 +00:00
|
|
|
echo ' make:collection - build a Postman API Collection'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parameter check
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Store original path
|
|
|
|
OLDPATH=$(pwd)
|
|
|
|
|
|
|
|
# Return value for CI test runs
|
|
|
|
TESTRESULT=0
|
|
|
|
|
2022-03-30 02:57:11 +00:00
|
|
|
# Function to generate report
|
|
|
|
report() {
|
|
|
|
|
2022-05-16 09:59:40 +00:00
|
|
|
# Set the API_TEST_REPORT_DIR to $PWD if it wasn't set
|
|
|
|
ALLURE_RESULTS_DIR="${API_TEST_REPORT_DIR:-$PWD}/allure-results"
|
|
|
|
ALLURE_REPORT_DIR="${API_TEST_REPORT_DIR:-$PWD}/allure-report"
|
2022-03-30 02:57:11 +00:00
|
|
|
|
|
|
|
echo "Generating report..."
|
|
|
|
allure generate --clean "$ALLURE_RESULTS_DIR" --output "$ALLURE_REPORT_DIR"
|
|
|
|
REPORT_EXIT_CODE=$?
|
|
|
|
|
|
|
|
# Suggest opening the report
|
2022-04-01 02:24:09 +00:00
|
|
|
if [[ $REPORT_EXIT_CODE -eq 0 && $GITHUB_ACTIONS != "true" ]]; then
|
2022-03-30 02:57:11 +00:00
|
|
|
echo "To view the report on your browser, run:"
|
|
|
|
echo ""
|
2022-04-08 00:19:25 +00:00
|
|
|
echo "pnpm dlx allure open \"$ALLURE_REPORT_DIR\""
|
2022-03-30 02:57:11 +00:00
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-09-09 14:41:36 +00:00
|
|
|
# Use the script symlink to find and change directory to the root of the package
|
|
|
|
SCRIPTPATH=$(dirname "$0")
|
|
|
|
REALPATH=$(readlink "$0")
|
|
|
|
cd "$SCRIPTPATH/$(dirname "$REALPATH")/.."
|
|
|
|
|
|
|
|
# Run scripts
|
|
|
|
case $1 in
|
2022-03-30 02:57:11 +00:00
|
|
|
'test')
|
2022-08-17 18:04:41 +00:00
|
|
|
node_modules/.bin/jest --group=$2 --runInBand
|
2022-03-30 02:57:11 +00:00
|
|
|
TESTRESULT=$?
|
|
|
|
report
|
|
|
|
;;
|
|
|
|
'make:collection')
|
|
|
|
node utils/api-collection/build-collection.js $2
|
|
|
|
TESTRESULT=$?
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
2021-09-09 14:41:36 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
# Restore working path
|
|
|
|
cd "$OLDPATH"
|
|
|
|
|
|
|
|
exit $TESTRESULT
|