@@ -9,10 +9,9 @@ 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 ]
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)"
1615fi
1716
1817# Check if jq is installed
@@ -22,46 +21,58 @@ if ! command -v jq &> /dev/null; then
2221fi
2322
2423runTestSuite () {
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; }
2732}
2833
2934processWorkspace () {
3035 local location=" $1 "
36+ local testProject=" $2 "
3137
3238 if [ ! -d " $location " ]; then
33- echo " No directory found at $location "
39+ echo " ⚠ No directory found at $location "
3440 return
3541 fi
3642
3743 package_json_path=" $location /package.json"
3844 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 "
4046 return
4147 fi
4248
4349 workspace=$( jq -r ' .name' " $package_json_path " )
4450 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 "
4652 return
4753 fi
4854
49- echo -e " Processing workspace $workspace at location $location ...\n"
55+ echo -e " ⏳ Processing workspace $workspace at location $location ...\n"
5056
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"
5258 deps=$( jq -r ' .peerDependencies | keys[]' " $package_json_path " )
5359 for library in $deps ; do
5460 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
5667
5768 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
6172 fi
6273 done
6374
64- echo " Checking '$package_json_path ' for peerDependencies with multiple versions defined"
75+ echo " ⚙️ Checking '$package_json_path ' for peerDependencies with multiple versions defined"
6576 deps_with_multiple_versions=$( jq -r ' .peerDependencies | to_entries[] | select(.value | contains("||")) | .key' " $package_json_path " )
6677
6778 if [ -n " $deps_with_multiple_versions " ]; then
@@ -78,20 +89,26 @@ processWorkspace() {
7889 echo -e " - Install $library @$trimmed_version for $workspace \n"
7990 pnpm add " $library @$trimmed_version " --save-peer --filter " $workspace "
8091
81- runTestSuite
92+ runTestSuite " $testProject "
8293 fi
8394 done
8495 done
8596
8697 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 "
8899 else
89100 echo -e " -> No peerDependencies found with multiple versions defined\n"
90- runTestSuite
101+ runTestSuite " $testProject "
91102 fi
92103}
93104
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 "
95112
96113# Check the flag at the end and exit with code 1 if any test failed
97114if [ " $all_tests_passed " = false ]; then
0 commit comments