Skip to content

Commit 9c5d210

Browse files
committed
Configure Vitest for unit and browser tests
1 parent 5eb1153 commit 9c5d210

File tree

108 files changed

+1865
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1865
-412
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Browser Tests
2+
3+
defaults:
4+
run:
5+
shell: bash
6+
7+
on:
8+
push:
9+
paths-ignore:
10+
- 'src/*/doc/**'
11+
- 'src/**/*.md'
12+
- 'ux.symfony.com/**'
13+
- '.github/workflows/app-tests.yaml'
14+
- '.github/workflows/unit-tests.yaml'
15+
pull_request:
16+
paths-ignore:
17+
- 'src/*/doc/**'
18+
- 'src/**/*.md'
19+
- 'ux.symfony.com/**'
20+
- '.github/workflows/app-tests.yaml'
21+
- '.github/workflows/unit-tests.yaml'
22+
23+
jobs:
24+
js:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
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+
src/**/package.json
37+
- run: pnpm install --frozen-lockfile
38+
# TODO: Install the E2E app + run webserver
39+
- run: pnpm run test:browser

.github/workflows/functional-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Deprecated, will be removed in favor of browser-tests.yml
12
name: Functional Tests
23

34
defaults:

.github/workflows/unit-tests.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,16 @@ jobs:
143143
fi
144144
js:
145145
runs-on: ubuntu-latest
146-
strategy:
147-
fail-fast: false
148-
matrix:
149-
node-version: [ '18.x', '20.x', '22.x', '24.x' ]
150146
steps:
151147
- uses: actions/checkout@v4
152148
- run: npm i -g corepack && corepack enable
153149
- uses: actions/setup-node@v4
154150
with:
155-
node-version: ${{ matrix.node-version }}
151+
node-version-file: '.nvmrc'
156152
cache: 'pnpm'
157153
cache-dependency-path: |
158154
pnpm-lock.yaml
159155
package.json
160156
src/**/package.json
161157
- run: pnpm install --frozen-lockfile
162-
- run: pnpm exec playwright install chromium
163-
- run: pnpm run test
158+
- run: pnpm run test:unit

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,16 @@ To help you with assets, you can run the following commands in a specific packag
8282
- `pnpm run build`: build (compile) assets from the package,
8383
- `pnpm run watch`: watch for modifications and rebuild assets from the package,
8484
- `pnpm run test`: run the tests from the package,
85+
- `pnpm run test:unit`: run the Unit tests from the package,
86+
- `pnpm run test:browser`: run the Browser tests from the package,
8587
- `pnpm run check`: run the formatter, linter, and sort imports, and fails if any modifications
8688
- `pnpm run check --write`: run the formatter, linter, imports sorting, and write modifications
8789

