From 11a66fab6f3ee799eb064ba86eeed32fa7f2fe3b Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 25 Oct 2026 20:25:10 +0000 Subject: [PATCH 1/3] feat: enhance Laravel Playwright module and tests for improved E2E environment setup --- .github/workflows/run-tests.yml | 17 +++-------------- .github/workflows/test-module.yml | 18 ++++-------------- src/Console/Commands/InstallCommand.php | 5 +++++ stubs/app/README.md | 2 +- stubs/app/playwright.config.ts | 13 ++++++++++--- stubs/stack/react/config/package.json | 2 +- stubs/stack/vue/config/package.json | 2 +- tests/Feature/InstallCommandTest.php | 18 +++++++++++++++++- 8 files changed, 42 insertions(+), 35 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b9e840c..1bb53bd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -136,21 +136,10 @@ jobs: timeout-minutes: 2 run: ./node_modules/.bin/playwright install chromium --with-deps - - name: Start Laravel server + # Playwright serves .env.e2e itself (laravelServer() in playwright.config.ts). + - name: Prepare the E2E environment working-directory: app - run: php artisan serve --host=0.0.0.0 --port=8000 & - - - name: Wait for server - run: | - for _ in $(seq 15); do - if curl -fs localhost:8000 > /dev/null; then - echo "Server is ready!" - exit 0 - fi - echo 'Waiting for server...' - sleep 2 - done - exit 1 + run: php artisan playwright:env --url=http://localhost:8000 --force - name: Execute core's browser tests working-directory: app diff --git a/.github/workflows/test-module.yml b/.github/workflows/test-module.yml index 50b80dc..99d4683 100644 --- a/.github/workflows/test-module.yml +++ b/.github/workflows/test-module.yml @@ -178,9 +178,12 @@ jobs: E2E_SETUP: ${{ inputs.e2e_setup }} run: bash -euo pipefail -c "$E2E_SETUP" - - name: Start Laravel server + # After the variant's setup, which may write to .env: .env.e2e is a copy of it. + # Playwright then serves it itself (laravelServer() in playwright.config.ts). + - name: Prepare the E2E environment working-directory: app run: | + php artisan playwright:env --url="$APP_URL" --force # Ports below 1024 are privileged by default. Lower the threshold # rather than serving as root, so the app never writes root-owned # logs, sessions, or SQLite files. Already root (act, containers) @@ -188,19 +191,6 @@ jobs: if [ "$SERVE_PORT" -lt 1024 ] && [ "$(id -u)" -ne 0 ]; then sudo sysctl -w "net.ipv4.ip_unprivileged_port_start=$SERVE_PORT" fi - php artisan serve --host=0.0.0.0 --port="$SERVE_PORT" & - - - name: Wait for server - run: | - for _ in $(seq 15); do - if curl -fs "localhost:$SERVE_PORT" > /dev/null; then - echo "Server is ready!" - exit 0 - fi - echo 'Waiting for server...' - sleep 2 - done - exit 1 - name: Run E2E tests working-directory: app diff --git a/src/Console/Commands/InstallCommand.php b/src/Console/Commands/InstallCommand.php index 28b3456..15da6f5 100644 --- a/src/Console/Commands/InstallCommand.php +++ b/src/Console/Commands/InstallCommand.php @@ -37,6 +37,11 @@ class InstallCommand extends Command '/bootstrap/ssr', '/playwright-report', '/test-results', + '/storage/framework/playwright', + // Every env file, the E2E suite's `.env.e2e` included, but the examples. + '.env.*', + '!.env.*.example', + '!.env.example', '/public/css/filament', '/public/js/filament', '/public/fonts/filament', diff --git a/stubs/app/README.md b/stubs/app/README.md index aea640b..d0d0318 100644 --- a/stubs/app/README.md +++ b/stubs/app/README.md @@ -40,7 +40,7 @@ php artisan test # PHPUnit npm run test:e2e # Playwright ``` -**`npm run test:e2e` resets the database in `.env`.** Run it on an app whose data you can lose. +**`npm run test:e2e` runs on its own server and database**, from `.env.e2e`, so your app's data stays untouched. Create the file once with `php artisan playwright:env` (a copy of `.env` with its own SQLite database and port). ## Learn more diff --git a/stubs/app/playwright.config.ts b/stubs/app/playwright.config.ts index 3a4a018..f219351 100644 --- a/stubs/app/playwright.config.ts +++ b/stubs/app/playwright.config.ts @@ -1,10 +1,14 @@ /// 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, written +// by `php artisan playwright:env`. Loading .env here instead would hand that server +// your database. +config({ path: '.env.e2e', quiet: true }); +const BASE_URL = process.env.APP_URL ?? 'http://localhost:8100'; async function createConfig() { // database.setup, every module's setups and projects, per device, in order. @@ -62,6 +66,9 @@ async function createConfig() { /* 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. * diff --git a/stubs/stack/react/config/package.json b/stubs/stack/react/config/package.json index 8a94fc5..509654b 100644 --- a/stubs/stack/react/config/package.json +++ b/stubs/stack/react/config/package.json @@ -36,7 +36,7 @@ "@inertiajs/react": "^3.9.1", "@inertiajs/vite": "^3.9.1", "@playwright/test": "^1.64.1", - "@saucebase/laravel-playwright": "^1.0", + "@saucebase/laravel-playwright": "^2.0.1", "@svgr/core": "^8.1.0", "@svgr/plugin-jsx": "^8.1.0", "@tailwindcss/forms": "^0.5.11", diff --git a/stubs/stack/vue/config/package.json b/stubs/stack/vue/config/package.json index e04dd78..f96d010 100644 --- a/stubs/stack/vue/config/package.json +++ b/stubs/stack/vue/config/package.json @@ -36,7 +36,7 @@ "@inertiajs/vite": "^3.9.1", "@inertiajs/vue3": "^3.9.1", "@playwright/test": "^1.64.1", - "@saucebase/laravel-playwright": "^1.0", + "@saucebase/laravel-playwright": "^2.0.1", "@tailwindcss/forms": "^0.5.11", "@tailwindcss/typography": "^0.5.20", "@tailwindcss/vite": "^4.3.3", diff --git a/tests/Feature/InstallCommandTest.php b/tests/Feature/InstallCommandTest.php index d8c26e7..7670b3b 100644 --- a/tests/Feature/InstallCommandTest.php +++ b/tests/Feature/InstallCommandTest.php @@ -294,11 +294,27 @@ public function test_it_ignores_the_files_saucebase_generates(): void // Laravel's own lines stay. $this->assertStringStartsWith("/vendor\n/public/build\n", $ignored); - foreach (['/bootstrap/ssr', '/playwright-report', '/test-results', '/public/css/filament', '/public/js/filament', '/public/fonts/filament'] as $path) { + foreach (['/bootstrap/ssr', '/playwright-report', '/test-results', '/storage/framework/playwright', '/public/css/filament', '/public/js/filament', '/public/fonts/filament'] as $path) { $this->assertStringContainsString("\n{$path}\n", $ignored); } } + /** `.env.e2e` (the E2E suite's own env) and any other env file, but never an example. */ + public function test_it_ignores_every_env_file_but_the_examples(): void + { + $this->files->put($this->appPath.'/.gitignore', "/vendor\n.env\n.env.backup\n"); + + $this->artisan('saucebase:install', ['framework' => 'vue', '--force' => true])->assertSuccessful(); + + $ignored = $this->read('.gitignore'); + $envs = strpos($ignored, "\n.env.*\n"); + + $this->assertNotFalse($envs); + // Negations only work after the pattern they undo. + $this->assertGreaterThan($envs, strpos($ignored, "\n!.env.*.example\n")); + $this->assertGreaterThan($envs, strpos($ignored, "\n!.env.example\n")); + } + public function test_it_does_not_ignore_a_path_twice(): void { $this->files->put($this->appPath.'/.gitignore', "/vendor\n/bootstrap/ssr\n"); From 5fcae4b560d742b32148b1c645d85b6bef4aff8f Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 25 Oct 2026 20:31:49 +0000 Subject: [PATCH 2/3] feat: update E2E environment setup and README assertions in tests --- .github/workflows/test-module.yml | 1 + tests/Feature/InstallCommandTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-module.yml b/.github/workflows/test-module.yml index 99d4683..e2b628c 100644 --- a/.github/workflows/test-module.yml +++ b/.github/workflows/test-module.yml @@ -183,6 +183,7 @@ jobs: - name: Prepare the E2E environment working-directory: app run: | + # localhost inside the runner, and artisan serve has no TLS. php artisan playwright:env --url="$APP_URL" --force # Ports below 1024 are privileged by default. Lower the threshold # rather than serving as root, so the app never writes root-owned diff --git a/tests/Feature/InstallCommandTest.php b/tests/Feature/InstallCommandTest.php index 7670b3b..db3740c 100644 --- a/tests/Feature/InstallCommandTest.php +++ b/tests/Feature/InstallCommandTest.php @@ -57,7 +57,7 @@ public function test_it_replaces_laravels_readme_with_one_for_saucebase(): void $readme = $this->read('README.md'); $this->assertStringContainsString('php artisan saucebase:module-install', $readme); $this->assertStringContainsString('docker compose exec app php artisan', $readme); - $this->assertStringContainsString('resets the database', $readme); + $this->assertStringContainsString('php artisan playwright:env', $readme); } public function test_the_published_user_factory_never_repeats_an_email_across_requests(): void From 6f907ebf3389ffa9ba70f6af8d8d22f7938f2957 Mon Sep 17 00:00:00 2001 From: roble Date: Sun, 25 Oct 2026 20:34:17 +0000 Subject: [PATCH 3/3] feat: update Laravel Playwright module to version 2.1.0 and refactor configuration for improved environment handling --- stubs/app/playwright.config.ts | 8 +++++--- stubs/stack/react/config/package-lock.json | 8 ++++---- stubs/stack/vue/config/package-lock.json | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/stubs/app/playwright.config.ts b/stubs/app/playwright.config.ts index f219351..8e226af 100644 --- a/stubs/app/playwright.config.ts +++ b/stubs/app/playwright.config.ts @@ -7,8 +7,10 @@ import { saucebaseProjects } from './vendor/saucebase/core/resources/js/modules. // The suite runs on its own server and database, never the app's: .env.e2e, written // by `php artisan playwright:env`. Loading .env here instead would hand that server // your database. -config({ path: '.env.e2e', quiet: true }); -const BASE_URL = process.env.APP_URL ?? 'http://localhost:8100'; +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. @@ -60,7 +62,7 @@ async function createConfig() { /** Laravel Playwright integration */ laravelBaseUrl: `${BASE_URL}/playwright`, - laravelSecret: process.env.PLAYWRIGHT_SECRET, + laravelSecret: e2e.PLAYWRIGHT_SECRET, }, /* Configure projects for major browsers */ diff --git a/stubs/stack/react/config/package-lock.json b/stubs/stack/react/config/package-lock.json index 2f41479..dcd596b 100644 --- a/stubs/stack/react/config/package-lock.json +++ b/stubs/stack/react/config/package-lock.json @@ -35,7 +35,7 @@ "@inertiajs/react": "^3.9.1", "@inertiajs/vite": "^3.9.1", "@playwright/test": "^1.64.1", - "@saucebase/laravel-playwright": "^1.0", + "@saucebase/laravel-playwright": "^2.0.1", "@svgr/core": "^8.1.0", "@svgr/plugin-jsx": "^8.1.0", "@tailwindcss/forms": "^0.5.11", @@ -3998,9 +3998,9 @@ } }, "node_modules/@saucebase/laravel-playwright": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@saucebase/laravel-playwright/-/laravel-playwright-1.0.0.tgz", - "integrity": "sha512-zMO31P4ssto7W7T0PaGyQMsQO0nFmEgHjBUJtetCu3kkTF9ZP438VzzWikEfn1x5EIiPMBrA6aTn63HXf5oMsw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@saucebase/laravel-playwright/-/laravel-playwright-2.1.0.tgz", + "integrity": "sha512-4sK2sUIwbS8vKz7FaL+Xw5AeSUFz79WXJ4BdBNj4LJDxUMH1dCB85P+S61vrVn1FpEdSmOdyqqxbvsEZK5eVWw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/stubs/stack/vue/config/package-lock.json b/stubs/stack/vue/config/package-lock.json index f51f785..6297f5e 100644 --- a/stubs/stack/vue/config/package-lock.json +++ b/stubs/stack/vue/config/package-lock.json @@ -35,7 +35,7 @@ "@inertiajs/vite": "^3.9.1", "@inertiajs/vue3": "^3.9.1", "@playwright/test": "^1.64.1", - "@saucebase/laravel-playwright": "^1.0", + "@saucebase/laravel-playwright": "^2.0.1", "@tailwindcss/forms": "^0.5.11", "@tailwindcss/typography": "^0.5.20", "@tailwindcss/vite": "^4.3.3", @@ -2381,9 +2381,9 @@ } }, "node_modules/@saucebase/laravel-playwright": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@saucebase/laravel-playwright/-/laravel-playwright-1.0.0.tgz", - "integrity": "sha512-zMO31P4ssto7W7T0PaGyQMsQO0nFmEgHjBUJtetCu3kkTF9ZP438VzzWikEfn1x5EIiPMBrA6aTn63HXf5oMsw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@saucebase/laravel-playwright/-/laravel-playwright-2.1.0.tgz", + "integrity": "sha512-4sK2sUIwbS8vKz7FaL+Xw5AeSUFz79WXJ4BdBNj4LJDxUMH1dCB85P+S61vrVn1FpEdSmOdyqqxbvsEZK5eVWw==", "dev": true, "license": "MIT", "dependencies": {