Skip to content

Commit c217b8d

Browse files
committed
Refactor "test_package.sh" to its original purpose, add multiples checks for packages definition
1 parent 405251f commit c217b8d

File tree

21 files changed

+158
-84
lines changed

21 files changed

+158
-84
lines changed

.github/workflows/code-quality.yaml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,117 @@ concurrency:
1919
cancel-in-progress: true
2020

2121
jobs:
22+
validate-packages:
23+
name: Valide packages definition
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- run: npm i -g corepack && corepack enable
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version-file: '.nvmrc'
32+
cache: 'pnpm'
33+
cache-dependency-path: |
34+
pnpm-lock.yaml
35+
package.json
36+
37+
- name: Install root JS dependencies
38+
run: pnpm install --frozen-lockfile
39+
40+
- name: Check all composer.json have label "symfony-ux"
41+
run: |
42+
for file in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*"); do
43+
if ! jq -e '.keywords | index("symfony-ux")' "$file" > /dev/null; then
44+
echo "File $file does not have the keyword 'symfony-ux' in its composer.json";
45+
exit 1;
46+
fi
47+
done
48+
49+
- name: Check all composer.json have license "MIT"
50+
run: |
51+
for file in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*"); do
52+
if ! jq -e '.license == "MIT"' "$file" > /dev/null; then
53+
echo "File $file does not have the license 'MIT' in its composer.json";
54+
exit 1;
55+
fi
56+
done
57+
58+
- name: Check all composer.json have minimum-stability "dev"
59+
run: |
60+
for file in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*"); do
61+
if ! jq -e '."minimum-stability" == "dev"' "$file" > /dev/null; then
62+
echo "File $file does not have the minimum-stability 'dev' in its composer.json";
63+
exit 1;
64+
fi
65+
done
66+
67+
- name: Check all composer.json have dependency to "php" >=8.1
68+
run:
69+
for file in $(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*"); do
70+
if ! jq -e '.require.php | test(">=8.1")' "$file" > /dev/null; then
71+
echo "File $file does not have the dependency 'php' >=8.1 in its composer.json";
72+
exit 1;
73+
fi
74+
done
75+
76+
- name: Check all package.json have license "MIT"
77+
run: |
78+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
79+
if ! jq -e '.license == "MIT"' "$file" > /dev/null; then
80+
echo "File $file does not have the license 'MIT' in its package.json";
81+
exit 1;
82+
fi
83+
done
84+
85+
- name: Check all package.json have keywords including "symfony-ux"
86+
run: |
87+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
88+
if ! jq -e '.keywords | index("symfony-ux")' "$file" > /dev/null; then
89+
echo "File $file does not have the keyword 'symfony-ux' in its package.json";
90+
exit 1;
91+
fi
92+
done
93+
94+
95+
- name: Check all package.json have type "module"
96+
run: |
97+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
98+
if ! jq -e '.type == "module"' "$file" > /dev/null; then
99+
echo "File $file does not have the type 'module' in its package.json";
100+
exit 1;
101+
fi
102+
done
103+
104+
- name: Check all package.json have files '["dist"]'
105+
run: |
106+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
107+
if ! jq -e '.files | index("dist")' "$file" > /dev/null; then
108+
echo "File $file does not have the files 'dist' in its package.json";
109+
exit 1;
110+
fi
111+
done
112+
113+
- name: Check all package.json peerDependencies are present in devDependencies and importmap to the exact same version
114+
run: |
115+
for file in $(find src/ -mindepth 2 -type f -name package.json -not -path "*/vendor/*" -not -path "*/node_modules/*" -not -path "*/tests/*"); do
116+
peerDependencies=$(jq -r '.peerDependencies | keys[]' "$file")
117+
for peerDependency in $peerDependencies; do
118+
peerDependencyVersion=$(jq -r --arg dep "$peerDependency" '.peerDependencies[$dep]' "$file")
119+
importmapVersion=$(jq -r ".symfony.importmap.\"$peerDependency\" | if type == \"string\" then . else .version end" "$file")
120+
121+
if [ "$importmapVersion" == null ]; then
122+
echo "File $file does not have the peerDependency '$peerDependency' in its symfony.importmap, skipping version check";
123+
continue
124+
fi
125+
126+
if [ "$peerDependencyVersion" != "$importmapVersion" ]; then
127+
echo "File $file has a mismatch for $peerDependency: peerDependency version is '$peerDependencyVersion' but symfony.importmap version is '$importmapVersion'";
128+
exit 1;
129+
fi
130+
done
131+
done
132+
22133
coding-style-js:
23134
name: JavaScript Coding Style
24135
runs-on: ubuntu-latest

bin/test_package.sh renamed to bin/unit_test_package.sh

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# This script is used to test an UX package.
3+
# This script is used to unit test assets from an UX package.
44
# It also handle the case where a package has multiple versions of a peerDependency defined.
55

66
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
@@ -21,13 +21,6 @@ if [ ! -d "$location" ]; then
2121
exit 1
2222
fi
2323

24-
shift
25-
case "$1" in
26-
--unit) testType="unit" ;;
27-
--browser) testType="browser" ;;
28-
*) echo "Unknown test type: $2. Please use --unit or --browser."; exit 1 ;;
29-
esac
30-
3124
shift
3225
args=("$@")
3326

