@@ -9,8 +9,8 @@ PROJECT_DIR=$(dirname "$SCRIPT_DIR")
99# Flag to track if any test fails
1010all_tests_passed=true
1111
12- # Check if we have at least one argument
13- if [ $# -eq 0 ]
12+ # Check if we have enough arguments
13+ if [ $# -eq 2 ]
1414 then
1515 echo " No arguments supplied, please provide the package's path."
1616fi
@@ -22,46 +22,58 @@ if ! command -v jq &> /dev/null; then
2222fi
2323
2424runTestSuite () {
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; }
2733}
2834
2935processWorkspace () {
3036 local location=" $1 "
37+ local testProject=" $2 "
3138
3239 if [ ! -d " $location " ]; then
33- echo " No directory found at $location "
40+ echo " ⚠ No directory found at $location "
3441 return
3542 fi
3643
3744 package_json_path=" $location /package.json"
3845 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 "
4047 return
4148 fi
4249
4350 workspace=$( jq -r ' .name' " $package_json_path " )
4451 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 "
4653 return
4754 fi
4855
49- echo -e " Processing workspace $workspace at location $location ...\n"
56+ echo -e " ⏳ Processing workspace $workspace at location $location ...\n"
5057
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"
5259 deps=$( jq -r ' .peerDependencies | keys[]' " $package_json_path " )
5360 for library in $deps ; do
5461 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
5668
5769 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
6173 fi
6274 done
6375
64- echo " Checking '$package_json_path ' for peerDependencies with multiple versions defined"
76+ echo " ⚙️ Checking '$package_json_path ' for peerDependencies with multiple versions defined"
6577 deps_with_multiple_versions=$( jq -r ' .peerDependencies | to_entries[] | select(.value | contains("||")) | .key' " $package_json_path " )
6678
6779 if [ -n " $deps_with_multiple_versions " ]; then
@@ -78,20 +90,26 @@ processWorkspace() {
7890 echo -e " - Install $library @$trimmed_version for $workspace \n"
7991 pnpm add " $library @$trimmed_version " --save-peer --filter " $workspace "
8092
81- runTestSuite
93+ runTestSuite " $testProject "
8294 fi
8395 done
8496 done
8597
8698 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 "
88100 else
89101 echo -e " -> No peerDependencies found with multiple versions defined\n"
90- runTestSuite
102+ runTestSuite " $testProject "
91103 fi
92104}
93105
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 "
95113
96114# Check the flag at the end and exit with code 1 if any test failed
97115if [ " $all_tests_passed " = false ]; then
0 commit comments