Repository: test-results-reporter/reporter
Pull request #158 (2024-03-19 05:31:44)

152 extension ci details


Patch:
diff --git a/package-lock.json b/package-lock.json
index 06bed9b..5daafe5 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "test-results-reporter",
-  "version": "1.1.3",
+  "version": "1.1.4",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "test-results-reporter",
-      "version": "1.1.3",
+      "version": "1.1.4",
       "license": "ISC",
       "dependencies": {
         "async-retry": "^1.3.3",
diff --git a/package.json b/package.json
index af38b70..b6f18b3 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "test-results-reporter",
-  "version": "1.1.3",
+  "version": "1.1.4",
   "description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB",
   "main": "src/index.js",
   "types": "./src/index.d.ts",
diff --git a/src/extensions/ci-info.js b/src/extensions/ci-info.js
index 0795c0d..05dbfa1 100644
--- a/src/extensions/ci-info.js
+++ b/src/extensions/ci-info.js
@@ -44,11 +44,11 @@ function get_repository_elements(inputs) {
   }
   if (inputs.show_repository_branch && ci && ci.repository_ref) {
     if (ci.repository_ref.includes('refs/pull')) {
-      const pr_url = ci.repository_url + ci.repository_ref.replace('refs/pull/', 'pull/');
+      const pr_url = ci.repository_url + ci.repository_ref.replace('refs/pull/', '/pull/');
       const pr_name = ci.repository_ref.replace('refs/pull/', '').replace('/merge', '');
       elements.push({ label: 'Pull Request', key: pr_name, value: pr_url, type: 'hyperlink' });
     } else {
-      const branch_url = ci.repository_url + ci.repository_ref.replace('refs/heads/', 'tree/');
+      const branch_url = ci.repository_url + ci.repository_ref.replace('refs/heads/', '/tree/');
       const branch_name = ci.repository_ref.replace('refs/heads/', '');
       elements.push({ label: 'Branch', key: branch_name, value: branch_url, type: 'hyperlink' });
     }
@@ -104,7 +104,7 @@ async function get_text({ target, extension, result }) {
 }
 
 const default_options = {
-  hook: HOOK.END,
+  hook: HOOK.AFTER_SUMMARY,
   condition: STATUS.PASS_OR_FAIL,
 }
 
diff --git a/src/helpers/constants.js b/src/helpers/constants.js
index 7d7c6b3..b9f5dab 100644
--- a/src/helpers/constants.js
+++ b/src/helpers/constants.js
@@ -6,7 +6,7 @@ const STATUS = Object.freeze({
 
 const HOOK = Object.freeze({
   START: 'start',
-  POST_MAIN: 'post-main',
+  AFTER_SUMMARY: 'after-summary',
   END: 'end',
 });
 
diff --git a/src/index.d.ts b/src/index.d.ts
index 36541d1..6ac70c3 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -5,7 +5,7 @@ import { ParseOptions } from 'test-results-parser';
 import TestResult from 'test-results-parser/src/models/TestResult';
 
 export type ExtensionName = 'report-portal-analysis' | 'hyperlinks' | 'mentions' | 'report-portal-history' | 'quick-chart-test-summary' | 'metadata' | 'ci-info' | 'custom';
-export type Hook = 'start' | 'end';
+export type Hook = 'start' | 'end' | 'after-summary';
 export type TargetName = 'slack' | 'teams' | 'chat' | 'custom' | 'delay';
 export type PublishReportType = 'test-summary' | 'test-summary-slim' | 'failure-details';
 
diff --git a/src/targets/chat.js b/src/targets/chat.js
index bf844ca..86a6441 100644
--- a/src/targets/chat.js
+++ b/src/targets/chat.js
@@ -23,7 +23,7 @@ async function run({ result, target }) {
 async function setFunctionalPayload({ result, target, payload, root_payload }) {
   await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.START });
   setMainBlock({ result, target, payload });
-  await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.POST_MAIN });
+  await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.AFTER_SUMMARY });
   setSuiteBlock({ result, target, payload });
   await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.END });
 }
@@ -137,7 +137,7 @@ function getTitleTextWithEmoji({ result, target }) {
 async function setPerformancePayload({ result, target, payload, root_payload }) {
   await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.START });
   await setPerformanceMainBlock({ result, target, payload });
-  await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.POST_MAIN });
+  await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.AFTER_SUMMARY });
   await setTransactionBlock({ result, target, payload });
   await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.END });
 }
