Skip to content

Commit 6e911d9

Browse files
committed
[#532] Added support for Functional JS tests.
1 parent b7dc131 commit 6e911d9

126 files changed

Lines changed: 1445 additions & 135 deletions

File tree

Some content is hidden

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

.ahoy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ commands:
274274
test-functional:
275275
usage: Run PHPUnit functional tests.
276276
cmd: ahoy cli vendor/bin/phpunit --testsuite=functional "$@"
277+
278+
test-functional-javascript:
279+
aliases: [test-js]
280+
usage: Run PHPUnit functional JavaScript tests.
281+
cmd: ahoy cli vendor/bin/phpunit --testsuite=functional-javascript "$@"
277282
#;> TOOL_PHPUNIT
278283

279284
#;< TOOL_BEHAT

.docker/cli.dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ ARG VORTEX_FRONTEND_BUILD_SKIP="0"
3939
ENV VORTEX_FRONTEND_BUILD_SKIP=${VORTEX_FRONTEND_BUILD_SKIP}
4040

4141
ENV COMPOSER_ALLOW_SUPERUSER=1 \
42-
COMPOSER_CACHE_DIR=/tmp/.composer/cache \
43-
SIMPLETEST_DB=mysql://drupal:drupal@database/drupal \
44-
SIMPLETEST_BASE_URL=http://nginx:8080 \
45-
SYMFONY_DEPRECATIONS_HELPER=disabled
42+
COMPOSER_CACHE_DIR=/tmp/.composer/cache
4643

4744
# Allow custom PHP runtime configuration for Drush CLI commands.
4845
# The leading colon appends to the default scan directories.

.vortex/.ahoy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ commands:
117117
118118
# If there are changes to the snapshots - this command will re-run twice reporting error the first time.
119119
update-snapshots:
120+
aliases: [us]
120121
cmd: |
121122
export XDEBUG_MODE=off
122123
composer --working-dir=tests update-snapshots
123124
composer --working-dir=installer update-snapshots
124125
125126
update-snapshots-install:
127+
aliases: [usi]
126128
cmd: |
127129
ahoy install
128130
ahoy update-snapshots

.vortex/docs/content/development/phpunit.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Test types supported:
1818
1. **Unit tests** - Test isolated PHP classes without Drupal bootstrap
1919
2. **Kernel tests** - Test with partial Drupal bootstrap (database, services)
2020
3. **Functional tests** - Test with full Drupal bootstrap including browser simulation
21+
4. **Functional JavaScript tests** - Test with full Drupal bootstrap and a real browser (Chrome via Selenium) for JavaScript interactions
2122

2223
## Running tests
2324

@@ -35,6 +36,8 @@ import TabItem from '@theme/TabItem';
3536
ahoy test-kernel
3637
# Run only Functional tests
3738
ahoy test-functional
39+
# Run only Functional JavaScript tests
40+
ahoy test-functional-javascript
3841
# Run specific test file
3942
ahoy test tests/phpunit/ExampleTest.php
4043
# Run tests with filter
@@ -51,6 +54,8 @@ import TabItem from '@theme/TabItem';
5154
docker compose exec cli vendor/bin/phpunit --testsuite=kernel
5255
# Run only Functional tests
5356
docker compose exec cli vendor/bin/phpunit --testsuite=functional
57+
# Run only Functional JavaScript tests
58+
docker compose exec cli vendor/bin/phpunit --testsuite=functional-javascript
5459
# Run specific test file
5560
docker compose exec cli vendor/bin/phpunit tests/phpunit/ExampleTest.php
5661
# Run tests with filter
@@ -66,6 +71,7 @@ PHPUnit tests are organized into test suites defined in `phpunit.xml`:
6671
- **unit** - Fast tests that don't require Drupal bootstrap
6772
- **kernel** - Tests that need database and core services
6873
- **functional** - Full browser simulation tests
74+
- **functional-javascript** - Tests requiring a real browser with JavaScript support (Chrome via Selenium)
6975

7076
## Configuration
7177

@@ -97,7 +103,7 @@ continuous integration to track test performance and stability.
97103

98104
## Boilerplate
99105

100-
**Vortex** provides Unit, Kernel and Functional tests boilerplate for custom [modules](https://github.com/drevops/vortex/blob/main/web/modules/custom/ys_base/tests/src),
106+
**Vortex** provides Unit, Kernel, Functional and Functional JavaScript tests boilerplate for custom [modules](https://github.com/drevops/vortex/blob/main/web/modules/custom/ys_base/tests/src),
101107
[themes](https://github.com/drevops/vortex/blob/main/web/themes/custom/your_site_theme/tests/src) and
102108
[scripts](https://github.com/drevops/vortex/blob/main/tests/phpunit).
103109

.vortex/docs/content/tools/behat.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ default:
7777
- '%paths.base%/web/modules/custom/mymodule/tests/behat/features'
7878
```
7979
80+
### Chrome session flags
81+
82+
The [`behat.yml`](https://github.com/drevops/vortex/blob/main/behat.yml)
83+
configuration passes the following flags to Chrome via `goog:chromeOptions`
84+
to ensure stable and deterministic test execution in the container environment:
85+
86+
| Flag | Purpose |
87+
|----------------------------------|------------------------------------------------------------------|
88+
| `--disable-extensions` | Prevents interference from browser extensions |
89+
| `--disable-translate` | Prevents the translation bar from appearing on non-English pages |
90+
| `--force-prefers-reduced-motion` | Disables CSS animations and transitions for test stability |
91+
| `--test-type` | Suppresses error dialogs and crash recovery prompts |
92+
8093
### Contexts and extensions
8194

8295
The configuration uses the following contexts and extensions:

.vortex/docs/content/tools/phpunit.mdx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ import TabItem from '@theme/TabItem';
2121
ahoy test-unit # Run Unit tests.
2222
ahoy test-kernel # Run Kernel tests.
2323
ahoy test-functional # Run Functional tests.
24+
ahoy test-functional-javascript # Run Functional JavaScript tests.
2425
```
2526
</TabItem>
2627
<TabItem value="docker-compose" label="Docker Compose">
2728
```shell
28-
docker compose exec cli vendor/bin/phpunit # Run all tests.
29-
docker compose exec cli vendor/bin/phpunit --testsuite=unit # Run Unit tests.
30-
docker compose exec cli vendor/bin/phpunit --testsuite=kernel # Run Kernel tests.
31-
docker compose exec cli vendor/bin/phpunit --testsuite=functional # Run Functional tests.
29+
docker compose exec cli vendor/bin/phpunit # Run all tests.
30+
docker compose exec cli vendor/bin/phpunit --testsuite=unit # Run Unit tests.
31+
docker compose exec cli vendor/bin/phpunit --testsuite=kernel # Run Kernel tests.
32+
docker compose exec cli vendor/bin/phpunit --testsuite=functional # Run Functional tests.
33+
docker compose exec cli vendor/bin/phpunit --testsuite=functional-javascript # Run Functional JavaScript tests.
3234
```
3335
</TabItem>
3436
</Tabs>
@@ -102,6 +104,34 @@ Run checks against platform version specified in `composer.json` key `config.pla
102104
<config name="testVersion" value="8.1"/>
103105
```
104106

107+
### Chrome session flags
108+
109+
Functional JavaScript tests use a Chrome browser running in the
110+
[`selenium/standalone-chromium`](https://hub.docker.com/r/selenium/standalone-chromium)
111+
container. The following flags are passed via `MINK_DRIVER_ARGS_WEBDRIVER`
112+
in `phpunit.xml` to ensure stable and deterministic test execution:
113+
114+
| Flag | Purpose |
115+
|----------------------------------|------------------------------------------------------------------|
116+
| `--disable-extensions` | Prevents interference from browser extensions |
117+
| `--disable-translate` | Prevents the translation bar from appearing on non-English pages |
118+
| `--force-prefers-reduced-motion` | Disables CSS animations and transitions for test stability |
119+
| `--test-type` | Suppresses error dialogs and crash recovery prompts |
120+
| `--window-size=1920,1080` | Sets a deterministic viewport size for consistent screenshots |
121+
122+
The `w3c: true` option is required for compatibility with Selenium 4.
123+
124+
### Bootstrap
125+
126+
The custom [`tests/phpunit/bootstrap.php`](https://github.com/drevops/vortex/blob/main/tests/phpunit/bootstrap.php)
127+
file runs before tests to:
128+
129+
1. Set `BROWSERTEST_OUTPUT_BASE_URL` from the `VORTEX_LOCALDEV_URL` environment
130+
variable so that HTML output links are accessible from the host machine.
131+
2. Create the `web/sites/simpletest/browser_output` directory required by the
132+
`HtmlOutputLogger` extension before it initializes
133+
(see [Drupal core issue #2992069](https://www.drupal.org/project/drupal/issues/2992069)).
134+
105135
## Coverage
106136

107137
PHPUnit is configured to generate code coverage reports. The reports are stored

.vortex/docs/cspell.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
],
99
"words": [
1010
"Asciinema",
11+
"BROWSERTEST",
1112
"Buildx",
1213
"Diffy",
1314
"GHSA",
@@ -19,8 +20,8 @@
1920
"acquia",
2021
"amazee",
2122
"amazeeio",
22-
"automations",
2323
"apikey",
24+
"automations",
2425
"behat",
2526
"bootstrappable",
2627
"calver",
@@ -73,6 +74,7 @@
7374
"runsheets",
7475
"seckit",
7576
"shellvar",
77+
"simpletest",
7678
"standardise",
7779
"updatedb",
7880
"uselagoon",

.vortex/installer/src/Prompts/Handlers/Theme.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ protected function removeThemeConfigLines(string $tmpDir): void {
207207
File::removeLineInFile($tmpDir . '/phpunit.xml', '<directory>web/themes/custom/**/tests/src/Kernel</directory>');
208208
File::removeLineInFile($tmpDir . '/phpunit.xml', '<directory>web/themes/custom/*/tests/src/Functional</directory>');
209209
File::removeLineInFile($tmpDir . '/phpunit.xml', '<directory>web/themes/custom/**/tests/src/Functional</directory>');
210+
File::removeLineInFile($tmpDir . '/phpunit.xml', '<directory>web/themes/custom/*/tests/src/FunctionalJavascript</directory>');
211+
File::removeLineInFile($tmpDir . '/phpunit.xml', '<directory>web/themes/custom/**/tests/src/FunctionalJavascript</directory>');
210212
File::removeLineInFile($tmpDir . '/phpunit.xml', '<directory>web/themes/custom</directory>');
211213
File::removeLineInFile($tmpDir . '/phpunit.xml', '<directory suffix="Test.php">web/themes/custom</directory>');
212214
File::removeLineInFile($tmpDir . '/phpunit.xml', '<directory>web/themes/custom/*/node_modules</directory>');

.vortex/installer/tests/Fixtures/handler_process/_baseline/.ahoy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ commands:
235235
usage: Run PHPUnit functional tests.
236236
cmd: ahoy cli vendor/bin/phpunit --testsuite=functional "$@"
237237

238+
test-functional-javascript:
239+
aliases: [test-js]
240+
usage: Run PHPUnit functional JavaScript tests.
241+
cmd: ahoy cli vendor/bin/phpunit --testsuite=functional-javascript "$@"
242+
238243
test-bdd:
239244
usage: Run BDD tests.
240245
aliases: [test-behat]

.vortex/installer/tests/Fixtures/handler_process/_baseline/.docker/cli.dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ ARG VORTEX_FRONTEND_BUILD_SKIP="0"
3939
ENV VORTEX_FRONTEND_BUILD_SKIP=${VORTEX_FRONTEND_BUILD_SKIP}
4040

4141
ENV COMPOSER_ALLOW_SUPERUSER=1 \
42-
COMPOSER_CACHE_DIR=/tmp/.composer/cache \
43-
SIMPLETEST_DB=mysql://drupal:drupal@database/drupal \
44-
SIMPLETEST_BASE_URL=http://nginx:8080 \
45-
SYMFONY_DEPRECATIONS_HELPER=disabled
42+
COMPOSER_CACHE_DIR=/tmp/.composer/cache
4643

4744
# Allow custom PHP runtime configuration for Drush CLI commands.
4845
# The leading colon appends to the default scan directories.

0 commit comments

Comments
 (0)