test-results-reporter / parser

Parse test results from JUnit, TestNG, xUnit and many more
https://www.testbeats.com
MIT License
12 stars 9 forks source link

'Error: undefined' appears on failure-details Slack message #73

Open mnoorenberghe opened 1 month ago

mnoorenberghe commented 1 month ago
SLACK_MESSAGE_FORMAT=failure-details npx testbeats publish -c testbeats.config.js
Screenshot 2024-07-09 at 3 11 14 PM

Example junit.xml from jest-junit:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="E2E Test" tests="38" failures="12" errors="0" time="334.312">
  <testsuite name="site-info" errors="0" failures="12" skipped="0" timestamp="2024-07-09T14:03:34" time="332.454" tests="38">
    <testcase classname="foo should be correct for: bar" name="foo should be correct for: bar" time="20.74" file="test.ts">
      <failure>Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

@@ -1,7 +1,7 @@
  Object {
-   &quot;Address&quot;: &quot;7, Stone Hill&quot;,
+   &quot;Address&quot;: &quot;&quot;,
    &quot;First Name&quot;: &quot;Bob&quot;,
    &quot;Last Name&quot;: &quot;Tree&quot;,
    &quot;Status&quot;: &quot;&quot;,
    at /test.ts:113:33
    at processTicksAndRejections (node:internal/process/task_queues:96:5)</failure>
    </testcase>
  </testsuite>
</testsuites>
ASaiAnudeep commented 1 month ago

Seems to be a bug from jest-junit implementation.

failure element should have a message property to include the error.

Reference: https://github.com/junit-team/junit5/blob/main/platform-tests/src/test/resources/jenkins-junit.xsd#L31-L36

mnoorenberghe commented 1 month ago

failure element should have a message property to include the error.

Does use="optional"mean it's optional? If so, then it doesn't mean it should.

ASaiAnudeep commented 1 month ago

The message property or failure element may be optional. According to the schema, error text should belong to the message property and not elsewhere.

I understand that many test frameworks do not consistently adhere to a specific pattern. It would be beneficial to address this within the jest-unit reporter. We are also open to making adjustments if this can benefit the community overall.

leelaprasadv commented 1 month ago

@mnoorenberghe we might have a workaround here.

According to jest-junit plugin code, adding --noStackTraceto your jest test should create the junit XML with nested message attributes (if everything else checks out) for failure tests.

https://github.com/jest-community/jest-junit/blob/master/utils/buildJsonResults.js#L86

Note: this would mean the entire stack trace will likely be removed and may not be reported to slack.

You could try adding a link to the test run/build in the notification for users to view the error message printed on the console instead.

mnoorenberghe commented 1 month ago

The message property or failure element may be optional. According to the schema, error text should belong to the message property and not elsewhere.

I would be fine with it just omitting the Error: undefined portion of the Slack message if that is undefined (since it's optional according to the xsd)

According to jest-junit plugin code, adding --noStackTraceto your jest test should create the junit XML with nested message attributes (if everything else checks out) for failure tests.

Thanks, I'll give that a try now.

mnoorenberghe commented 1 month ago

According to jest-junit plugin code, adding --noStackTraceto your jest test should create the junit XML with nested message attributes (if everything else checks out) for failure tests.

Thanks, I'll give that a try now.

The code never sets the message attribute AFAICT, regardless of --noStackTrace.

mnoorenberghe commented 1 month ago

Does this project have any interest in retrieving the error message from the contents of the <failure> like how jest-junit produces it?