feat: adds --flaky cli option

This commit is contained in:
nuno maduro
2026-04-10 20:03:50 +01:00
parent f528bd8427
commit 3855249ce9
7 changed files with 42 additions and 11 deletions

View File

@ -10,6 +10,7 @@ use Pest\TestCaseMethodFilters\AssigneeTestCaseFilter;
use Pest\TestCaseMethodFilters\IssueTestCaseFilter; use Pest\TestCaseMethodFilters\IssueTestCaseFilter;
use Pest\TestCaseMethodFilters\NotesTestCaseFilter; use Pest\TestCaseMethodFilters\NotesTestCaseFilter;
use Pest\TestCaseMethodFilters\PrTestCaseFilter; use Pest\TestCaseMethodFilters\PrTestCaseFilter;
use Pest\TestCaseMethodFilters\FlakyTestCaseFilter;
use Pest\TestCaseMethodFilters\TodoTestCaseFilter; use Pest\TestCaseMethodFilters\TodoTestCaseFilter;
use Pest\TestSuite; use Pest\TestSuite;
use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\ArgvInput;
@ -23,6 +24,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
$dirty = false; $dirty = false;
$todo = false; $todo = false;
$flaky = false;
$notes = false; $notes = false;
foreach ($arguments as $key => $value) { foreach ($arguments as $key => $value) {
@ -57,6 +59,11 @@ use Symfony\Component\Console\Output\ConsoleOutput;
unset($arguments[$key]); unset($arguments[$key]);
} }
if ($value === '--flaky') {
$flaky = true;
unset($arguments[$key]);
}
if ($value === '--notes') { if ($value === '--notes') {
$notes = true; $notes = true;
unset($arguments[$key]); unset($arguments[$key]);
@ -150,6 +157,10 @@ use Symfony\Component\Console\Output\ConsoleOutput;
$testSuite->tests->addTestCaseMethodFilter(new TodoTestCaseFilter); $testSuite->tests->addTestCaseMethodFilter(new TodoTestCaseFilter);
} }
if ($flaky) {
$testSuite->tests->addTestCaseMethodFilter(new FlakyTestCaseFilter);
}
if ($notes) { if ($notes) {
$testSuite->tests->addTestCaseMethodFilter(new NotesTestCaseFilter); $testSuite->tests->addTestCaseMethodFilter(new NotesTestCaseFilter);
} }

View File

@ -152,6 +152,9 @@ final readonly class Help implements HandlesArguments
], [ ], [
'arg' => '--dirty', 'arg' => '--dirty',
'desc' => 'Only run tests that have uncommitted changes according to Git', '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['Selection']];
$content['Reporting'] = [...$content['Reporting'], ...[ $content['Reporting'] = [...$content['Reporting'], ...[

View File

@ -34,7 +34,7 @@ final class Parallel implements HandlesArguments
/** /**
* @var string[] * @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. * Whether the given command line arguments indicate that the test suite should be run in parallel.

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Pest\TestCaseMethodFilters;
use Pest\Contracts\TestCaseMethodFilter;
use Pest\Factories\TestCaseMethodFactory;
final readonly class FlakyTestCaseFilter implements TestCaseMethodFilter
{
/**
* Filter the test case methods.
*/
public function accept(TestCaseMethodFactory $factory): bool
{
return $factory->flakyTries !== null;
}
}

View File

@ -28,6 +28,7 @@
--pull-request Output to standard output tests with the given pull request number (alias for --pr) --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 --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 --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 --all .................... Ignore test selection from XML configuration file
--list-suites ................................... List available test suites --list-suites ................................... List available test suites
--testsuite [name] ......... Only run tests from the specified test suite(s) --testsuite [name] ......... Only run tests from the specified test suite(s)

View File

@ -1862,9 +1862,9 @@
PASS Tests\Visual\Help PASS Tests\Visual\Help
✓ visual snapshot of help command output ✓ visual snapshot of help command output
WARN Tests\Visual\JUnit PASS Tests\Visual\JUnit
✓ junit output ✓ junit output
- junit with parallel → Not working yet junit with parallel
PASS Tests\Visual\Parallel PASS Tests\Visual\Parallel
✓ parallel ✓ parallel
@ -1903,4 +1903,4 @@
✓ pass with dataset with ('my-datas-set-value') ✓ pass with dataset with ('my-datas-set-value')
✓ within describe → 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) Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1296 passed (2977 assertions)

View File

@ -60,20 +60,17 @@ test('junit with parallel', function () use ($normalizedPath, $run) {
expect($result['testsuite']['@attributes']) expect($result['testsuite']['@attributes'])
->name->toBe('Tests\tests\SuccessOnly') ->name->toBe('Tests\tests\SuccessOnly')
->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php')) ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php'))
->tests->toBe('2') ->tests->toBe('1')
->assertions->toBe('2') ->assertions->toBe('1')
->errors->toBe('0') ->errors->toBe('0')
->failures->toBe('0') ->failures->toBe('0')
->skipped->toBe('0'); ->skipped->toBe('0');
expect($result['testsuite']['testcase']) expect($result['testsuite']['testcase']['@attributes'])
->toHaveCount(2);
expect($result['testsuite']['testcase'][0]['@attributes'])
->name->toBe('it can pass with comparison') ->name->toBe('it can pass with comparison')
->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison')) ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison'))
->class->toBe('Tests\tests\SuccessOnly') ->class->toBe('Tests\tests\SuccessOnly')
->classname->toBe('Tests.tests.SuccessOnly') ->classname->toBe('Tests.tests.SuccessOnly')
->assertions->toBe('1') ->assertions->toBe('1')
->time->toStartWith('0.0'); ->time->toStartWith('0.0');
})->skip('Not working yet'); });