@@ -38,15 +31,9 @@ if ! command -v jq &> /dev/null; then
3831
fi
3932

4033
runTestSuite() {
41-
if [ "$testType" == "unit" ]; then
42-
echo -e "🧪 Running unit tests for $workspace...\n"
43-
# Using "cd" instead of "pnpm --filter" prevent rendering issues in GitHub Actions that does not support nested groups
44-
(cd "$location"; pnpm exec vitest --run "${args[@]}") || { all_tests_passed=false; }
45-
elif [ "$testType" == "browser" ]; then
46-
echo -e "🧪 Running browser tests for $workspace...\n"
47-
# Using "cd" instead of "pnpm --filter" prevent rendering issues in GitHub Actions that does not support nested groups
48-
(cd "$location"; pnpm exec playwright test "${args[@]}") || { all_tests_passed=false; }
49-
fi
34+
echo -e "🧪 Running unit tests for $workspace...\n"
35+
# Using "cd" instead of "pnpm --filter" prevent rendering issues in GitHub Actions that does not support nested groups
36+
(cd "$location"; pnpm exec vitest --run "${args[@]}") || { all_tests_passed=false; }
5037
}
5138

5239
processWorkspace() {
@@ -69,30 +56,6 @@ processWorkspace() {
6956

7057
echo -e "⏳ Processing workspace $workspace at location $location...\n"
7158

72-
# TODO: Refactor the `test_package.sh` script to its simple form: only run unit tests for a given UX package,
73-
# The rest will be moved to `pnpm` scripts or other CI checks
74-
if [ "$testType" == "browser" ]; then
75-
runTestSuite
76-
fi
77-
78-
echo "⚙️ Checking '$package_json_path' for peerDependencies and importmap dependencies to have the same version"
79-
deps=$(jq -r '.peerDependencies | keys[]' "$package_json_path")
80-
for library in $deps; do
81-
version=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path")
82-
importmap_version=$(jq -r ".symfony.importmap.\"$library\" | if type == \"string\" then . else .version end" "$package_json_path")
83-
84-
if [ "$importmap_version" == null ]; then
85-
echo " ⚠ No importmap version found for $library in $package_json_path, skipping..."
86-
continue
87-
fi
88-
89-
if [ "$version" != "$importmap_version" ]; then
90-
echo " ⚠ Version mismatch for $library: $version (peerDependencies) vs $importmap_version (importmap)"
91-
echo " ⚠ You need to match the version of the \"peerDependency\" with the version in the \"importmap\""
92-
exit 1
93-
fi
94-
done
95-
9659
echo "⚙️ Checking '$package_json_path' for peerDependencies with multiple versions defined"
9760
deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path")
9861

src/Autocomplete/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"build": "tsx ../../../bin/build_package.ts .",
1919
"watch": "tsx ../../../bin/build_package.ts . --watch",
2020
"test": "pnpm run test:unit && pnpm run test:browser",
21-
"test:unit": "../../../bin/test_package.sh . --unit",
22-
"test:browser": "../../../bin/test_package.sh . --browser",
23-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
21+
"test:unit": "../../../bin/unit_test_package.sh .",
22+
"test:browser": "playwright test",
23+
"test:browser:ui": "playwright test --ui",
2424
"check": "biome check",
2525
"ci": "biome ci"
2626
},

src/Chartjs/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"build": "tsx ../../../bin/build_package.ts .",
1919
"watch": "tsx ../../../bin/build_package.ts . --watch",
2020
"test": "pnpm run test:unit && pnpm run test:browser",
21-
"test:unit": "../../../bin/test_package.sh . --unit",
22-
"test:browser": "../../../bin/test_package.sh . --browser",
23-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
21+
"test:unit": "../../../bin/unit_test_package.sh .",
22+
"test:browser": "playwright test",
23+
"test:browser:ui": "playwright test --ui",
2424
"check": "biome check",
2525
"ci": "biome ci"
2626
},

