Skip to content

Run tests for all supported versions defined for peerDependencies per component #1417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn --frozen-lockfile
- run: yarn --immutable
- run: yarn test
73 changes: 61 additions & 12 deletions bin/run-vitest-all.sh
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)"')

# 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