Skip to content

Commit e244ac8

Browse files
committed
feat: sharding on type coverage
1 parent 513a533 commit e244ac8

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/Plugin.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
use Pest\Contracts\Plugins\HandlesOriginalArguments;
88
use Pest\Plugins\Concerns\HandleArguments;
9+
use Pest\Plugins\Shard;
910
use Pest\Support\View;
1011
use Pest\TestSuite;
1112
use Pest\TypeCoverage\Contracts\Logger;
1213
use Pest\TypeCoverage\Logging\JsonLogger;
1314
use Pest\TypeCoverage\Logging\NullLogger;
1415
use Pest\TypeCoverage\Support\Cache;
1516
use Pest\TypeCoverage\Support\ConfigurationSourceDetector;
17+
use Symfony\Component\Console\Input\ArgvInput;
1618
use Symfony\Component\Console\Output\OutputInterface;
1719
use Symfony\Component\Finder\Finder;
1820

@@ -133,8 +135,25 @@ public function handleOriginalArguments(array $arguments): void
133135

134136
$terminalWidth = terminal()->width();
135137

138+
$input = new ArgvInput($arguments);
139+
140+
$total = 1;
141+
$index = 1;
142+
143+
if ($input->hasParameterOption('--shard')) {
144+
['index' => $index, 'total' => $total] = Shard::getShard($input);
145+
}
146+
147+
$files = iterator_to_array($files);
148+
149+
if ($total > 1) {
150+
$files = array_filter($files, static function ($file) use ($index, $total): bool {
151+
return (crc32($file->getRealPath()) % $total) === ($index - 1);
152+
});
153+
}
154+
136155
Analyser::analyse(
137-
array_keys(iterator_to_array($files)),
156+
array_keys($files),
138157
function (Result $result) use (&$totals): void {
139158
$path = str_replace(TestSuite::getInstance()->rootPath.'/', '', $result->file);
140159
$uncoveredLines = [];

0 commit comments

Comments
 (0)