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