@@ -9,32 +9,45 @@ PROJECT_DIR=$(dirname "$SCRIPT_DIR")
9
9
# Flag to track if any test fails
10
10
all_tests_passed=true
11
11
12
- # Check if we have enough arguments
12
+ # Check if we have at least two arguments
13
13
if [ $# -ne 2 ]; then
14
14
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...]"
15
16
fi
16
17
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
+
17
34
# Check if jq is installed
18
35
if ! command -v jq & > /dev/null; then
19
36
echo " jq is required but not installed. Aborting."
20
37
exit 1
21
38
fi
22
39
23
40
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
28
47
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; }
32
48
}
33
49
34
50
processWorkspace () {
35
- local location=" $1 "
36
- local testProject=" $2 "
37
-
38
51
if [ ! -d " $location " ]; then
39
52
echo " ⚠ No directory found at $location "
40
53
return
@@ -89,7 +102,7 @@ processWorkspace() {
89
102
echo -e " - Install $library @$trimmed_version for $workspace \n"
90
103
pnpm add " $library @$trimmed_version " --save-peer --filter " $workspace "
91
104
92
- runTestSuite " $testProject "
105
+ runTestSuite
93
106
fi
94
107
done
95
108
done
@@ -98,17 +111,11 @@ processWorkspace() {
98
111
git checkout -- " $package_json_path " " $PROJECT_DIR /pnpm-lock.yaml"
99
112
else
100
113
echo -e " -> No peerDependencies found with multiple versions defined\n"
101
- runTestSuite " $testProject "
114
+ runTestSuite
102
115
fi
103
116
}
104
117
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
112
119
113
120
# Check the flag at the end and exit with code 1 if any test failed
114
121
if [ " $all_tests_passed " = false ]; then
0 commit comments