From 9e1fc655fafefdf38109d7547daf3288ff3abb28 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Thu, 11 Jul 2024 09:21:19 -0400 Subject: [PATCH] Notifications: Handle a failure without a failure message The message attribute of `` is optional and some tools print the message in the textContent. We shouldn't output `undefined` if it's not present. See https://github.com/test-results-reporter/parser/issues/73 for the root issue --- src/targets/chat.js | 2 +- src/targets/slack.js | 2 +- src/targets/teams.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/targets/chat.js b/src/targets/chat.js index ede57d7..fb74265 100644 --- a/src/targets/chat.js +++ b/src/targets/chat.js @@ -111,7 +111,7 @@ function getFailureDetails(suite) { for (let i = 0; i < cases.length; i++) { const test_case = cases[i]; if (test_case.status === 'FAIL') { - text += `Test: ${test_case.name}
Error: ${truncate(test_case.failure, 150)}

`; + text += `Test: ${test_case.name}
Error: ${truncate(test_case.failure ?? 'N/A', 150)}

`; } } return text; diff --git a/src/targets/slack.js b/src/targets/slack.js index a627911..8e7b335 100644 --- a/src/targets/slack.js +++ b/src/targets/slack.js @@ -129,7 +129,7 @@ function getFailureDetails(suite) { for (let i = 0; i < cases.length; i++) { const test_case = cases[i]; if (test_case.status === 'FAIL') { - text += `*Test*: ${test_case.name}\n*Error*: ${truncate(test_case.failure, 150)}\n\n`; + text += `*Test*: ${test_case.name}\n*Error*: ${truncate(test_case.failure ?? 'N/A', 150)}\n\n`; } } return { diff --git a/src/targets/teams.js b/src/targets/teams.js index 7f1ab41..8a30e4f 100644 --- a/src/targets/teams.js +++ b/src/targets/teams.js @@ -183,7 +183,7 @@ function getFailureDetailsFactSets(suite) { }, { "title": "Error:", - "value": truncate(test_case.failure, 150) + "value": truncate(test_case.failure ?? 'N/A', 150) } ] });