daun / playwright-report-summary

A GitHub action to report Playwright test results as pull request comments
MIT License
40 stars 8 forks source link

[Bug] Reports 0 tests run when specs are in third level of suite hierarchy #147

Closed larmitage-bjss closed 7 months ago

larmitage-bjss commented 7 months ago

I have two projects generating playwright json files, one has the spec details inside the second level of suites and the summary is working correctly:

Screenshot 2024-04-17 at 17 22 32

The second has the spec details inside the third level of suites and the summary is coming out as "0 tests across 4 suites":

Screenshot 2024-04-17 at 17 22 40

I can see the issue is in report.ts where it is only looking at the first and second level of suites, but I have been struggling to update the code as the tests are currently not working.

It should just need updating to something like:

const specs: SpecSummary[] = report.suites.reduce((all, file) => {
    for (const spec of file.specs) {
        all.push(parseSpec(spec, [file]))
    }
    for (const suite of file.suites || []) {
        for (const spec of suite.specs) {
            all.push(parseSpec(spec, [file, suite]))
        }

        for (const suite2 of suite.suites || []) {
            for (const spec of suite2.specs) {
                all.push(parseSpec(spec, [file, suite, suite2]))
            }
        }
    }
    return all
}, [] as SpecSummary[])

Or even better a recursive function until it finds an empty array of suites.

Thanks

daun commented 7 months ago

Makes sense. I never knew one could just recursively nest suites! If you can provide an example json report that's failing to generate the correct summary, I'm happy to take a look at it.

daun commented 7 months ago

I think the tests are currently failing because of too strict an eslint or typescript config, not because the logic is faulty.

larmitage-bjss commented 7 months ago

I can share examples but I'd rather not do it publicly. I've just followed you on Twitter/X, would you be able to follow me back and I can DM you? Unless you've got a different method (public email address etc)?

daun commented 7 months ago

@larmitage-bjss I've sent you a dm, let me know if that works.

daun commented 7 months ago

I've released 3.3.0 which should take care of this. Can you try it out and report back if it's working for you?

larmitage-bjss commented 7 months ago

Absolute star, looks like it's working correctly now! Thank you so much!

Screenshot 2024-04-22 at 09 49 58