Pest: Feature: option to collapse passing tests on the report

Created on 15 Jun 2020  ·  13Comments  ·  Source: pestphp/pest

Problem:

A big test suite report will take a lot of vertical space on the terminal, and then, a lot of scrolling to check everything is OK.
Even on a 27" screen, it's almost impossible to display more than 60 tests:

Capture d’écran 2020-06-15 à 14 41 59

Suggested solution:

Provide a ./vendor/bin/pest --compact option which would collapse passing tests, and only show the individual tests in a file when at least one of them is not passing:

PestCompact

Most helpful comment

Yeah - think is better for now to add a the --compact option.

All 13 comments

Approved. This need to be worked on the collision repository tho. It's important to make it somehow an option.

Got the first basic version working!
I'll work on a clean implementation with a proper option now.

Here is the code, on src/Adapters/PHPUnit/Styles.php:

public function writeCurrentTestCaseSummary(State $state): void
{

    // [Previous code here…]

    $state->eachTestCaseTests(function (TestResult $testResult) {
        usleep(20000);

        /**
         * Only write summary for tests who aren't passing:
         *
         * ```
         *    PASS  Unit\ExampleTest
         *
         * ```
         * ```
         *    FAIL  Unit\ExampleTest
         *    ⅹ  basic test
         * ```
         *
         * TODO: Check for an option passed to Pest
         */
        if ($testResult->type !== 'passed') {
            $this->output->writeln($this->testLineFrom(
                $testResult->color,
                $testResult->icon,
                $testResult->description,
                $testResult->warning
            ));
        }
    });
}

Capture d’écran 2020-06-16 à 23 44 00

Can you do a pull request?

I can, but there is no option detection yet, so this would make it the default view.
Not sure people would like that as a default?

I'm trying a pest-plugin-trim to bring a new option for that.

Yeah - think is better for now to add a the --compact option.

Just extracted this question from the Full-Stack Utrecht presentation chat:

"When you have a test suite that is 1000+ tests, won't pest take up literally your entire terminal when 10+ tests fail? Ending up with you losing the detailed info you need in order to fix your test?"

Deep down it's the same concern as this issue.
I'll be testing something like that to see what happens.

So, I can't find a way to pass an option from Pest to Collision.
I've been trying to inject a parameter of some kind into the test suite, so that Collision could read it, but to no avail so far.

Do you have any advice regarding that, @nunomaduro ?

@AlexMartinFR maybe you can detect that you the Pest side, and change the printer to a different printer class? what do you think @owenvoke

Nice approach 👍 It should allow a custom rendering without adding too much conditionals in Collision.
I'll look into it and let you know how it goes :)

I think that sounds good. 👍 I was trying to work out how to do a similar thing for this GitHub Actions printer. Although, for that I don't think it would be that good as a separate printer class, but maybe it would. 🤷

So, I'm still struggling to pass a custom option, but at least I now have a working prototype leveraging the native PHPUnit verbose option!

Capture d’écran 2020-07-15 à 11 51 45

Niceeeeeeeeeeee...

That actually sounds good to me.

@AlexMartinFR Fell free to submit a pull request on this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rihardssceredins picture rihardssceredins  ·  5Comments

AlexMartinFR picture AlexMartinFR  ·  6Comments

nunomaduro picture nunomaduro  ·  7Comments

khalyomede picture khalyomede  ·  7Comments

JacobBennett picture JacobBennett  ·  6Comments