Skip to content

Commit

Permalink
Run tests for all supported versions of peerDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
evertharmeling committed Jan 24, 2024
1 parent 54650c3 commit 4a439be
Showing 1 changed file with 62 additions and 13 deletions.
75 changes: 62 additions & 13 deletions bin/run-vitest-all.sh
@@ -1,23 +1,72 @@
#!/bin/bash

# Get all workspace names
workspaces=$(yarn workspaces info | grep -o '@symfony/[^"]*')

# Flag to track if any test fails
all_tests_passed=true

for workspace in $workspaces; do
echo "Running tests in $workspace..."
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "jq is required but not installed. Aborting."
exit 1
fi

runTestSuite() {
echo -e "Running tests for $workspace...\n"
yarn workspace $workspace run vitest --run || { all_tests_passed=false; }
}

processWorkspace() {
local workspace="$1"
local location="$2"

echo -e "Processing workspace $workspace at location $location...\n"

package_json_path="$location/package.json"
echo "Checking '$package_json_path' for peerDependencies with multiple versions defined"
deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path")

if [ -n "$deps_with_multiple_versions" ]; then
echo " -> Multiple versions found for peerDependencies: $deps_with_multiple_versions"
for library in $deps_with_multiple_versions; do
versionValue=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path")

IFS="||" read -ra versions <<< "$versionValue"

for version in "${versions[@]}"; do
trimmed_version=$(echo "$version" | tr -d '[:space:]')
if [ -n "$trimmed_version" ]; then
# Install each version of the library separately
echo -e " - Install $library@$trimmed_version for $workspace\n"
yarn workspace "$workspace" add "$library@$trimmed_version" --peer

runTestSuite
fi
done
done
else
echo -e " -> No peerDependencies found with multiple versions defined\n"
runTestSuite
fi
}

# Get all workspace names
workspaces_info=$(yarn workspaces info)

# Iterate over each workspace using process substitution
while IFS= read -r workspace_info; do
# Split the workspace_info into workspace and location
workspace=$(echo "$workspace_info" | awk '{print $1}')
location=$(echo "$workspace_info" | awk '{print $2}')

# Call the function to process the workspace
processWorkspace "$workspace" "$location"

# Run the tests and if they fail, set the flag to false
yarn workspace $workspace run vitest --run || { echo "$workspace failed"; all_tests_passed=false; }
done
done < <(echo "$workspaces_info" | jq -r 'to_entries[0:] | .[] | "\(.key) \(.value.location)"')

# Check the flag at the end and exit with code 1 if any test failed
if [ "$all_tests_passed" = false ]; then
echo "Some tests failed."
exit 1
if [ "$all_tests_passed" = false ]; then
echo "Some tests failed."
exit 1
else
echo "All tests passed!"
exit 0
echo "All tests passed!"
exit 0
fi

0 comments on commit 4a439be

Please sign in to comment.