ctrf-io / playwright-ctrf-json-reporter

A Playwright JSON test results reporter that follows the CTRF schema
https://ctrf.io
MIT License
38 stars 1 forks source link

Bug: `Error in reporter TypeError: Cannot read properties of undefined (reading 'status')` #2

Closed afonsosantos closed 4 months ago

afonsosantos commented 4 months ago

Hi there!

I'm trying to generate a test report in Github Actions, and the reporter failed with the error below:

Error in reporter TypeError: Cannot read properties of undefined (reading 'status')
    at GenerateCtrfReport.updateCtrfTestResultsFromTestResult (/home/runner/work/frontend/frontend/node_modules/playwright-ctrf-json-reporter/dist/generate-report.js:100:63)
    at GenerateCtrfReport.processTest (/home/runner/work/frontend/frontend/node_modules/playwright-ctrf-json-reporter/dist/generate-report.js:85:14)
    at GenerateCtrfReport.processSuite (/home/runner/work/frontend/frontend/node_modules/playwright-ctrf-json-reporter/dist/generate-report.js:77:18)
    at GenerateCtrfReport.processSuite (/home/runner/work/frontend/frontend/node_modules/playwright-ctrf-json-reporter/dist/generate-report.js:80:18)
    at GenerateCtrfReport.processSuite (/home/runner/work/frontend/frontend/node_modules/playwright-ctrf-json-reporter/dist/generate-report.js:80:18)
    at GenerateCtrfReport.processSuite (/home/runner/work/frontend/frontend/node_modules/playwright-ctrf-json-reporter/dist/generate-report.js:80:18)
    at GenerateCtrfReport.onEnd (/home/runner/work/frontend/frontend/node_modules/playwright-ctrf-json-reporter/dist/generate-report.js:70:18)
    at ReporterV2Wrapper.onEnd (/home/runner/work/frontend/frontend/node_modules/playwright/lib/reporters/reporterV2.js:91:165)
    at /home/runner/work/frontend/frontend/node_modules/playwright/lib/reporters/multiplexer.js:51:56
    at wrapAsync (/home/runner/work/frontend/frontend/node_modules/playwright/lib/reporters/multiplexer.js:79:18)
    at Multiplexer.onEnd (/home/runner/work/frontend/frontend/node_modules/playwright/lib/reporters/multiplexer.js:51:31)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at InternalReporter.onEnd (/home/runner/work/frontend/frontend/node_modules/playwright/lib/reporters/internalReporter.js:69:12)
    at Runner.runAllTests (/home/runner/work/frontend/frontend/node_modules/playwright/lib/runner/runner.js:78:28)
    at runTests (/home/runner/work/frontend/frontend/node_modules/playwright/lib/program.js:207:85)
    at t.<anonymous> (/home/runner/work/frontend/frontend/node_modules/playwright/lib/program.js:54:7)

The version I'm using is the latest available, 0.0.14. Here's my reporters config in playwright.nuxt.ts:

reporter: [
    ["list", { printSteps: true }],
    ["html", { open: "on-failure", port: 3010 }],
    [
      "playwright-ctrf-json-reporter",
      {
        outputFile: "report.json",
        outputDir: "ctrf",
        testType: "e2e",
      },
    ],
  ],

Also, I'm using github-actions-ctrf to display the results from the CTRF report in Github Actions, as configured in my workflow:

- name: Run Playwright tests
  run: bunx playwright test

- name: Run CTRF annotations
  if: always()
  run: bunx github-actions-ctrf ctrf/report.json

In case any more debugging or help is needed, let me know.

Thanks!

Ma11hewThomas commented 4 months ago

I'm unable to recreate this issue but it likely occurs because the code tries to access properties of a TestResult object without first ensuring that the results array contains elements. This might happen if a test suite is defined but contains no actual test cases or if test cases exist, but the results array is empty due to unknown reasons. I've added additional checks to ensure that the results array is not empty before trying to access its elements, please try version 0.0.15.