8890
Thanks to [PNPM Workspaces](https://pnpm.io/workspaces), you can also run these commands from the root directory of the project:
8991
- `pnpm run build`: build (compile) assets from **all** packages,
9092
- `pnpm run test`: run the tests from **all** packages,
93+
- `pnpm run test:unit`: run the Unit tests from **all** packages,
94+
- `pnpm run test:browser`: run the Browser tests from **all** packages,
9195
- `pnpm run check`: run the formatter, linter, and sort imports for **all** packages, and fails if any modifications
9296
- `pnpm run check --write`: run the formatter, linter, imports sorting for **all** packages, and write modifications
9397

@@ -112,7 +116,7 @@ docker run --rm -it -e DOCS_DIR='/docs' -v ${PWD}:/docs oskarstark/doctor-rst -
112116
```shell
113117
$ git checkout 2.x && \
114118
git fetch upstream && \
115-
git rebase upstream/2.x && \
119+
git reset --hard upstream/2.x && \
116120
git push origin 2.x
117121
```
118122

bin/test_package.sh

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ PROJECT_DIR=$(dirname "$SCRIPT_DIR")
99
# Flag to track if any test fails
1010
all_tests_passed=true
1111

12-
# Check if we have at least one argument
13-
if [ $# -eq 0 ]
12+
# Check if we have enough arguments
13+
if [ $# -eq 2 ]
1414
then
1515
echo "No arguments supplied, please provide the package's path."
1616
fi
@@ -22,46 +22,58 @@ if ! command -v jq &> /dev/null; then
2222
fi
2323

2424
runTestSuite() {
25-
echo -e "Running tests for $workspace...\n"
26-
pnpm exec vitest --run || { all_tests_passed=false; }
25+
local testProject="$1"
26+
if [ "$testProject" != "unit" ] && [ "$testProject" != "browser" ]; then
27+
echo "Unknown test project: $testProject. Please use 'unit' or 'browser'."
28+
exit 1
29+
fi
30+
31+
echo -e "🧪 Running $testProject tests for $workspace...\n"
32+
pnpm exec vitest --run --project "$testProject" || { all_tests_passed=false; }
2733
}
2834

2935
processWorkspace() {
3036
local location="$1"
37+
local testProject="$2"
3138

3239
if [ ! -d "$location" ]; then
33-
echo "No directory found at $location"
40+
echo "No directory found at $location"
3441
return
3542
fi
3643

3744
package_json_path="$location/package.json"
3845
if [ ! -f "$package_json_path" ]; then
39-
echo "No package.json found at $package_json_path"
46+
echo "No package.json found at $package_json_path"
4047
return
4148
fi
4249

4350
workspace=$(jq -r '.name' "$package_json_path")
4451
if [ -z "$workspace" ]; then
45-
echo "No name found in package.json at $package_json_path"
52+
echo "No name found in package.json at $package_json_path"
4653
return
4754
fi
4855

49-
echo -e "Processing workspace $workspace at location $location...\n"
56+
echo -e "Processing workspace $workspace at location $location...\n"
5057

51-
echo "Checking '$package_json_path' for peerDependencies and importmap dependencies to have the same version"
58+
echo "⚙️ Checking '$package_json_path' for peerDependencies and importmap dependencies to have the same version"
5259
deps=$(jq -r '.peerDependencies | keys[]' "$package_json_path")
5360
for library in $deps; do
5461
version=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path")
55-
importmap_version=$(jq -r ".symfony.importmap.\"$library\"" "$package_json_path")
62+
importmap_version=$(jq -r ".symfony.importmap.\"$library\" | if type == \"string\" then . else .version end" "$package_json_path")
63+
64+
if [ "$importmap_version" == null ]; then
65+
echo " ⚠ No importmap version found for $library in $package_json_path, skipping..."
66+
continue
67+
fi
5668

5769
if [ "$version" != "$importmap_version" ]; then
58-
echo " -> Version mismatch for $library: $version (peerDependencies) vs $importmap_version (importmap)"
59-
echo " -> You need to match the version of the \"peerDependency\" with the version in the \"importmap\""
60-
exit
70+
echo " Version mismatch for $library: $version (peerDependencies) vs $importmap_version (importmap)"
71+
echo " You need to match the version of the \"peerDependency\" with the version in the \"importmap\""
72+
exit 1
6173
fi
6274
done
6375

64-
echo "Checking '$package_json_path' for peerDependencies with multiple versions defined"
76+
echo "⚙️ Checking '$package_json_path' for peerDependencies with multiple versions defined"
6577
deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path")
6678

6779
if [ -n "$deps_with_multiple_versions" ]; then
@@ -78,20 +90,26 @@ processWorkspace() {
7890
echo -e " - Install $library@$trimmed_version for $workspace\n"
7991
pnpm add "$library@$trimmed_version" --save-peer --filter "$workspace"
8092

81-
runTestSuite
93+
runTestSuite "$testProject"
8294
fi
8395
done
8496
done
8597

8698
echo " -> Reverting version changes from $package_json_path"
87-
git checkout -- "$package_json_path"
99+
git checkout -- "$package_json_path" "$PROJECT_DIR/pnpm-lock.yaml"
88100
else
89101
echo -e " -> No peerDependencies found with multiple versions defined\n"
90-
runTestSuite
102+
runTestSuite "$testProject"
91103
fi
92104
}
93105

94-
processWorkspace "$(realpath "$PWD/$1")"
106+
case "$2" in
107+
--unit) testProject="unit" ;;
108+
--browser) testProject="browser" ;;
109+
*) echo "Unknown test type: $2. Please use --unit or --browser."; exit 1 ;;
110+
esac
111+
112+
processWorkspace "$(realpath "$PWD/$1")" "$testProject"
95113

96114
# Check the flag at the end and exit with code 1 if any test failed
97115
if [ "$all_tests_passed" = false ]; then

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
],
99
"scripts": {
1010
"build": "pnpm run --filter @symfony/ux-map build && pnpm run -r --aggregate-output build",
11-
"test": "pnpm run -r --aggregate-output test",
11+
"test": "pnpm run -r --workspace-concurrency=1 test",
12+
"test:unit": "pnpm run -r test:unit",
13+
"test:browser": "pnpm run -r --workspace-concurrency=1 test:browser",
1214
"check": "biome check",
1315
"ci": "biome ci"
1416
},
@@ -19,10 +21,10 @@
1921
"@types/node": "^22.6.0",
2022
"lightningcss": "^1.28.2",
2123
"pkg-types": "^2.2.0",
22-
"playwright": "^1.47.0",
2324
"tinyglobby": "^0.2.14",
2425
"tsup": "^8.5.0",
25-
"vitest": "^3.2.4"
26+
"vitest": "^3.2.4",
27+
"webdriverio": "^9.19.1"
2628
},
2729
"version": "2.27.0"
2830
}

0 commit comments

Comments
 (0)