diff --git a/bin/worker.php b/bin/worker.php index c26b05eba..01ca870ee 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 1632a0504..fb215f9c6 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,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); return CallsAddsOutput::execute($exitCode); } diff --git a/src/Plugins/Parallel/Paratest/ResultPrinter.php b/src/Plugins/Parallel/Paratest/ResultPrinter.php index bd416e1e7..69bc24ed1 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 25226b10e..59f353e28 100644 --- a/src/Plugins/Parallel/Support/CompactPrinter.php +++ b/src/Plugins/Parallel/Support/CompactPrinter.php @@ -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)), terminal()->width() - 4, ); } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 513a804ea..31c068125 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -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 @@ -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) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 38 todos, 33 skipped, 1145 passed (2739 assertions) \ No newline at end of file diff --git a/tests/Arch.php b/tests/Arch.php index d8deb4609..504719f61 100644 --- a/tests/Arch.php +++ b/tests/Arch.php @@ -33,6 +33,7 @@ 'dd', 'dump', 'expect', + 'ray', 'uses', 'Termwind', 'ParaTest', diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 313f82088..6ed2ac806 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();