From 6b8a7f8351ba70a68548c24b99708522fd2a0027 Mon Sep 17 00:00:00 2001 From: Sam Snelling Date: Thu, 7 Aug 2025 18:10:19 -0500 Subject: [PATCH 1/2] fix: respect --colors=never option in parallel mode The parallel mode was ignoring the --colors=never flag, causing ANSI color codes to appear even when colors were explicitly disabled. This affected multiple components of the parallel execution system. Changes: - Fixed bin/worker.php to respect --colors option from command line - Updated main parallel process to pass decoration setting to output - Modified CompactPrinter to accept decoration parameter - Updated ResultPrinter to use output decoration setting - Added test to verify --colors=never works in parallel mode Fixes parallel mode color handling inconsistency where --colors=never was ignored, ensuring clean output when colors are disabled. --- bin/worker.php | 3 ++- src/Plugins/Parallel.php | 7 ++++++- .../Parallel/Paratest/ResultPrinter.php | 2 +- .../Parallel/Support/CompactPrinter.php | 16 ++++++++++++---- tests/Visual/Parallel.php | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/bin/worker.php b/bin/worker.php index c26b05eb..01ca870e 100644 --- a/bin/worker.php +++ b/bin/worker.php @@ -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); }); diff --git a/src/Plugins/Parallel.php b/src/Plugins/Parallel.php index 94902823..461741e7 100644 --- a/src/Plugins/Parallel.php +++ b/src/Plugins/Parallel.php @@ -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; @@ -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); } diff --git a/src/Plugins/Parallel/Paratest/ResultPrinter.php b/src/Plugins/Parallel/Paratest/ResultPrinter.php index e7a1c24d..01296ef4 100644 --- a/src/Plugins/Parallel/Paratest/ResultPrinter.php +++ b/src/Plugins/Parallel/Paratest/ResultPrinter.php @@ -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; diff --git a/src/Plugins/Parallel/Support/CompactPrinter.php b/src/Plugins/Parallel/Support/CompactPrinter.php index aa2da210..4756252c 100644 --- a/src/Plugins/Parallel/Support/CompactPrinter.php +++ b/src/Plugins/Parallel/Support/CompactPrinter.php @@ -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. */ diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index f70c2826..472299fc 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -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(); From dc77861069c59737a3f62d7670c723da1e787f3c Mon Sep 17 00:00:00 2001 From: Sam Snelling Date: Thu, 7 Aug 2025 18:12:32 -0500 Subject: [PATCH 2/2] trigger CI pipeline