From 4318b5dddafaf67ef5005a10f558c4a4fbf43fbf Mon Sep 17 00:00:00 2001 From: Adil Khan <31621120+adilKhan72@users.noreply.github.com> Date: Mon, 19 Oct 2026 02:58:17 +0500 Subject: [PATCH] fix: accept `--no-results` and the `--do-not-*` test run history options with `--parallel` --- 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 023d54c04..dd5948f7d 100644 --- a/src/Plugins/Parallel/Handlers/Parallel.php +++ b/src/Plugins/Parallel/Handlers/Parallel.php @@ -6,6 +6,7 @@ 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 2cb01a10b..37593befd 100644 --- a/src/Plugins/Parallel/Paratest/WrapperRunner.php +++ b/src/Plugins/Parallel/Paratest/WrapperRunner.php @@ -14,6 +14,7 @@ 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 @@ */ 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; @@ -474,7 +477,7 @@ private function complete(TestResult $testResultSum): int 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 0ea8b3f6b..681649249 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2238,6 +2238,12 @@ ✓ parallel reports invalid datasets as failures ✓ 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 @@ -2271,4 +2277,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, 35 skipped, 1610 passed (3516 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1616 passed (3527 assertions) \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index a775c9926..e0654cffb 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -56,3 +56,37 @@ ->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();