Skip to content

Commit 405251f

Browse files
committed
minor #3086 Add doc for E2E steps + minor modifications (raphael-geffroy)
This PR was merged into the 2.x branch. Discussion ---------- Add doc for E2E steps + minor modifications | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | yes | Issues | Fix #3039 | License | MIT Commits ------- ceefa1d [Docs] Add doc for E2E steps + minor modifications
2 parents c31a6b9 + ceefa1d commit 405251f

File tree

16 files changed

+70
-3
lines changed

16 files changed

+70
-3
lines changed

CONTRIBUTING.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,64 @@ To help you with assets, you can run the following commands in a specific packag
8383
- `pnpm run watch`: watch for modifications and rebuild assets from the package,
8484
- `pnpm run test`: run the tests from the package,
8585
- `pnpm run test:unit`: run the Unit tests from the package,
86-
- `pnpm run test:browser`: run the Browser tests from the package,
86+
- `pnpm run test:browser`: run the Browser tests from the package, in a headless browser
87+
- `pnpm run test:browser:ui`: run the Browser tests from the package in interactive mode, allowing you to see the tests running in a browser window and debug them if needed
8788
- `pnpm run check`: run the formatter, linter, and sort imports, and fails if any modifications
8889
- `pnpm run check --write`: run the formatter, linter, imports sorting, and write modifications
8990

