From 629a121a02efc7cd78973f377c3bc46b32143555 Mon Sep 17 00:00:00 2001 From: dissto <11778632+dissto@users.noreply.github.com> Date: Tue, 9 Sep 2025 21:40:08 +0200 Subject: [PATCH 1/3] Add option to run Pest on generated test files --- resources/views/before-each.blade.php | 2 +- src/Commands/FilamentTestsCommand.php | 4 +++ .../Commands/InteractsWithFilesystem.php | 29 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/resources/views/before-each.blade.php b/resources/views/before-each.blade.php index e988951f..f5d562fc 100644 --- a/resources/views/before-each.blade.php +++ b/resources/views/before-each.blade.php @@ -2,4 +2,4 @@ beforeEach(function () { // -}); +})->group('filament-tests'); diff --git a/src/Commands/FilamentTestsCommand.php b/src/Commands/FilamentTestsCommand.php index 25a2862a..b6e72540 100644 --- a/src/Commands/FilamentTestsCommand.php +++ b/src/Commands/FilamentTestsCommand.php @@ -24,6 +24,7 @@ use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\HidesColumnTest; use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\Index\ShowsColumnTest; use CodeWithDennis\FilamentTests\TestRenderers\Resources\Pages\View\CanRenderViewPageTest; +use Filament\Support\Commands\Concerns\CanOpenUrlInBrowser; use Illuminate\Console\Command; use Illuminate\Support\Collection; @@ -33,10 +34,12 @@ class FilamentTestsCommand extends Command protected Collection $resources; + use CanOpenUrlInBrowser; use InteractsWithFilesystem; use InteractsWithUserInput; protected $signature = 'make:filament-test + {--skip-pest : Skip running Pest on generated files} {--skip-pint : Skip running Pint on generated files} {--force : Overwrite existing test files without confirmation}'; @@ -50,6 +53,7 @@ public function handle(): void $this->generateTests(); $this->showGenerationSummary(); $this->runPintOnGeneratedTests(); + $this->runPestOnGeneratedTests(); } /** diff --git a/src/Concerns/Commands/InteractsWithFilesystem.php b/src/Concerns/Commands/InteractsWithFilesystem.php index c67258ff..76bf75e0 100644 --- a/src/Concerns/Commands/InteractsWithFilesystem.php +++ b/src/Concerns/Commands/InteractsWithFilesystem.php @@ -8,6 +8,7 @@ use function Laravel\Prompts\confirm; use function Laravel\Prompts\info; +use function Laravel\Prompts\spin; use function Laravel\Prompts\table; use function Laravel\Prompts\warning; @@ -122,4 +123,32 @@ protected function showGenerationSummary(): void $rows ); } + + protected function runPestOnGeneratedTests(): void + { + if ($this->getGeneratedFiles() === [] || $this->option('skip-pest')) { + return; + } + + if (! confirm( + label: 'Would you like to run Pest on the generated test files?', + hint: 'You can always run Pest later by executing `vendor/bin/pest --group=filament-tests`', + )) { + return; + } + + $result = spin( + callback: fn () => \Illuminate\Support\Facades\Process::run('vendor/bin/pest --colors=always --group=filament-tests'), + message: 'Running Pest tests...' + ); + + echo $result->output(); + + if (confirm($result->successful() + ? "Looks like the tests passed! That's great. Would you like to star the repo on GitHub ⭐️" + : "Looks like some tests failed. But hey, that's a good thing! 🥳 Please consider starring the repo on GitHub ⭐ after you’ve reviewed the test results." + )) { + $this->openUrlInBrowser('https://www.github.com/CodeWithDennis/filament-tests'); + } + } } From f7e161d61f70a6116a007a6bf09c72578d0c51b9 Mon Sep 17 00:00:00 2001 From: dissto <11778632+dissto@users.noreply.github.com> Date: Tue, 9 Sep 2025 21:41:33 +0200 Subject: [PATCH 2/3] Fix punctuation in success message for test results --- src/Concerns/Commands/InteractsWithFilesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Concerns/Commands/InteractsWithFilesystem.php b/src/Concerns/Commands/InteractsWithFilesystem.php index 76bf75e0..ea7e1e3e 100644 --- a/src/Concerns/Commands/InteractsWithFilesystem.php +++ b/src/Concerns/Commands/InteractsWithFilesystem.php @@ -145,7 +145,7 @@ protected function runPestOnGeneratedTests(): void echo $result->output(); if (confirm($result->successful() - ? "Looks like the tests passed! That's great. Would you like to star the repo on GitHub ⭐️" + ? "Looks like the tests passed! That's great. Would you like to star the repo on GitHub ⭐️?" : "Looks like some tests failed. But hey, that's a good thing! 🥳 Please consider starring the repo on GitHub ⭐ after you’ve reviewed the test results." )) { $this->openUrlInBrowser('https://www.github.com/CodeWithDennis/filament-tests'); From 95b3375183a4ae6d0d989d000ebf7807c14c7fe3 Mon Sep 17 00:00:00 2001 From: dissto <11778632+dissto@users.noreply.github.com> Date: Wed, 10 Sep 2025 13:12:41 +0200 Subject: [PATCH 3/3] pint --- src/Concerns/Commands/InteractsWithFilesystem.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Concerns/Commands/InteractsWithFilesystem.php b/src/Concerns/Commands/InteractsWithFilesystem.php index e6aed7ac..f33a66a8 100644 --- a/src/Concerns/Commands/InteractsWithFilesystem.php +++ b/src/Concerns/Commands/InteractsWithFilesystem.php @@ -9,8 +9,6 @@ use function Laravel\Prompts\confirm; use function Laravel\Prompts\info; use function Laravel\Prompts\spin; -use function Laravel\Prompts\table; -use function Laravel\Prompts\warning; trait InteractsWithFilesystem {