Skip to content
Closed
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);
Copy link
Collaborator Author

@snellingio snellingio Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worker processes were hardcoded to use decorated output (true), causing --colors=never to be ignored in parallel mode. Now respects the --colors parameter from command line arguments.


Kernel::boot($testSuite, $input, $output);
});
Expand Down
6 changes: 5 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,10 @@ 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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main parallel process wasn't passing decoration setting to CleanConsoleOutput. Now checks --colors option and passes the decoration setting.


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
12 changes: 10 additions & 2 deletions src/Plugins/Parallel/Support/CompactPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,19 @@ public function __construct(
* Creates a new instance of the Compact Printer.
*/
public static function default(): self
{
return self::create(true);
}

/**
* Creates a new instance of the Compact Printer with specific decoration setting.
*/
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)),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added create() method to accept decoration parameter. Previously, CompactPrinter was hardcoded to use decorated output, ignoring --colors=never in parallel mode.

terminal()->width() - 4,
);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@
PASS Tests\Visual\Parallel
✓ parallel
✓ a parallel test can extend another test with same name
✓ parallel mode respects --colors=never option

PASS Tests\Visual\SingleTestOrDirectory
✓ allows to run a single test
Expand All @@ -1698,4 +1699,4 @@
WARN Tests\Visual\Version
- visual snapshot of help command output

Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1144 passed (2736 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1145 passed (2739 assertions)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if I'm supposed to update the snapshot or not.

1 change: 1 addition & 0 deletions tests/Arch.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'dd',
'dump',
'expect',
'ray',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually stumps me a bit -- because everyone else's pipelines pass.

Had to have Claude help me, and they pointed out that the issue seems to be that ray is already used here: https://github.com/pestphp/pest/blob/3.x/src/Expectation.php#L176

'uses',
'Termwind',
'ParaTest',
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