From cc59ba9172c9f1b070c9254960b98050218a1355 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 22 Mar 2021 16:48:44 +0800 Subject: [PATCH 1/4] [6.x] Add `purge` console command Signed-off-by: Mior Muhammad Zaki --- src/Console/PurgeCommand.php | 121 +++++++++++++++++++++++++++++++++++ src/DuskServiceProvider.php | 1 + 2 files changed, 122 insertions(+) create mode 100644 src/Console/PurgeCommand.php diff --git a/src/Console/PurgeCommand.php b/src/Console/PurgeCommand.php new file mode 100644 index 000000000..497a25fb0 --- /dev/null +++ b/src/Console/PurgeCommand.php @@ -0,0 +1,121 @@ +ignoreValidationErrors(); + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $this->purgeScreenshots(); + + $this->purgeConsoleLogs(); + + $this->purgeSourceLogs(); + } + + /** + * Purge the failure screenshots. + * + * @return void + */ + protected function purgeScreenshots() + { + $this->purgeDebuggingFiles( + 'tests/Browser/screenshots', 'failure-*' + ); + } + + /** + * Purge the console logs. + * + * @return void + */ + protected function purgeConsoleLogs() + { + $this->purgeDebuggingFiles( + 'tests/Browser/console', '*.log' + ); + } + + /** + * Purge the source logs. + * + * @return void + */ + protected function purgeSourceLogs() + { + $this->purgeDebuggingFiles( + 'tests/Browser/source', '*.txt' + ); + } + + /** + * Purge debugging files based on path and patterns. + * + * @param string $relativePath + * @param string $patterns + * @return void + */ + protected function purgeDebuggingFiles($relativePath, $patterns) + { + $path = base_path($relativePath); + + if (! is_dir($path)) { + $this->warn( + "Ignored purging none existing [{$relativePath}] path.", OutputInterface::VERBOSITY_DEBUG + ); + + return; + } + + $files = Finder::create()->files() + ->in($path) + ->name($patterns); + + foreach ($files as $file) { + @unlink($file->getRealPath()); + } + + $this->info("Purged \"{$patterns}\" from [{$relativePath}] path."); + } +} diff --git a/src/DuskServiceProvider.php b/src/DuskServiceProvider.php index 60d36c91e..263994fb8 100644 --- a/src/DuskServiceProvider.php +++ b/src/DuskServiceProvider.php @@ -44,6 +44,7 @@ public function boot() Console\DuskFailsCommand::class, Console\MakeCommand::class, Console\PageCommand::class, + Console\PurgeCommand::class, Console\ComponentCommand::class, Console\ChromeDriverCommand::class, ]); From 4fee85c1477e65942e6abb02f0d4be91d13bfd95 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 23 Mar 2021 06:41:41 +0800 Subject: [PATCH 2/4] Fixes CS Signed-off-by: Mior Muhammad Zaki --- src/Console/PurgeCommand.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Console/PurgeCommand.php b/src/Console/PurgeCommand.php index 497a25fb0..ec71d1b41 100644 --- a/src/Console/PurgeCommand.php +++ b/src/Console/PurgeCommand.php @@ -2,14 +2,9 @@ namespace Laravel\Dusk\Console; -use Dotenv\Dotenv; use Illuminate\Console\Command; -use Illuminate\Support\Str; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Finder\Finder; -use Symfony\Component\Process\Exception\ProcessSignaledException; -use Symfony\Component\Process\Exception\RuntimeException; -use Symfony\Component\Process\Process; class PurgeCommand extends Command { From c03e86448e43d1d4a7760ad0e363f8696c65e734 Mon Sep 17 00:00:00 2001 From: Derek Date: Tue, 23 Mar 2021 10:31:06 +0800 Subject: [PATCH 3/4] Improve warn message on folder doesn't exists. --- src/Console/PurgeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/PurgeCommand.php b/src/Console/PurgeCommand.php index ec71d1b41..270328d0b 100644 --- a/src/Console/PurgeCommand.php +++ b/src/Console/PurgeCommand.php @@ -97,7 +97,7 @@ protected function purgeDebuggingFiles($relativePath, $patterns) if (! is_dir($path)) { $this->warn( - "Ignored purging none existing [{$relativePath}] path.", OutputInterface::VERBOSITY_DEBUG + "Purge skipped the directory that does not exist at [{$relativePath}] path.", OutputInterface::VERBOSITY_DEBUG ); return; From 2cec31b08e96636ad2bdd8f4add5d9c3674679c4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 23 Mar 2021 08:02:48 -0700 Subject: [PATCH 4/4] Update PurgeCommand.php --- src/Console/PurgeCommand.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Console/PurgeCommand.php b/src/Console/PurgeCommand.php index 270328d0b..94d5776c9 100644 --- a/src/Console/PurgeCommand.php +++ b/src/Console/PurgeCommand.php @@ -42,9 +42,7 @@ public function __construct() public function handle() { $this->purgeScreenshots(); - $this->purgeConsoleLogs(); - $this->purgeSourceLogs(); } @@ -97,7 +95,7 @@ protected function purgeDebuggingFiles($relativePath, $patterns) if (! is_dir($path)) { $this->warn( - "Purge skipped the directory that does not exist at [{$relativePath}] path.", OutputInterface::VERBOSITY_DEBUG + "Unable to purge missing directory [{$relativePath}].", OutputInterface::VERBOSITY_DEBUG ); return; @@ -111,6 +109,6 @@ protected function purgeDebuggingFiles($relativePath, $patterns) @unlink($file->getRealPath()); } - $this->info("Purged \"{$patterns}\" from [{$relativePath}] path."); + $this->info("Purged \"{$patterns}\" from [{$relativePath}]."); } }