Skip execution for empty test shards (#2041)

Co-authored-by: haranishi <223786623+haranishi@users.noreply.github.com>
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
Ikki Nishihara
2026-11-20 06:00:56 +09:00
committed by GitHub
parent a1a902dbc7
commit 989c08008f
4 changed files with 63 additions and 10 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
use Symfony\Component\Process\Process;
test('an empty shard runs no tests', function (int $exitCode, string ...$arguments): void {
$process = new Process([
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
'--colors=never', '--shard=2/2', ...$arguments,
], dirname(__DIR__, 2));
$process->run();
expect($process->getExitCode())->toBe($exitCode)
->and(removeAnsiEscapeSequences($process->getOutput()))
->toContain('No tests found.', '2 of 2 — 0 files ran, out of 1.')
->not->toContain('example 1');
})->with([
'sequential' => [0],
'parallel' => [0, '--parallel', '--processes=2'],
'sequential with fail-on-empty-test-suite' => [1, '--fail-on-empty-test-suite'],
'parallel with fail-on-empty-test-suite' => [1, '--parallel', '--processes=2', '--fail-on-empty-test-suite'],
]);
test('an empty shard lists no tests', function (): void {
$process = new Process([
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
'--colors=never', '--shard=2/2', '--list-tests',
], dirname(__DIR__, 2));
$process->run();
expect($process->getExitCode())->toBe(0)
->and($process->getOutput())->toContain('Available test')
->not->toContain('__pest_evaluable_it_example_1', 'example 1');
});
test('a non-empty shard runs its assigned test', function (): void {
$process = new Process([
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
'--colors=never', '--shard=1/2',
], dirname(__DIR__, 2));
$process->run();
expect($process->getExitCode())->toBe(0)
->and($process->getOutput())->toContain('1 passed', '1 of 2 — 1 file ran, out of 1.');
});