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 2b369cab..a5f88132 100644 --- a/src/Commands/FilamentTestsCommand.php +++ b/src/Commands/FilamentTestsCommand.php @@ -25,6 +25,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; @@ -34,10 +35,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}'; @@ -51,6 +54,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 f144fa9f..f33a66a8 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; trait InteractsWithFilesystem { @@ -172,4 +173,32 @@ protected function displayResourceSummary(string $resource, string $panelId, int $this->components->twoColumnDetail($resourceDisplay, $statusDisplay); } + + 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'); + } + } }