-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run tests for all supported versions defined for peerDependencies per…
… component
- Loading branch information
1 parent
3c5d7a4
commit 16fa514
Showing
2 changed files
with
62 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)"') | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
# 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 | ||
echo "Some tests failed." | ||
exit 1 | ||
else | ||
echo "All tests passed!" | ||
exit 0 | ||
echo "All tests passed!" | ||
exit 0 | ||
fi |
Cannot run tests on macOS since this change :|