From 3855249ce9dd1c4126cd74bc7be240e65e3f5e2d Mon Sep 17 00:00:00 2001 From: nuno maduro Date: Fri, 10 Apr 2026 20:03:50 +0100 Subject: [PATCH] feat: adds `--flaky` cli option --- bin/pest | 11 +++++++++++ src/Plugins/Help.php | 3 +++ src/Plugins/Parallel.php | 2 +- .../FlakyTestCaseFilter.php | 19 +++++++++++++++++++ ...isual_snapshot_of_help_command_output.snap | 1 + tests/.snapshots/success.txt | 6 +++--- tests/Visual/JUnit.php | 11 ++++------- 7 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 src/TestCaseMethodFilters/FlakyTestCaseFilter.php diff --git a/bin/pest b/bin/pest index 9e6e703c..8cd27788 100755 --- a/bin/pest +++ b/bin/pest @@ -10,6 +10,7 @@ use Pest\TestCaseMethodFilters\AssigneeTestCaseFilter; use Pest\TestCaseMethodFilters\IssueTestCaseFilter; use Pest\TestCaseMethodFilters\NotesTestCaseFilter; use Pest\TestCaseMethodFilters\PrTestCaseFilter; +use Pest\TestCaseMethodFilters\FlakyTestCaseFilter; use Pest\TestCaseMethodFilters\TodoTestCaseFilter; use Pest\TestSuite; use Symfony\Component\Console\Input\ArgvInput; @@ -23,6 +24,7 @@ use Symfony\Component\Console\Output\ConsoleOutput; $dirty = false; $todo = false; + $flaky = false; $notes = false; foreach ($arguments as $key => $value) { @@ -57,6 +59,11 @@ use Symfony\Component\Console\Output\ConsoleOutput; unset($arguments[$key]); } + if ($value === '--flaky') { + $flaky = true; + unset($arguments[$key]); + } + if ($value === '--notes') { $notes = true; unset($arguments[$key]); @@ -150,6 +157,10 @@ use Symfony\Component\Console\Output\ConsoleOutput; $testSuite->tests->addTestCaseMethodFilter(new TodoTestCaseFilter); } + if ($flaky) { + $testSuite->tests->addTestCaseMethodFilter(new FlakyTestCaseFilter); + } + if ($notes) { $testSuite->tests->addTestCaseMethodFilter(new NotesTestCaseFilter); } diff --git a/src/Plugins/Help.php b/src/Plugins/Help.php index 8c43fefa..0795c806 100644 --- a/src/Plugins/Help.php +++ b/src/Plugins/Help.php @@ -152,6 +152,9 @@ final readonly class Help implements HandlesArguments ], [ 'arg' => '--dirty', 'desc' => 'Only run tests that have uncommitted changes according to Git', + ], [ + 'arg' => '--flaky', + 'desc' => 'Output to standard output tests marked as flaky', ], ...$content['Selection']]; $content['Reporting'] = [...$content['Reporting'], ...[ diff --git a/src/Plugins/Parallel.php b/src/Plugins/Parallel.php index d2509695..a36f8a8b 100644 --- a/src/Plugins/Parallel.php +++ b/src/Plugins/Parallel.php @@ -34,7 +34,7 @@ final class Parallel implements HandlesArguments /** * @var string[] */ - private const array UNSUPPORTED_ARGUMENTS = ['--todo', '--todos', '--retry', '--notes', '--issue', '--pr', '--pull-request']; + private const array UNSUPPORTED_ARGUMENTS = ['--todo', '--todos', '--retry', '--notes', '--issue', '--pr', '--pull-request', '--flaky']; /** * Whether the given command line arguments indicate that the test suite should be run in parallel. diff --git a/src/TestCaseMethodFilters/FlakyTestCaseFilter.php b/src/TestCaseMethodFilters/FlakyTestCaseFilter.php new file mode 100644 index 00000000..fac0640e --- /dev/null +++ b/src/TestCaseMethodFilters/FlakyTestCaseFilter.php @@ -0,0 +1,19 @@ +flakyTries !== null; + } +} diff --git a/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap b/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap index f0e77b0d..f8eee485 100644 --- a/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap +++ b/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap @@ -28,6 +28,7 @@ --pull-request Output to standard output tests with the given pull request number (alias for --pr) --retry Run non-passing tests first and stop execution upon first error or failure --dirty ...... Only run tests that have uncommitted changes according to Git + --flaky .................... Output to standard output tests marked as flaky --all .................... Ignore test selection from XML configuration file --list-suites ................................... List available test suites --testsuite [name] ......... Only run tests from the specified test suite(s) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index f95ad679..b87c2279 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1862,9 +1862,9 @@ PASS Tests\Visual\Help ✓ visual snapshot of help command output - WARN Tests\Visual\JUnit + PASS Tests\Visual\JUnit ✓ junit output - - junit with parallel → Not working yet + ✓ junit with parallel PASS Tests\Visual\Parallel ✓ parallel @@ -1903,4 +1903,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 36 skipped, 1295 passed (2964 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1296 passed (2977 assertions) \ No newline at end of file diff --git a/tests/Visual/JUnit.php b/tests/Visual/JUnit.php index fd34ea7a..74cfe584 100644 --- a/tests/Visual/JUnit.php +++ b/tests/Visual/JUnit.php @@ -60,20 +60,17 @@ test('junit with parallel', function () use ($normalizedPath, $run) { expect($result['testsuite']['@attributes']) ->name->toBe('Tests\tests\SuccessOnly') ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php')) - ->tests->toBe('2') - ->assertions->toBe('2') + ->tests->toBe('1') + ->assertions->toBe('1') ->errors->toBe('0') ->failures->toBe('0') ->skipped->toBe('0'); - expect($result['testsuite']['testcase']) - ->toHaveCount(2); - - expect($result['testsuite']['testcase'][0]['@attributes']) + expect($result['testsuite']['testcase']['@attributes']) ->name->toBe('it can pass with comparison') ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison')) ->class->toBe('Tests\tests\SuccessOnly') ->classname->toBe('Tests.tests.SuccessOnly') ->assertions->toBe('1') ->time->toStartWith('0.0'); -})->skip('Not working yet'); +});