Adds Pest output to parallel.

This commit is contained in:
luke
2021-08-09 18:57:20 +01:00
parent 31d1b1b91d
commit a760470e48
2 changed files with 45 additions and 7 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Pest\Console\Paratest; namespace Pest\Console\Paratest;
use Symfony\Component\Console\Output\OutputInterface;
use function array_merge; use function array_merge;
use const DIRECTORY_SEPARATOR; use const DIRECTORY_SEPARATOR;
use ParaTest\Runners\PHPUnit\ExecutableTest; use ParaTest\Runners\PHPUnit\ExecutableTest;
@ -22,11 +23,23 @@ final class PestRunnerWorker
{ {
/** @var ExecutableTest */ /** @var ExecutableTest */
private $executableTest; private $executableTest;
/** @var Process */ /** @var Process */
private $process; private $process;
public function __construct(ExecutableTest $executableTest, Options $options, int $token) /**
* @var OutputInterface
*/
private $output;
/**
* @var array<string>
*/
public static $additionalOutput = [];
public function __construct(OutputInterface $output, ExecutableTest $executableTest, Options $options, int $token)
{ {
$this->output = $output;
$this->executableTest = $executableTest; $this->executableTest = $executableTest;
$phpFinder = new PhpExecutableFinder(); $phpFinder = new PhpExecutableFinder();
@ -81,7 +94,28 @@ final class PestRunnerWorker
*/ */
public function stop(): ?int public function stop(): ?int
{ {
return $this->process->stop(); $exitCode = $this->process->stop();
$this->handleOutput($this->process->getOutput());
return $exitCode;
}
private function handleOutput(string $output)
{
$matches = [];
preg_match_all("/^\\n/m", $output, $matches, PREG_OFFSET_CAPTURE);
$overview = substr($output, 0, $matches[0][1][1]);
$this->output->write($overview);
if (count($matches[0]) > 3) {
$summarySectionIndex = count($matches[0]) - 2;
static::$additionalOutput[] = substr(
$output,
$matches[0][1][1],
$matches[0][$summarySectionIndex][1] - $matches[0][1][1],
);
}
} }
/** /**

View File

@ -84,7 +84,7 @@ final class Runner implements RunnerInterface
final public function run(): void final public function run(): void
{ {
$this->load(new SuiteLoader($this->options, $this->output)); $this->load(new SuiteLoader($this->options, $this->output));
$this->printer->start(); // $this->printer->start();
$this->doRun(); $this->doRun();
@ -109,7 +109,7 @@ final class Runner implements RunnerInterface
$this->sortPending(); $this->sortPending();
foreach ($this->pending as $pending) { foreach ($this->pending as $pending) {
$this->printer->addTest($pending); // $this->printer->addTest($pending);
} }
} }
@ -135,7 +135,11 @@ final class Runner implements RunnerInterface
*/ */
private function complete(): void private function complete(): void
{ {
$this->printer->printResults(); foreach(PestRunnerWorker::$additionalOutput as $output) {
$this->output->write($output);
}
PestRunnerWorker::$additionalOutput = [];
// $this->printer->printResults();
$this->log(); $this->log();
$this->logCoverage(); $this->logCoverage();
$readers = $this->interpreter->getReaders(); $readers = $this->interpreter->getReaders();
@ -273,7 +277,7 @@ final class Runner implements RunnerInterface
) { ) {
$executableTest = array_shift($this->pending); $executableTest = array_shift($this->pending);
$this->running[$token] = new PestRunnerWorker($executableTest, $this->options, $token); $this->running[$token] = new PestRunnerWorker($this->output, $executableTest, $this->options, $token);
$this->running[$token]->run(); $this->running[$token]->run();
if ($this->options->verbosity() < Options::VERBOSITY_VERY_VERBOSE) { if ($this->options->verbosity() < Options::VERBOSITY_VERY_VERBOSE) {
@ -314,7 +318,7 @@ final class Runner implements RunnerInterface
$executableTest = $worker->getExecutableTest(); $executableTest = $worker->getExecutableTest();
try { try {
$this->printer->printFeedback($executableTest); // $this->printer->printFeedback($executableTest);
} catch (EmptyLogFileException $emptyLogFileException) { } catch (EmptyLogFileException $emptyLogFileException) {
throw $worker->getWorkerCrashedException($emptyLogFileException); throw $worker->getWorkerCrashedException($emptyLogFileException);
} }