Disable output during tests
eleftrik opened this issue · 4 comments
Maybe it's a dumb question, but I didn't find any solutions.
Is it possible to disable termwind output when tests are running?
Let's say there is a simple command which outputs text with $this->info()
and render()
:
public function handle(): int
{
$this->info("Green text");
render('<div class="text-red-500">Red text</div>');
return self::SUCCESS;
}
and a simple test (Pest):
<?php
use App\Console\Commands\TestCommand;
use function Pest\Laravel\artisan;
it('returns a successful response', function () {
artisan(TestCommand::class)
->assertOk();
});
When tests are running, "Green text" will not show, while "Red text" will.
I think both should not be rendered while tests are running.
What's the best way to make render()
behave like standard output functions?
Thank you
You can use renderUsing(new BufferedOutput)
.
Ok, now I've setup my Pest test like this:
<?php
use Symfony\Component\Console\Output\BufferedOutput;
use function Pest\Laravel\artisan;
use function Termwind\renderUsing;
beforeEach(fn() => renderUsing(new BufferedOutput()));
...and the output while tests are running is gone.
Thank you @xiCO2k!
Awesome 💪
If you really don't need the output, there's also Symfony\Component\Console\Output\NullOutput
.