From b3baf7e2103de2586566ab075345fd80d4ce33c4 Mon Sep 17 00:00:00 2001 From: Adil Khan Date: Tue, 3 Nov 2026 21:11:05 +0500 Subject: [PATCH] fix: accept `--no-results` and the `--do-not-*` test run history options with `--parallel` (#1982) * fix: accept `--no-results` and the `--do-not-*` test run history options with `--parallel` * Update success snapshot count --------- Co-authored-by: Punyapal Shah Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> --- src/Plugins/Parallel/Handlers/Parallel.php | 13 +++++++ .../Parallel/Paratest/WrapperRunner.php | 5 ++- tests/.snapshots/success.txt | 8 ++++- tests/Visual/Parallel.php | 34 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Plugins/Parallel/Handlers/Parallel.php b/src/Plugins/Parallel/Handlers/Parallel.php index 023d54c0..dd5948f7 100644 --- a/src/Plugins/Parallel/Handlers/Parallel.php +++ b/src/Plugins/Parallel/Handlers/Parallel.php @@ -6,6 +6,7 @@ namespace Pest\Plugins\Parallel\Handlers; use Pest\Contracts\Plugins\HandlesArguments; use Pest\Plugins\Concerns\HandleArguments; +use Pest\Plugins\Parallel as ParallelPlugin; use Pest\Plugins\Parallel\Paratest\WrapperRunner; /** @@ -19,12 +20,24 @@ final class Parallel implements HandlesArguments '--parallel', '-p', '--no-output', + '--no-results', '--cache-result', + '--do-not-cache-result', '--record-test-run-history', + '--do-not-record-test-run-history', + ]; + + private const array ARGS_THAT_DISABLE_TEST_RUN_HISTORY = [ + '--do-not-cache-result', + '--do-not-record-test-run-history', ]; public function handleArguments(array $arguments): array { + if (array_any(self::ARGS_THAT_DISABLE_TEST_RUN_HISTORY, fn (string $argument): bool => $this->hasArgument($argument, $arguments))) { + ParallelPlugin::setGlobal(WrapperRunner::DO_NOT_RECORD_TEST_RUN_HISTORY, true); + } + $args = array_reduce(self::ARGS_TO_REMOVE, fn (array $args, string $arg): array => $this->popArgument($arg, $args), $arguments); return $this->pushArgument('--runner='.WrapperRunner::class, $args); diff --git a/src/Plugins/Parallel/Paratest/WrapperRunner.php b/src/Plugins/Parallel/Paratest/WrapperRunner.php index f4118c65..0b54e20c 100644 --- a/src/Plugins/Parallel/Paratest/WrapperRunner.php +++ b/src/Plugins/Parallel/Paratest/WrapperRunner.php @@ -14,6 +14,7 @@ use ParaTest\RunnerInterface; use ParaTest\WrapperRunner\MissingResultsException; use ParaTest\WrapperRunner\SuiteLoader; use ParaTest\WrapperRunner\WrapperWorker; +use Pest\Plugins\Parallel; use Pest\Plugins\Tia; use Pest\Result; use Pest\TestSuite; @@ -64,6 +65,8 @@ use function usleep; */ final class WrapperRunner implements RunnerInterface { + public const string DO_NOT_RECORD_TEST_RUN_HISTORY = 'DO_NOT_RECORD_TEST_RUN_HISTORY'; + public static ?TestResult $result = null; private const int CYCLE_SLEEP = 1000; @@ -472,7 +475,7 @@ final class WrapperRunner implements RunnerInterface self::$result = $testResultSum; - if ($this->options->configuration->recordTestRunHistory()) { + if ($this->options->configuration->recordTestRunHistory() && Parallel::getGlobal(self::DO_NOT_RECORD_TEST_RUN_HISTORY) !== true) { $resultCacheSum = new DefaultTestRunHistory($this->options->configuration->testRunHistoryFile()); foreach ($this->resultCacheFiles as $resultCacheFile) { $resultCache = new DefaultTestRunHistory($resultCacheFile->getPathname()); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 248e4cc7..2348e978 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2269,6 +2269,12 @@ ✓ parallel lets extensions register event subscribers ✓ parallel can have multiple exclude-groups ✓ parallel can have multiple groups + ✓ parallel accepts the options that the workers ignore with ('--no-results') + ✓ parallel accepts the options that the workers ignore with ('--do-not-cache-result') + ✓ parallel accepts the options that the workers ignore with ('--do-not-record-test-run-history') + ✓ parallel records the test run history + ✓ parallel does not record the test run history when asked not to with ('--do-not-cache-result') + ✓ parallel does not record the test run history when asked not to with ('--do-not-record-test-run-history') PASS Tests\Visual\ParallelNestedDatasets ✓ parallel loads nested datasets from nested directories @@ -2302,4 +2308,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, 37 skipped, 1629 passed (3599 assertions) + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1635 passed (3610 assertions) diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index f504afae..9bbf5a8c 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -71,3 +71,37 @@ test('parallel can have multiple groups', function () use ($run): void { ->toContain('Tests: 2 passed (2 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); + +test('parallel accepts the options that the workers ignore', function (string $option) use ($run): void { + expect($run('tests/Fixtures/Inheritance', $option)) + ->toContain('Tests: 1 skipped, 1 passed (1 assertions)') + ->toContain('Parallel: 3 processes'); +})->with([ + '--no-results', + '--do-not-cache-result', + '--do-not-record-test-run-history', +])->skipOnWindows(); + +test('parallel records the test run history', function () use ($run): void { + $cacheDirectory = sys_get_temp_dir().'/pest-parallel-history-'.bin2hex(random_bytes(8)); + + $run('tests/Fixtures/Inheritance', '--cache-directory='.$cacheDirectory); + + expect($cacheDirectory.'/test-run-history')->toBeFile(); + + unlink($cacheDirectory.'/test-run-history'); + rmdir($cacheDirectory); +})->skipOnWindows(); + +test('parallel does not record the test run history when asked not to', function (string $option) use ($run): void { + $cacheDirectory = sys_get_temp_dir().'/pest-parallel-history-'.bin2hex(random_bytes(8)); + + expect($run('tests/Fixtures/Inheritance', '--cache-directory='.$cacheDirectory, $option)) + ->toContain('Tests: 1 skipped, 1 passed (1 assertions)') + ->and($cacheDirectory.'/test-run-history')->not->toBeFile(); + + rmdir($cacheDirectory); +})->with([ + '--do-not-cache-result', + '--do-not-record-test-run-history', +])->skipOnWindows();