@@ -9,10 +9,9 @@ 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 at least one argument
13
- if [ $# -eq 0 ]
14
- then
15
- echo " No arguments supplied, please provide the package's path."
12
+ # Check if we have enough arguments
13
+ if [ $# -ne 2 ]; then
14
+ echo " No arguments supplied, please provide the package's path and the test type (e.g. --unit or --browser)"
16
15
fi
17
16
18
17
# Check if jq is installed
@@ -22,46 +21,58 @@ if ! command -v jq &> /dev/null; then
22
21
fi
23
22
24
23
runTestSuite () {
25
- echo -e " Running tests for $workspace ...\n"
26
- pnpm exec vitest --run || { all_tests_passed=false; }
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
28
+ 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; }
27
32
}
28
33
29
34
processWorkspace () {
30
35
local location=" $1 "
36
+ local testProject=" $2 "
31
37
32
38
if [ ! -d " $location " ]; then
33
- echo " No directory found at $location "
39
+ echo " ⚠ No directory found at $location "
34
40
return
35
41
fi
36
42
37
43
package_json_path=" $location /package.json"
38
44
if [ ! -f " $package_json_path " ]; then
39
- echo " No package.json found at $package_json_path "
45
+ echo " ⚠ No package.json found at $package_json_path "
40
46
return
41
47
fi
42
48
43
49
workspace=$( jq -r ' .name' " $package_json_path " )
44
50
if [ -z " $workspace " ]; then
45
- echo " No name found in package.json at $package_json_path "
51
+ echo " ⚠ No name found in package.json at $package_json_path "
46
52
return
47
53
fi
48
54
49
- echo -e " Processing workspace $workspace at location $location ...\n"
55
+ echo -e " ⏳ Processing workspace $workspace at location $location ...\n"
50
56
51
- echo " Checking '$package_json_path ' for peerDependencies and importmap dependencies to have the same version"
57
+ echo " ⚙️ Checking '$package_json_path ' for peerDependencies and importmap dependencies to have the same version"
52
58
deps=$( jq -r ' .peerDependencies | keys[]' " $package_json_path " )
53
59
for library in $deps ; do
54
60
version=$( jq -r " .peerDependencies.\" $library \" " " $package_json_path " )
55
- importmap_version=$( jq -r " .symfony.importmap.\" $library \" " " $package_json_path " )
61
+ importmap_version=$( jq -r " .symfony.importmap.\" $library \" | if type == \" string\" then . else .version end" " $package_json_path " )
62
+
63
+ if [ " $importmap_version " == null ]; then
64
+ echo " ⚠ No importmap version found for $library in $package_json_path , skipping..."
65
+ continue
66
+ fi
56
67
57
68
if [ " $version " != " $importmap_version " ]; then
58
- echo " -> Version mismatch for $library : $version (peerDependencies) vs $importmap_version (importmap)"
59
- echo " -> You need to match the version of the \" peerDependency\" with the version in the \" importmap\" "
60
- exit
69
+ echo " ⚠ Version mismatch for $library : $version (peerDependencies) vs $importmap_version (importmap)"
70
+ echo " ⚠ You need to match the version of the \" peerDependency\" with the version in the \" importmap\" "
71
+ exit 1
61
72
fi
62
73
done
63
74
64
- echo " Checking '$package_json_path ' for peerDependencies with multiple versions defined"
75
+ echo " ⚙️ Checking '$package_json_path ' for peerDependencies with multiple versions defined"
65
76
deps_with_multiple_versions=$( jq -r ' .peerDependencies | to_entries[] | select(.value | contains("||")) | .key' " $package_json_path " )
66
77
67
78
if [ -n " $deps_with_multiple_versions " ]; then
@@ -78,20 +89,26 @@ processWorkspace() {
78
89
echo -e " - Install $library @$trimmed_version for $workspace \n"
79
90
pnpm add " $library @$trimmed_version " --save-peer --filter " $workspace "
80
91
81
- runTestSuite
92
+ runTestSuite " $testProject "
82
93
fi
83
94
done
84
95
done
85
96
86
97
echo " -> Reverting version changes from $package_json_path "
87
- git checkout -- " $package_json_path "
98
+ git checkout -- " $package_json_path " " $PROJECT_DIR /pnpm-lock.yaml "
88
99
else
89
100
echo -e " -> No peerDependencies found with multiple versions defined\n"
90
- runTestSuite
101
+ runTestSuite " $testProject "
91
102
fi
92
103
}
93
104
94
- processWorkspace " $( realpath " $PWD /$1 " ) "
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 "
95
112
96
113
# Check the flag at the end and exit with code 1 if any test failed
97
114
if [ " $all_tests_passed " = false ]; then
0 commit comments