From 2876ac590d46079f94b2697e87bbfc11dd0d0f5a Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 3 Mar 2023 01:09:35 +0000 Subject: [PATCH] fix: todo in parallel --- bin/pest | 8 ++++---- src/Plugins/Parallel/Paratest/ResultPrinter.php | 10 ++++++---- tests/.snapshots/success.txt | 3 ++- tests/Visual/Todo.php | 14 ++++++++++---- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/bin/pest b/bin/pest index e99c09bb..9f51fa08 100755 --- a/bin/pest +++ b/bin/pest @@ -22,12 +22,12 @@ use Symfony\Component\Console\Output\OutputInterface; $todo = false; foreach ($args as $key => $value) { - if (str_contains($value, '--compact')) { + if ($value === '--compact') { $_SERVER['COLLISION_PRINTER_COMPACT'] = 'true'; unset($args[$key]); } - if (str_contains($value, '--profile')) { + if ($value === '--profile') { $_SERVER['COLLISION_PRINTER_PROFILE'] = 'true'; unset($args[$key]); } @@ -36,12 +36,12 @@ use Symfony\Component\Console\Output\OutputInterface; unset($args[$key]); } - if (str_contains($value, '--dirty')) { + if ($value === '--dirty') { $dirty = true; unset($args[$key]); } - if (str_contains($value, '--todo')) { + if ($value === '--todo') { $todo = true; unset($args[$key]); } diff --git a/src/Plugins/Parallel/Paratest/ResultPrinter.php b/src/Plugins/Parallel/Paratest/ResultPrinter.php index eb23ccfe..62297e1c 100644 --- a/src/Plugins/Parallel/Paratest/ResultPrinter.php +++ b/src/Plugins/Parallel/Paratest/ResultPrinter.php @@ -68,11 +68,13 @@ final class ResultPrinter public function print(string $buffer): void { $buffer = OutputFormatter::escape($buffer); - - if (! str_starts_with($buffer, "\nGenerating code coverage report") - && ! str_starts_with($buffer, 'done [')) { - $this->output->write(OutputFormatter::escape($buffer)); + if (str_starts_with($buffer, "\nGenerating code coverage report")) { + return; } + if (str_starts_with($buffer, 'done [')) { + return; + } + $this->output->write(OutputFormatter::escape($buffer)); } public function flush(): void diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index d28df786..1812c562 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -924,8 +924,9 @@ PASS Tests\Visual\Todo ✓ todo + ✓ todo in parallel PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 633 passed (1564 assertions) \ No newline at end of file + Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 634 passed (1567 assertions) \ No newline at end of file diff --git a/tests/Visual/Todo.php b/tests/Visual/Todo.php index ac4f3ba5..3a396a21 100644 --- a/tests/Visual/Todo.php +++ b/tests/Visual/Todo.php @@ -2,14 +2,16 @@ use Symfony\Component\Process\Process; -$run = function (string $target, $decorated = false) { - $process = new Process(['php', 'bin/pest', $target, '--colors=always'], dirname(__DIR__, 2), +$run = function (string $target, bool $parallel) { + $process = new Process(['php', 'bin/pest', $target, $parallel ? '--parallel' : '', '--colors=always'], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], ); $process->run(); - return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); + expect($process->getExitCode())->toBe(0); + + return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); }; $snapshot = function ($name) { @@ -23,5 +25,9 @@ $snapshot = function ($name) { }; test('todo', function () use ($run, $snapshot) { - expect($run('--todo'))->toContain($snapshot('todo')); + expect($run('--todo', false))->toContain($snapshot('todo')); +})->skip(PHP_OS_FAMILY === 'Windows'); + +test('todo in parallel', function () use ($run, $snapshot) { + expect($run('--todo', true))->toContain($snapshot('todo')); })->skip(PHP_OS_FAMILY === 'Windows');