From e5b845f88132f3996454e04b4c3d34b49ffc1657 Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 25 Oct 2026 20:50:31 +0000 Subject: [PATCH] fix: update Playwright configuration and documentation for improved E2E testing setup --- .github/workflows/test.yml | 17 +++-------------- .gitignore | 6 ++++-- CONTRIBUTING.md | 2 +- TESTING.md | 16 +++++++++------- composer.json | 2 +- composer.lock | 27 ++++++++++++++------------- playwright.config.ts | 16 ++++++++++++---- 7 files changed, 44 insertions(+), 42 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0733a6b0..14c361e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,23 +68,12 @@ jobs: - name: Install Playwright run: npx playwright install chromium --with-deps - - name: Start Laravel server - run: php artisan serve --host=0.0.0.0 --port=8000 & - env: - APP_ENV: testing - - - name: Wait for server - run: | - timeout 30 bash -c 'until curl -f http://localhost:8000 > /dev/null 2>&1; do - echo "Waiting for Laravel server..." - sleep 2 - done' - echo "Server is ready!" + # Playwright starts the server itself (laravelServer() in playwright.config.ts). + - name: Prepare E2E environment + run: php artisan playwright:env --force - name: Run E2E tests run: npm run test:e2e - env: - APP_URL: http://localhost:8000 - name: Upload test report if: failure() diff --git a/.gitignore b/.gitignore index 476816d6..ea2b1ca7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ *.log .DS_Store .env -.env.backup -.env.production +.env.* +!.env.*.example +!.env.example .phpactor.json .phpunit.result.cache /.fleet @@ -73,6 +74,7 @@ public/vendor/livewire/ /playwright/ /test-results/ /playwright-report/ +/storage/framework/playwright/ /playwright/.cache/ /playwright-mcp/ /.playwright-mcp/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8f93e1e2..d61d854b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -273,7 +273,7 @@ composer analyse # Larastan/PHPStan level 5 composer lint # Laravel Pint npm run lint # ESLint, fixes files in place npm run format:check -npm run test:e2e # wipes your app's database +npm run test:e2e # own server and database (.env.e2e) npm run build ``` diff --git a/TESTING.md b/TESTING.md index 9a279826..2ae32708 100644 --- a/TESTING.md +++ b/TESTING.md @@ -15,8 +15,8 @@ Set up the repository first, as described in [CONTRIBUTING.md](CONTRIBUTING.md). - PHPUnit runs on SQLite in memory (`phpunit.xml`). It never needs your app's database. -- End-to-end tests are the exception: they run against the real app and reset - its database. See [End-to-end tests](#end-to-end-tests-playwright). +- End-to-end tests run on their own server and SQLite database (`.env.e2e`), so + they never touch your app's data. See [End-to-end tests](#end-to-end-tests-playwright). - Pick the test for the change: | Change | Test | @@ -79,19 +79,21 @@ npm run test:unit ## End-to-end tests (Playwright) -> [!CAUTION] -> The setup project runs `migrate:fresh` and the seeders against the database in -> `.env`. It **wipes your local app data** on every run. +The suite runs on its own server and database, from `.env.e2e`: a copy of `.env` +with `APP_ENV=e2e`, `APP_URL=http://localhost:8100` and SQLite +`database/e2e.sqlite`. Playwright starts that server itself (`laravelServer()` in +`playwright.config.ts`) and migrates its database, so your app and its data stay +untouched, however you serve them. ```bash +php artisan playwright:env # first run only: writes .env.e2e from .env npx playwright install # first run only npm run test:e2e # everything npx playwright test --project="@auth*" # one module npm run test:e2e:ui # pick and watch tests ``` -- The app must be served at `APP_URL` (Herd: `https://.test`). Outside - CI, the assets are rebuilt before the run. +- Outside CI, the assets are rebuilt before the run. - Each module ships its specs in `modules//tests/e2e`, registered as a `@` project. - Select elements by `data-testid`, never by translated text. diff --git a/composer.json b/composer.json index d91641d0..e4d6698c 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "mockery/mockery": "^1.6.15", "nunomaduro/collision": "^8.9.5", "phpunit/phpunit": "^13.4.3", - "saucebase/laravel-playwright": "^1.1" + "saucebase/laravel-playwright": "^2.1" }, "suggest": { "saucebase/announcements": "Site-wide announcement banners with scheduling, audience targeting, and cookie-based dismissal", diff --git a/composer.lock b/composer.lock index 9281db06..0f4a3a61 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b12c322c6addb8f8fc1126de5e32822e", + "content-hash": "7b9972500e7557a56c020dcda73858bb", "packages": [ { "name": "anourvalar/eloquent-serialize", @@ -7046,16 +7046,16 @@ }, { "name": "saucebase/core", - "version": "v2.0.2", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/saucebase-dev/core.git", - "reference": "bafcde878bc4851fb48de25bf979af20c09d9244" + "reference": "920c60c7508e70d6b7d3c3ec1fabff6dd3f36c6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/saucebase-dev/core/zipball/bafcde878bc4851fb48de25bf979af20c09d9244", - "reference": "bafcde878bc4851fb48de25bf979af20c09d9244", + "url": "https://api.github.com/repos/saucebase-dev/core/zipball/920c60c7508e70d6b7d3c3ec1fabff6dd3f36c6a", + "reference": "920c60c7508e70d6b7d3c3ec1fabff6dd3f36c6a", "shasum": "" }, "require": { @@ -7127,9 +7127,9 @@ ], "support": { "issues": "https://github.com/saucebase-dev/core/issues", - "source": "https://github.com/saucebase-dev/core/tree/v2.0.2" + "source": "https://github.com/saucebase-dev/core/tree/v2.5.0" }, - "time": "2026-10-23T20:54:46+00:00" + "time": "2026-10-25T20:36:55+00:00" }, { "name": "saucebase/module-installer", @@ -13968,24 +13968,25 @@ }, { "name": "saucebase/laravel-playwright", - "version": "v1.1.0", + "version": "v2.1.0", "source": { "type": "git", "url": "https://github.com/saucebase-dev/laravel-playwright.git", - "reference": "471614ecad25e5c0e960bd5bb7aff9f37cba2cf6" + "reference": "766eafcecd55d4135ca7487be47d40ab852bb4e6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/saucebase-dev/laravel-playwright/zipball/471614ecad25e5c0e960bd5bb7aff9f37cba2cf6", - "reference": "471614ecad25e5c0e960bd5bb7aff9f37cba2cf6", + "url": "https://api.github.com/repos/saucebase-dev/laravel-playwright/zipball/766eafcecd55d4135ca7487be47d40ab852bb4e6", + "reference": "766eafcecd55d4135ca7487be47d40ab852bb4e6", "shasum": "" }, "require": { + "illuminate/support": "^12.0|^13.0", "php": ">=8.3" }, "require-dev": { "larastan/larastan": "^3.0", - "orchestra/testbench": "^11.0", + "orchestra/testbench": "^10.0|^11.0", "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^11.0" }, @@ -14028,7 +14029,7 @@ "issues": "https://github.com/sauce-base/laravel-playwright/issues", "source": "https://github.com/sauce-base/laravel-playwright" }, - "time": "2026-03-20T20:02:20+00:00" + "time": "2026-10-25T20:18:44+00:00" }, { "name": "sebastian/cli-parser", diff --git a/playwright.config.ts b/playwright.config.ts index 2827434b..9db64622 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,10 +1,15 @@ /// import { defineConfig, devices } from '@playwright/test'; -import type { LaravelOptions } from '@saucebase/laravel-playwright'; -import 'dotenv/config'; +import { laravelServer, type LaravelOptions } from '@saucebase/laravel-playwright'; +import { config } from 'dotenv'; import { saucebaseProjects } from './vendor/saucebase/core/resources/js/modules.ts'; -const BASE_URL = process.env.APP_URL ?? 'http://localhost'; +// The suite runs on its own server and database, never the app's (.env.e2e). +// Loading .env here instead would hand that server your database. +const e2e = config({ path: '.env.e2e', quiet: true }).parsed ?? {}; +// From the file, not process.env: an APP_URL exported for the dev app would win there, +// and the suite would test it while laravelServer() serves .env.e2e's. +const BASE_URL = e2e.APP_URL ?? 'http://localhost:8100'; async function createConfig() { // database.setup, every module's setups and projects, per device, in order. @@ -56,12 +61,15 @@ async function createConfig() { /** Laravel Playwright integration */ laravelBaseUrl: `${BASE_URL}/playwright`, - laravelSecret: process.env.PLAYWRIGHT_SECRET, + laravelSecret: e2e.PLAYWRIGHT_SECRET, }, /* Configure projects for major browsers */ projects, + /* Migrates .env.e2e's database, then serves it on APP_URL's port. */ + webServer: laravelServer(), + /** * Tests run against built assets, the way CI does. *