Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/views/before-each.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

beforeEach(function () {
//
});
})->group('filament-tests');
4 changes: 4 additions & 0 deletions src/Commands/FilamentTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}';

Expand All @@ -51,6 +54,7 @@ public function handle(): void
$this->generateTests();
$this->showGenerationSummary();
$this->runPintOnGeneratedTests();
$this->runPestOnGeneratedTests();
}

/**
Expand Down
29 changes: 29 additions & 0 deletions src/Concerns/Commands/InteractsWithFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use function Laravel\Prompts\confirm;
use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;

trait InteractsWithFilesystem
{
Expand Down Expand Up @@ -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');
}
}
}