Skip to content

Commit a13d427

Browse files
committed
Rework test_package.sh to allow passing tail args to vitest
1 parent 6c474d4 commit a13d427

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

bin/test_package.sh

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,45 @@ PROJECT_DIR=$(dirname "$SCRIPT_DIR")
99
# Flag to track if any test fails
1010
all_tests_passed=true
1111

12-
# Check if we have enough arguments
12+
# Check if we have at least two arguments
1313
if [ $# -ne 2 ]; then
1414
echo "No arguments supplied, please provide the package's path and the test type (e.g. --unit or --browser)"
15+
echo "Usage: $0 <package_path> <test_type> [args...]"
1516
fi
1617

18+
location="$(realpath "$PWD/$1")"
19+
if [ ! -d "$location" ]; then
20+
echo "The provided package path does not exist or is not a directory: $location"
21+
exit 1
22+
fi
23+
24+
shift
25+
case "$1" in
26+
--unit) testType="unit" ;;
27+
--browser) testType="browser" ;;
28+
*) echo "Unknown test type: $2. Please use --unit or --browser."; exit 1 ;;
29+
esac
30+
31+
shift
32+
args=("$@")
33+
1734
# Check if jq is installed
1835
if ! command -v jq &> /dev/null; then
1936
echo "jq is required but not installed. Aborting."
2037
exit 1
2138
fi
2239

2340
runTestSuite() {
24-
local testProject="$1"
25-
if [ "$testProject" != "unit" ] && [ "$testProject" != "browser" ]; then
26-
echo "Unknown test project: $testProject. Please use 'unit' or 'browser'."
27-
exit 1
41+
if [ "$testType" == "unit" ]; then
42+
echo -e "🧪 Running unit tests for $workspace...\n"
43+
pnpm exec vitest --run "${args[@]}" || { all_tests_passed=false; }
44+
elif [ "$testType" == "browser" ]; then
45+
echo -e "🧪 Running browser tests for $workspace...\n"
46+
# TODO: to implement
2847
fi
29-
30-
echo -e "🧪 Running $testProject tests for $workspace...\n"
31-
pnpm exec vitest --run --config "vitest.config.$testProject.mjs" || { all_tests_passed=false; }
3248
}
3349

3450
processWorkspace() {
35-
local location="$1"
36-
local testProject="$2"
37-
3851
if [ ! -d "$location" ]; then
3952
echo "⚠ No directory found at $location"
4053
return
@@ -89,7 +102,7 @@ processWorkspace() {
89102
echo -e " - Install $library@$trimmed_version for $workspace\n"
90103
pnpm add "$library@$trimmed_version" --save-peer --filter "$workspace"
91104

92-
runTestSuite "$testProject"
105+
runTestSuite
93106
fi
94107
done
95108
done
@@ -98,17 +111,11 @@ processWorkspace() {
98111
git checkout -- "$package_json_path" "$PROJECT_DIR/pnpm-lock.yaml"
99112
else
100113
echo -e " -> No peerDependencies found with multiple versions defined\n"
101-
runTestSuite "$testProject"
114+
runTestSuite
102115
fi
103116
}
104117

105-
case "$2" in
106-
--unit) testProject="unit" ;;
107-
--browser) testProject="browser" ;;
108-
*) echo "Unknown test type: $2. Please use --unit or --browser."; exit 1 ;;
109-
esac
110-
111-
processWorkspace "$(realpath "$PWD/$1")" "$testProject"
118+
processWorkspace
112119

113120
# Check the flag at the end and exit with code 1 if any test failed
114121
if [ "$all_tests_passed" = false ]; then

0 commit comments

Comments
 (0)