Skip to content

Commit

Permalink
Run tests for all supported versions defined for peerDependencies per…
Browse files Browse the repository at this point in the history
… component
  • Loading branch information
evertharmeling authored and weaverryan committed Jan 29, 2024
1 parent 3c5d7a4 commit 16fa514
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 13 deletions.
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)"')

This comment has been minimized.

Copy link
@smnandre

smnandre Jan 29, 2024

Member

Cannot run tests on macOS since this change :|


# 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

0 comments on commit 16fa514

Please sign in to comment.