Skip to content

Commit b52bd37

Browse files
committed
minor #1417 Run tests for all supported versions defined for peerDependencies per component (evertharmeling)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Run tests for all supported versions defined for peerDependencies per component | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Issues | Relates to #1389 | License | MIT Refactored the `run-vitest-all.sh` script to loop over every component/workspace and check if there are `peerDependencies` who defined support for multiple versions (like https://github.com/symfony/ux/blob/2.x/src/Svelte/assets/package.json#L23). The script then runs the tests for every defined version for that library in that workspace. The greatest benefit of this change is that this needs no extra administration in keeping a `matrix` value up-to-date in the GitHub workflow for every library in a workspace that supports more than 1 version as it checks every `package.json` automatically. Tell me what you think about it! Cheers! - https://github.com/symfony/ux/actions/runs/7646573943/job/20835661388?pr=1417#step:6:200 -> `[email protected]` is installed - https://github.com/symfony/ux/actions/runs/7646573943/job/20835661388?pr=1417#step:6:259 -> `[email protected]` is installed Commits ------- 16fa514 Run tests for all supported versions defined for peerDependencies per component
2 parents 3c8eb41 + 16fa514 commit b52bd37

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

.github/workflows/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,5 @@ jobs:
143143
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
144144
restore-keys: |
145145
${{ runner.os }}-yarn-
146-
- run: yarn --frozen-lockfile
146+
- run: yarn --immutable
147147
- run: yarn test

bin/run-vitest-all.sh

+61-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,72 @@
11
#!/bin/bash
22

3-
# Get all workspace names
4-
workspaces=$(yarn workspaces info | grep -o '@symfony/[^"]*')
5-
63
# Flag to track if any test fails
74
all_tests_passed=true
85

9-
for workspace in $workspaces; do
10-
echo "Running tests in $workspace..."
6+
# Check if jq is installed
7+
if ! command -v jq &> /dev/null; then
8+
echo "jq is required but not installed. Aborting."
9+
exit 1
10+
fi
11+
12+
runTestSuite() {
13+
echo -e "Running tests for $workspace...\n"
14+
yarn workspace $workspace run vitest --run || { all_tests_passed=false; }
15+
}
16+
17+
processWorkspace() {
18+
local workspace="$1"
19+
local location="$2"
20+
21+
echo -e "Processing workspace $workspace at location $location...\n"
22+
23+
package_json_path="$location/package.json"
24+
echo "Checking '$package_json_path' for peerDependencies with multiple versions defined"
25+
deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path")
26+
27+
if [ -n "$deps_with_multiple_versions" ]; then
28+
echo " -> Multiple versions found for peerDependencies: $deps_with_multiple_versions"
29+
for library in $deps_with_multiple_versions; do
30+
versionValue=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path")
31+
32+
IFS="||" read -ra versions <<< "$versionValue"
33+
34+
for version in "${versions[@]}"; do
35+
trimmed_version=$(echo "$version" | tr -d '[:space:]')
36+
if [ -n "$trimmed_version" ]; then
37+
# Install each version of the library separately
38+
echo -e " - Install $library@$trimmed_version for $workspace\n"
39+
yarn workspace "$workspace" add "$library@$trimmed_version" --peer
40+
41+
runTestSuite
42+
fi
43+
done
44+
done
45+
else
46+
echo -e " -> No peerDependencies found with multiple versions defined\n"
47+
runTestSuite
48+
fi
49+
}
50+
51+
# Get all workspace names
52+
workspaces_info=$(yarn workspaces info)
53+
54+
# Iterate over each workspace using process substitution
55+
while IFS= read -r workspace_info; do
56+
# Split the workspace_info into workspace and location
57+
workspace=$(echo "$workspace_info" | awk '{print $1}')
58+
location=$(echo "$workspace_info" | awk '{print $2}')
59+
60+
# Call the function to process the workspace
61+
processWorkspace "$workspace" "$location"
1162

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

1665
# Check the flag at the end and exit with code 1 if any test failed
1766
if [ "$all_tests_passed" = false ]; then
18-
echo "Some tests failed."
19-
exit 1
67+
echo "Some tests failed."
68+
exit 1
2069
else
21-
echo "All tests passed!"
22-
exit 0
70+
echo "All tests passed!"
71+
exit 0
2372
fi

0 commit comments

Comments
 (0)