diff --git a/src/targets/slack.js b/src/targets/slack.js
index 7c95328..dfead54 100644
--- a/src/targets/slack.js
+++ b/src/targets/slack.js
@@ -32,7 +32,7 @@ async function run({ result, target }) {
 async function setFunctionalPayload({ result, target, payload }) {
   await extension_manager.run({ result, target, payload, hook: HOOK.START });
   setMainBlock({ result, target, payload });
-  await extension_manager.run({ result, target, payload, hook: HOOK.POST_MAIN });
+  await extension_manager.run({ result, target, payload, hook: HOOK.AFTER_SUMMARY });
   setSuiteBlock({ result, target, payload });
   await extension_manager.run({ result, target, payload, hook: HOOK.END });
 }
@@ -173,7 +173,7 @@ function getRootPayload({ result, payload }) {
 async function setPerformancePayload({ result, target, payload }) {
   await extension_manager.run({ result, target, payload, hook: HOOK.START });
   await setPerformanceMainBlock({ result, target, payload });
-  await extension_manager.run({ result, target, payload, hook: HOOK.POST_MAIN });
+  await extension_manager.run({ result, target, payload, hook: HOOK.AFTER_SUMMARY });
   await setTransactionBlock({ result, target, payload });
   await extension_manager.run({ result, target, payload, hook: HOOK.END });
 }
diff --git a/src/targets/teams.js b/src/targets/teams.js
index 3c058e1..6cc5b06 100644
--- a/src/targets/teams.js
+++ b/src/targets/teams.js
@@ -32,7 +32,7 @@ async function setPerformancePayload({ result, target, payload, root_payload })
   await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.START });
   setTitleBlock({ result, target, payload });
   await setMainBlockForPerformance({ result, target, payload });
-  await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.POST_MAIN });
+  await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.AFTER_SUMMARY });
   await setTransactionBlock({ result, target, payload });
   await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.END });
 }
@@ -41,7 +41,7 @@ async function setFunctionalPayload({ result, target, payload, root_payload }) {
   await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.START });
   setTitleBlock({ result, target, payload });
   setMainBlock({ result, target, payload });
-  await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.POST_MAIN });
+  await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.AFTER_SUMMARY });
   setSuiteBlock({ result, target, payload });
   await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.END });
 }


Test patch:
diff --git a/src/extensions/quick-chart-test-summary.js b/src/extensions/quick-chart-test-summary.js
index 4bdbce0..984c03d 100644
--- a/src/extensions/quick-chart-test-summary.js
+++ b/src/extensions/quick-chart-test-summary.js
@@ -72,7 +72,7 @@ function run(params) {
 }
 
 const default_options = {
-  hook: HOOK.POST_MAIN,
+  hook: HOOK.AFTER_SUMMARY,
   condition: STATUS.PASS_OR_FAIL
 }
 
