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
3 changes: 2 additions & 1 deletion bin/worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

$input = new ArgvInput;

$output = new ConsoleOutput(OutputInterface::VERBOSITY_NORMAL, true);
$isDecorated = $workerArgv->getParameterOption('--colors', 'always') !== 'never';
$output = new ConsoleOutput(OutputInterface::VERBOSITY_NORMAL, $isDecorated);

Kernel::boot($testSuite, $input, $output);
});
Expand Down
7 changes: 6 additions & 1 deletion src/Plugins/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Stringable;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;

use function Pest\version;

Expand Down Expand Up @@ -127,7 +128,11 @@ private function runTestSuiteInParallel(array $arguments): int
$arguments
);

$exitCode = $this->paratestCommand()->run(new ArgvInput($filteredArguments), new CleanConsoleOutput);
$input = new ArgvInput($filteredArguments);
$isDecorated = $input->getParameterOption('--colors', 'always') !== 'never';
$output = new CleanConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, $isDecorated);

$exitCode = $this->paratestCommand()->run($input, $output);

return CallsAddsOutput::execute($exitCode);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/Parallel/Paratest/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function print(string $buffer): void
public function flush(): void {}
};

$this->compactPrinter = CompactPrinter::default();
$this->compactPrinter = CompactPrinter::create($this->output->isDecorated());

if (! $this->options->configuration->hasLogfileTeamcity()) {
return;
Expand Down
16 changes: 12 additions & 4 deletions src/Plugins/Parallel/Support/CompactPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,26 @@ public function __construct(
}

/**
* Creates a new instance of the Compact Printer.
* Creates a new instance of the Compact Printer with decoration setting.
*/
public static function default(): self
public static function create(bool $decorated): self
{
return new self(
terminal(),
new ConsoleOutput(decorated: true),
new Style(new ConsoleOutput(decorated: true)),
new ConsoleOutput(decorated: $decorated),
new Style(new ConsoleOutput(decorated: $decorated)),
terminal()->width() - 4,
);
}

/**
* Creates a new instance of the Compact Printer.
*/
public static function default(): self
{
return self::create(true);
}

/**
* Output an empty line in the console. Useful for providing a little breathing room.
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,22 @@
test('a parallel test can extend another test with same name', function () use ($run) {
expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 2 passed (2 assertions)');
});

test('parallel mode respects --colors=never option', function () {
$process = new Process([
'php',
'./bin/pest',
'--parallel',
'--processes=2',
'--colors=never',
'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']);
$process->run();
$output = $process->getOutput();

// Output should not contain ANSI color codes when --colors=never is used
expect($output)
->not->toMatch('/\x1b\[[0-9;]*m/') // ANSI color codes pattern
->toContain('Tests:') // Should still have test output
->toContain('Parallel:'); // Should still indicate parallel mode
})->skipOnWindows();
Loading