src/Cropperjs/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"build": "tsx ../../../bin/build_package.ts .",
2222
"watch": "tsx ../../../bin/build_package.ts . --watch",
2323
"test": "pnpm run test:unit && pnpm run test:browser",
24-
"test:unit": "../../../bin/test_package.sh . --unit",
25-
"test:browser": "../../../bin/test_package.sh . --browser",
26-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
24+
"test:unit": "../../../bin/unit_test_package.sh .",
25+
"test:browser": "playwright test",
26+
"test:browser:ui": "playwright test --ui",
2727
"check": "biome check",
2828
"ci": "biome ci"
2929
},

src/Dropzone/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"build": "tsx ../../../bin/build_package.ts .",
2222
"watch": "tsx ../../../bin/build_package.ts . --watch",
2323
"test": "pnpm run test:unit && pnpm run test:browser",
24-
"test:unit": "../../../bin/test_package.sh . --unit",
25-
"test:browser": "../../../bin/test_package.sh . --browser",
26-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
24+
"test:unit": "../../../bin/unit_test_package.sh .",
25+
"test:browser": "playwright test",
26+
"test:browser:ui": "playwright test --ui",
2727
"check": "biome check",
2828
"ci": "biome ci"
2929
},

src/LazyImage/assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"build": "tsx ../../../bin/build_package.ts .",
1919
"watch": "tsx ../../../bin/build_package.ts . --watch",
2020
"test": "pnpm run test:unit",
21-
"test:unit": "../../../bin/test_package.sh . --unit",
21+
"test:unit": "../../../bin/unit_test_package.sh .",
2222
"check": "biome check",
2323
"ci": "biome ci"
2424
},

src/LiveComponent/assets/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"build": "tsx ../../../bin/build_package.ts .",
2424
"watch": "tsx ../../../bin/build_package.ts . --watch",
2525
"test": "pnpm run test:unit && pnpm run test:browser",
26-
"test:unit": "../../../bin/test_package.sh . --unit",
27-
"test:browser": "../../../bin/test_package.sh . --browser",
28-
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
26+
"test:unit": "../../../bin/unit_test_package.sh .",
27+
"test:browser": "playwright test",
28+
"test:browser:ui": "playwright test --ui",
2929
"check": "biome check",
3030
"ci": "biome ci"
3131
},

src/Map/assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"build": "tsx ../../../bin/build_package.ts .",
2323
"watch": "tsx ../../../bin/build_package.ts . --watch",
2424
"test": "pnpm run test:unit",
25-
"test:unit": "../../../bin/test_package.sh . --unit",
25+
"test:unit": "../../../bin/unit_test_package.sh .",
2626
"check": "biome check",
2727
"ci": "biome ci"
2828
},

src/Map/src/Bridge/Google/assets/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"build": "tsx ../../../../../../bin/build_package.ts .",
2121
"watch": "tsx ../../../../../../bin/build_package.ts . --watch",
2222
"test": "pnpm run test:browser",
23-
"test:browser": "../../../../../../bin/test_package.sh . --browser",
24-
"test:browser:ui": "../../../../../../bin/test_package.sh . --browser --ui",
23+
"test:browser": "playwright test",
24+
"test:browser:ui": "playwright test --ui",
2525
"check": "biome check",
2626
"ci": "biome ci"
2727
},

0 commit comments

Comments
 (0)