Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Plugins/Parallel/Handlers/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/Plugins/Parallel/Paratest/WrapperRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 7 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1616 passed (3527 assertions)
34 changes: 34 additions & 0 deletions tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();