|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +# This script is used to test an UX package. |
| 4 | +# It also handle the case where a package has multiple versions of a peerDependency defined. |
| 5 | + |
| 6 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" |
| 7 | +PROJECT_DIR=$(dirname "$SCRIPT_DIR") |
| 8 | + |
3 | 9 | # Flag to track if any test fails |
4 | 10 | all_tests_passed=true |
5 | 11 |
|
| 12 | +# Check if we have at least one argument |
| 13 | +if [ $# -eq 0 ] |
| 14 | + then |
| 15 | + echo "No arguments supplied, please provide the package's path." |
| 16 | +fi |
| 17 | + |
6 | 18 | # Check if jq is installed |
7 | 19 | if ! command -v jq &> /dev/null; then |
8 | 20 | echo "jq is required but not installed. Aborting." |
|
11 | 23 |
|
12 | 24 | runTestSuite() { |
13 | 25 | echo -e "Running tests for $workspace...\n" |
14 | | - yarn workspace $workspace run -T vitest --run || { all_tests_passed=false; } |
| 26 | + yarn run -T vitest --run || { all_tests_passed=false; } |
15 | 27 | } |
16 | 28 |
|
17 | 29 | processWorkspace() { |
18 | | - local workspace="$1" |
19 | | - local location="$2" |
| 30 | + local location="$1" |
20 | 31 |
|
21 | | - echo -e "Processing workspace $workspace at location $location...\n" |
| 32 | + if [ ! -d "$location" ]; then |
| 33 | + echo "No directory found at $location" |
| 34 | + return |
| 35 | + fi |
22 | 36 |
|
23 | 37 | package_json_path="$location/package.json" |
| 38 | + if [ ! -f "$package_json_path" ]; then |
| 39 | + echo "No package.json found at $package_json_path" |
| 40 | + return |
| 41 | + fi |
| 42 | + |
| 43 | + workspace=$(jq -r '.name' "$package_json_path") |
| 44 | + if [ -z "$workspace" ]; then |
| 45 | + echo "No name found in package.json at $package_json_path" |
| 46 | + return |
| 47 | + fi |
| 48 | + |
| 49 | + echo -e "Processing workspace $workspace at location $location...\n" |
| 50 | + |
24 | 51 | echo "Checking '$package_json_path' for peerDependencies with multiple versions defined" |
25 | 52 | deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path") |
26 | 53 |
|
@@ -48,21 +75,7 @@ processWorkspace() { |
48 | 75 | fi |
49 | 76 | } |
50 | 77 |
|
51 | | -# Iterate over each workspace using process substitution |
52 | | -while IFS= read -r workspace_info; do |
53 | | - # Split the workspace_info into workspace and location |
54 | | - workspace=$(echo "$workspace_info" | jq -r '.name') |
55 | | - location=$(echo "$workspace_info" | jq -r '.location') |
56 | | - |
57 | | - # Skip the root workspace |
58 | | - if [ $workspace == "null" ]; then |
59 | | - continue |
60 | | - fi |
61 | | - |
62 | | - # Call the function to process the workspace |
63 | | - processWorkspace "$workspace" "$location" |
64 | | - |
65 | | -done < <(yarn workspaces list --json) |
| 78 | +processWorkspace "$(realpath "$PWD/$1")" |
66 | 79 |
|
67 | 80 | # Check the flag at the end and exit with code 1 if any test failed |
68 | 81 | if [ "$all_tests_passed" = false ]; then |
|
0 commit comments