9091
Thanks to [PNPM Workspaces](https://pnpm.io/workspaces), you can also run these commands from the root directory of the project:
9192
- `pnpm run build`: build (compile) assets from **all** packages,
9293
- `pnpm run test`: run the tests from **all** packages,
9394
- `pnpm run test:unit`: run the Unit tests from **all** packages,
94-
- `pnpm run test:browser`: run the Browser tests from **all** packages,
95+
- `pnpm run test:browser`: run the Browser tests from **all** packages, in a headless browser
9596
- `pnpm run check`: run the formatter, linter, and sort imports for **all** packages, and fails if any modifications
9697
- `pnpm run check --write`: run the formatter, linter, imports sorting for **all** packages, and write modifications
9798

99+
#### Working with Unit tests
100+
101+
We use [Vitest](https://vitest.dev/) for unit testing of the assets,
102+
and tests files are located in the `assets/test/unit/` directory of each UX package,
103+
for example: `src/Vue/assets/test/unit/render_controller.test.ts`.
104+
105+
**Running tests:**
106+
- At the project's root, you can run the following commands:
107+
- `pnpm run test:unit`: runs the unit tests for **all** UX packages
108+
- Inside the `assets/` directory of each UX package, you can run the following commands:
109+
- `pnpm run test:unit`: runs the unit tests for the package
110+
111+
> [!IMPORTANT]
112+
> The command `pnpm run test:unit` ensure that each possible combination of dependencies is tested
113+
> (e.g., `"chart.js": "^3.4.1 || ^4.0"` for UX Chartjs).
114+
> Thus it may take some time to run, and it may be not recommended to use watch mode.
115+
116+
#### Working with End-to-End (E2E) tests
117+
118+
> [!NOTE]
119+
> E2E tests simulate real user interactions in a browser, to ensure that the
120+
> UX packages work as expected in a real-world scenario.
121+
122+
Symfony UX use [Playwright](https://playwright.dev/) for browser automation and testing,
123+
and a dedicated Symfony application located in the [`apps/e2e/`](./apps/e2e/) directory,
124+
which contains many examples of Symfony UX packages usage.
125+
126+
Tests files are located in the `assets/test/browser/` directory of each UX package,
127+
for example: `src/Vue/assets/test/browser/vue.test.ts`.
128+
129+
**Setup:**
130+
1. Ensure to have followed the steps in the [Setting up the development environment](#setting-up-the-development-environment) section
131+
2. Read and follow the instructions in the [`apps/e2e/README.md`](./apps/e2e/README.md) file,
132+
133+
**Running tests:**
134+
- At the project's root, you can run the following commands:
135+
- `pnpm run test:browser`: runs the browser tests for **all** UX packages, using a headless browser
136+
- Inside the `assets/` directory of each UX package, you can run the following commands:
137+
- `pnpm run test:browser`: runs browser tests for the package, using a headless browser
138+
- `pnpm run test:browser:ui`: runs the browser tests in interactive mode, allowing you to see the tests running in a browser window and debug them if needed
139+
140+
> [!IMPORTANT]
141+
> Due to their nature, E2E tests may be slower to run than unit tests.
142+
> During the development, we recommend to run `pnpm run test:browser` or `pnpm run test:browser:ui` for a specific UX package.
143+
98144
### Working on documentation
99145

100146
Symfony UX documentation is written in ReStructuredText (`.rst`) and is located in the `docs/` directory

bin/test_package.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ fi
4040
runTestSuite() {
4141
if [ "$testType" == "unit" ]; then
4242
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
4344
(cd "$location"; pnpm exec vitest --run "${args[@]}") || { all_tests_passed=false; }
4445
elif [ "$testType" == "browser" ]; then
4546
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
4648
(cd "$location"; pnpm exec playwright test "${args[@]}") || { all_tests_passed=false; }
4749
fi
4850
}
@@ -67,6 +69,12 @@ processWorkspace() {
6769

6870
echo -e "⏳ Processing workspace $workspace at location $location...\n"
6971

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+
7078
echo "⚙️ Checking '$package_json_path' for peerDependencies and importmap dependencies to have the same version"
7179
deps=$(jq -r '.peerDependencies | keys[]' "$package_json_path")
7280
for library in $deps; do

playwright.config.base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* ```typescript
77
* // src/Autocomplete/assets/playwright.config.ts
88
*
9-
* import baseConfig from '../../../../../../playwright.config.base';
9+
* import baseConfig from '../../../playwright.config.base';
1010
*
1111
* export default baseConfig;
1212
* ```

src/Autocomplete/assets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"test": "pnpm run test:unit && pnpm run test:browser",
2121
"test:unit": "../../../bin/test_package.sh . --unit",
2222
"test:browser": "../../../bin/test_package.sh . --browser",
23+
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
2324
"check": "biome check",
2425
"ci": "biome ci"
2526
},

src/Chartjs/assets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"test": "pnpm run test:unit && pnpm run test:browser",
2121
"test:unit": "../../../bin/test_package.sh . --unit",
2222
"test:browser": "../../../bin/test_package.sh . --browser",
23+
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
2324
"check": "biome check",
2425
"ci": "biome ci"
2526
},

src/Cropperjs/assets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"test": "pnpm run test:unit && pnpm run test:browser",
2424
"test:unit": "../../../bin/test_package.sh . --unit",
2525
"test:browser": "../../../bin/test_package.sh . --browser",
26+
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
2627
"check": "biome check",
2728
"ci": "biome ci"
2829
},

src/Dropzone/assets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"test": "pnpm run test:unit && pnpm run test:browser",
2424
"test:unit": "../../../bin/test_package.sh . --unit",
2525
"test:browser": "../../../bin/test_package.sh . --browser",
26+
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
2627
"check": "biome check",
2728
"ci": "biome ci"
2829
},

src/LiveComponent/assets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"test": "pnpm run test:unit && pnpm run test:browser",
2626
"test:unit": "../../../bin/test_package.sh . --unit",
2727
"test:browser": "../../../bin/test_package.sh . --browser",
28+
"test:browser:ui": "../../../bin/test_package.sh . --browser --ui",
2829
"check": "biome check",
2930
"ci": "biome ci"
3031
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"watch": "tsx ../../../../../../bin/build_package.ts . --watch",
2222
"test": "pnpm run test:browser",
2323
"test:browser": "../../../../../../bin/test_package.sh . --browser",
24+
"test:browser:ui": "../../../../../../bin/test_package.sh . --browser --ui",
2425
"check": "biome check",
2526
"ci": "biome ci"
2627
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"watch": "tsx ../../../../../../bin/build_package.ts . --watch",
2222
"test": "pnpm run test:browser",
2323
"test:browser": "../../../../../../bin/test_package.sh . --browser",
24+
"test:browser:ui": "../../../../../../bin/test_package.sh . --browser --ui",
2425
"check": "biome check",
2526
"ci": "biome ci"
2627
},

0 commit comments

Comments
 (0)