diff --git a/test/ext-ci-info.spec.js b/test/ext-ci-info.spec.js
index 12eb480..539fb74 100644
--- a/test/ext-ci-info.spec.js
+++ b/test/ext-ci-info.spec.js
@@ -58,7 +58,7 @@ describe('extensions - ci-info', () => {
     process.env.GITHUB_ACTIONS = 'GITHUB_ACTIONS';
     process.env.GITHUB_SERVER_URL = 'https://github.com';
     process.env.GITHUB_REPOSITORY = 'test/test';
-    process.env.GITHUB_REF = '/refs/heads/feature-test';
+    process.env.GITHUB_REF = 'refs/heads/feature-test';
     process.env.GITHUB_SHA = 'sha';
     process.env.GITHUB_RUN_ID = 'id-123';
     process.env.GITHUB_RUN_NUMBER = 'number-123';
@@ -97,7 +97,7 @@ describe('extensions - ci-info', () => {
     process.env.SYSTEM_TEAMPROJECT = 'test';
     process.env.BUILD_REPOSITORY_URI = 'https://github.com/test/test';
     process.env.BUILD_REPOSITORY_NAME = 'test/test';
-    process.env.BUILD_SOURCEBRANCH = '/refs/pull/123/merge';
+    process.env.BUILD_SOURCEBRANCH = 'refs/pull/123/merge';
     process.env.BUILD_SOURCEVERSION = 'sha';
     process.env.BUILD_BUILDID = 'id-123';
     process.env.BUILD_BUILDNUMBER = 'number-123';
@@ -135,7 +135,7 @@ describe('extensions - ci-info', () => {
     process.env.GITHUB_ACTIONS = 'GITHUB_ACTIONS';
     process.env.GITHUB_SERVER_URL = 'https://github.com';
     process.env.GITHUB_REPOSITORY = 'org/repo';
-    process.env.GITHUB_REF = '/refs/heads/feature-test';
+    process.env.GITHUB_REF = 'refs/heads/feature-test';
     process.env.GITHUB_SHA = 'sha';
     process.env.GITHUB_RUN_ID = 'id-123';
     process.env.GITHUB_RUN_NUMBER = 'number-123';
@@ -178,6 +178,45 @@ describe('extensions - ci-info', () => {
     assert.equal(mock.getInteraction(id).exercised, true);
   });
 
+  it('should send test-summary with multiple suites and ci information to slack', async () => {
+    process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = 'https://dev.azure.com/';
+    process.env.SYSTEM_TEAMPROJECT = 'test';
+    process.env.BUILD_REPOSITORY_URI = 'https://github.com/test/test';
+    process.env.BUILD_REPOSITORY_NAME = 'test/test';
+    process.env.BUILD_SOURCEBRANCH = 'refs/pull/123/merge';
+    process.env.BUILD_SOURCEVERSION = 'sha';
+    process.env.BUILD_BUILDID = 'id-123';
+    process.env.BUILD_BUILDNUMBER = 'number-123';
+    process.env.BUILD_DEFINITIONNAME = 'Build';
+    const id = mock.addInteraction('post test-summary with multiple suites and ci-info to to slack');
+    await publish({
+      config: {
+        targets: [
+          {
+            name: 'slack',
+            inputs: {
+              url: 'http://localhost:9393/message'
+            },
+            extensions: [
+              {
+                name: 'ci-info'
+              }
+            ]
+          }
+        ],
+        results: [
+          {
+            type: 'testng',
+            files: [
+              'test/data/testng/multiple-suites.xml'
+            ]
+          }
+        ]
+      }
+    });
+    assert.equal(mock.getInteraction(id).exercised, true);
+  });
+
   afterEach(() => {
     mock.clearInteractions();
   });
diff --git a/test/mocks/chat.mock.js b/test/mocks/chat.mock.js
index f039138..1d92aaa 100644
--- a/test/mocks/chat.mock.js
+++ b/test/mocks/chat.mock.js
@@ -566,7 +566,7 @@ addInteractionHandler('post test-summary with ci-info to chat', () => {
                 "widgets": [
                   {
                     "textParagraph": {
-                      "text": "<b>Repository:</b> <a href=\"https://github.com/org/repo\">org/repo</a> ｜ <b>Branch:</b> <a href=\"https://github.com/org/repo/tree/feature-test\">/feature-test</a><br><b>Build:</b> <a href=\"https://github.com/org/repo/actions/runs/id-123\">Build #number-123</a> ｜ <a href=\"LOGS_URL\">Download Logs</a>"
+                      "text": "<b>Repository:</b> <a href=\"https://github.com/org/repo\">org/repo</a> ｜ <b>Branch:</b> <a href=\"https://github.com/org/repo/tree/feature-test\">feature-test</a><br><b>Build:</b> <a href=\"https://github.com/org/repo/actions/runs/id-123\">Build #number-123</a> ｜ <a href=\"LOGS_URL\">Download Logs</a>"
                     }
                   }
                 ]
diff --git a/test/mocks/slack.mock.js b/test/mocks/slack.mock.js
index ce42c68..b23eb1c 100644
--- a/test/mocks/slack.mock.js
+++ b/test/mocks/slack.mock.js
@@ -631,7 +631,7 @@ addInteractionHandler('post test-summary with ci-info to slack', () => {
                 "type": "section",
                 "text": {
                   "type": "mrkdwn",
-                  "text": "*Repository:* <https://github.com/test/test|test/test> ｜ *Pull Request:* <https://github.com/test/test/pull/123/merge|/123>\n*Build:* <https://dev.azure.com/test/_build/results?buildId=id-123|Build #number-123>"
+                  "text": "*Repository:* <https://github.com/test/test|test/test> ｜ *Pull Request:* <https://github.com/test/test/pull/123/merge|123>\n*Build:* <https://dev.azure.com/test/_build/results?buildId=id-123|Build #number-123>"
                 }
               }
             ]
@@ -643,4 +643,41 @@ addInteractionHandler('post test-summary with ci-info to slack', () => {
       status: 200
     }
   }
+});
+
+addInteractionHandler('post test-summary with multiple suites and ci-info to to slack', () => {
+  return {
+    request: {
+      method: 'POST',
+      path: '/message',
+      body: {
+        "attachments": [
+          {
+            "color": "#DC143C",
+            "blocks": [
+              {
+                "@DATA:TEMPLATE@": "SLACK_ROOT_MULTIPLE_SUITES"
+              },
+              {
+                "type": "section",
+                "text": {
+                  "type": "mrkdwn",
+                  "text": "*Repository:* <https://github.com/test/test|test/test> ｜ *Pull Request:* <https://github.com/test/test/pull/123/merge|123>\n*Build:* <https://dev.azure.com/test/_build/results?buildId=id-123|Build #number-123>"
+                }
+              },
+              {
+                "@DATA:TEMPLATE@": "SLACK_SUITE_CHROME"
+              },
+              {
+                "@DATA:TEMPLATE@": "SLACK_SUITE_IOS"
+              }
+            ]
+          }
+        ]
+      }
+    },
+    response: {
+      status: 200
+    }
+  }
 });
\ No newline at end of file
diff --git a/test/mocks/teams.mock.js b/test/mocks/teams.mock.js
index 7ff965d..534e15d 100644
--- a/test/mocks/teams.mock.js
+++ b/test/mocks/teams.mock.js
@@ -1556,7 +1556,7 @@ addInteractionHandler('post test-summary with ci-info to teams', () => {
                 },
                 {
                   "type": "TextBlock",
-                  "text": "**Repository:** [test/test](https://github.com/test/test) ｜ **Branch:** [/feature-test](https://github.com/test/test/tree/feature-test)\n\n**Build:** [Build #number-123](https://github.com/test/test/actions/runs/id-123)",
+                  "text": "**Repository:** [test/test](https://github.com/test/test) ｜ **Branch:** [feature-test](https://github.com/test/test/tree/feature-test)\n\n**Build:** [Build #number-123](https://github.com/test/test/actions/runs/id-123)",
                   "wrap": true,
                   "separator": true
                 }