From 0fa1a5ce157ba338b482e781c13f193cf660bd1f Mon Sep 17 00:00:00 2001 From: Anudeep Date: Sun, 21 Jul 2024 19:14:18 +0530 Subject: [PATCH] chore: update result name to run name (#226) --- package-lock.json | 4 ++-- package.json | 2 +- src/beats/beats.js | 23 ++++++----------------- src/targets/chat.js | 10 ++++++---- src/targets/slack.js | 23 +++++++++++++---------- src/targets/teams.js | 16 +++++++++------- test/mocks/teams.mock.js | 6 +++--- 7 files changed, 40 insertions(+), 44 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9f8b583..09bd288 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "testbeats", - "version": "2.0.7", + "version": "2.0.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "testbeats", - "version": "2.0.7", + "version": "2.0.8", "license": "ISC", "dependencies": { "async-retry": "^1.3.3", diff --git a/package.json b/package.json index 653537e..148bcae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "testbeats", - "version": "2.0.7", + "version": "2.0.8", "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/beats/beats.js b/src/beats/beats.js index a89e27e..501fa1f 100644 --- a/src/beats/beats.js +++ b/src/beats/beats.js @@ -20,10 +20,14 @@ class Beats { } async publish() { + this.#setApiKey(); + if (!this.config.api_key) { + logger.warn('😿 No API key provided, skipping publishing results to TestBeats Portal...'); + return; + } this.#setCIInfo(); this.#setProjectName(); this.#setRunName(); - this.#setApiKey(); await this.#publishTestResults(); await this.#uploadAttachments(); this.#updateTitleLink(); @@ -45,13 +49,10 @@ class Beats { #setRunName() { this.config.run = this.config.run || process.env.TEST_BEATS_RUN || (this.ci && this.ci.build_name) || 'demo-run'; + this.result.name = this.config.run; } async #publishTestResults() { - if (!this.config.api_key) { - logger.warn('😿 No API key provided, skipping publishing results to TestBeats Portal...'); - return; - } logger.info("🚀 Publishing results to TestBeats Portal..."); try { const payload = this.#getPayload(); @@ -89,18 +90,6 @@ class Beats { } } - #getAllFailedTestCases() { - const test_cases = []; - for (const suite of this.result.suites) { - for (const test of suite.cases) { - if (test.status === 'FAIL') { - test_cases.push(test); - } - } - } - return test_cases; - } - #updateTitleLink() { if (!this.test_run_id) { return; diff --git a/src/targets/chat.js b/src/targets/chat.js index fb74265..0c7c59d 100644 --- a/src/targets/chat.js +++ b/src/targets/chat.js @@ -4,6 +4,7 @@ const extension_manager = require('../extensions'); const { HOOK, STATUS } = require('../helpers/constants'); const PerformanceTestResult = require('performance-results-parser/src/models/PerformanceTestResult'); const { getValidMetrics, getMetricValuesText } = require('../helpers/performance'); +const logger = require('../utils/logger'); async function run({ result, target }) { setTargetInputs(target); @@ -14,6 +15,7 @@ async function run({ result, target }) { } else { await setFunctionalPayload({ result, target, payload, root_payload }); } + logger.info(`🔔 Publishing results to Chat...`); return request.post({ url: target.inputs.url, body: root_payload @@ -144,9 +146,9 @@ async function setPerformancePayload({ result, target, payload, root_payload }) } /** - * + * * @param {object} param0 - * @param {PerformanceTestResult} param0.result + * @param {PerformanceTestResult} param0.result */ async function setPerformanceMainBlock({ result, target, payload }) { const title_text_with_emoji = getTitleTextWithEmoji({ result, target }); @@ -169,9 +171,9 @@ async function setPerformanceMainBlock({ result, target, payload }) { } /** - * + * * @param {object} param0 - * @param {PerformanceTestResult} param0.result + * @param {PerformanceTestResult} param0.result */ async function setTransactionBlock({ result, target, payload }) { if (target.inputs.include_suites) { diff --git a/src/targets/slack.js b/src/targets/slack.js index 8e7b335..78e504b 100644 --- a/src/targets/slack.js +++ b/src/targets/slack.js @@ -2,12 +2,14 @@ const request = require('phin-retry'); const { getPercentage, truncate, getPrettyDuration } = require('../helpers/helper'); const extension_manager = require('../extensions'); const { HOOK, STATUS } = require('../helpers/constants'); +const logger = require('../utils/logger'); const PerformanceTestResult = require('performance-results-parser/src/models/PerformanceTestResult'); const { getValidMetrics, getMetricValuesText } = require('../helpers/performance'); const TestResult = require('test-results-parser/src/models/TestResult'); + const COLORS = { GOOD: '#36A64F', WARNING: '#ECB22E', @@ -23,6 +25,7 @@ async function run({ result, target }) { await setFunctionalPayload({ result, target, payload }); } const message = getRootPayload({ result, target, payload }); + logger.info(`🔔 Publishing results to Slack...`); return request.post({ url: target.inputs.url, body: message @@ -142,10 +145,10 @@ function getFailureDetails(suite) { } /** - * - * @param {object} param0 - * @param {PerformanceTestResult | TestResult} param0.result - * @returns + * + * @param {object} param0 + * @param {PerformanceTestResult | TestResult} param0.result + * @returns */ function getRootPayload({ result, target, payload }) { let color = COLORS.GOOD; @@ -182,9 +185,9 @@ async function setPerformancePayload({ result, target, payload }) { } /** - * - * @param {object} param0 - * @param {PerformanceTestResult} param0.result + * + * @param {object} param0 + * @param {PerformanceTestResult} param0.result */ async function setPerformanceMainBlock({ result, target, payload }) { let text = `*${getTitleText(result, target)}*\n`; @@ -206,9 +209,9 @@ async function setPerformanceMainBlock({ result, target, payload }) { } /** - * - * @param {object} param0 - * @param {PerformanceTestResult} param0.result + * + * @param {object} param0 + * @param {PerformanceTestResult} param0.result */ async function setTransactionBlock({ result, target, payload }) { if (target.inputs.include_suites) { diff --git a/src/targets/teams.js b/src/targets/teams.js index 8a30e4f..293145f 100644 --- a/src/targets/teams.js +++ b/src/targets/teams.js @@ -3,14 +3,15 @@ const { getPercentage, truncate, getPrettyDuration } = require('../helpers/helpe const { getValidMetrics, getMetricValuesText } = require('../helpers/performance'); const extension_manager = require('../extensions'); const { HOOK, STATUS } = require('../helpers/constants'); +const logger = require('../utils/logger'); const TestResult = require('test-results-parser/src/models/TestResult'); const PerformanceTestResult = require('performance-results-parser/src/models/PerformanceTestResult'); /** - * @param {object} param0 - * @param {PerformanceTestResult | TestResult} param0.result - * @returns + * @param {object} param0 + * @param {PerformanceTestResult | TestResult} param0.result + * @returns */ async function run({ result, target }) { setTargetInputs(target); @@ -22,6 +23,7 @@ async function run({ result, target }) { await setFunctionalPayload({ result, target, payload, root_payload }); } setRootPayload(root_payload, payload); + logger.info(`🔔 Publishing results to Teams...`); return request.post({ url: target.inputs.url, body: root_payload @@ -209,8 +211,8 @@ function setRootPayload(root_payload, payload) { } /** - * @param {object} param0 - * @param {PerformanceTestResult} param0.result + * @param {object} param0 + * @param {PerformanceTestResult} param0.result */ async function setMainBlockForPerformance({ result, target, payload }) { const total = result.transactions.length; @@ -245,8 +247,8 @@ async function getFactMetrics({ metrics, target, result }) { } /** - * @param {object} param0 - * @param {PerformanceTestResult} param0.result + * @param {object} param0 + * @param {PerformanceTestResult} param0.result */ async function setTransactionBlock({ result, target, payload }) { if (target.inputs.include_suites) { diff --git a/test/mocks/teams.mock.js b/test/mocks/teams.mock.js index 7765ef7..dd73842 100644 --- a/test/mocks/teams.mock.js +++ b/test/mocks/teams.mock.js @@ -1464,7 +1464,7 @@ addInteractionHandler('post test-summary with beats to teams', () => { "body": [ { "type": "TextBlock", - "text": "[✅ Default suite](http://localhost:9393/reports/test-run-id)", + "text": "[✅ build-name](http://localhost:9393/reports/test-run-id)", "size": "medium", "weight": "bolder", "wrap": true @@ -1542,7 +1542,7 @@ addInteractionHandler('post test-summary with beats to teams with ai failure sum "body": [ { "type": "TextBlock", - "text": "[❌ Default suite](http://localhost:9393/reports/test-run-id)", + "text": "[❌ build-name](http://localhost:9393/reports/test-run-id)", "size": "medium", "weight": "bolder", "wrap": true @@ -1593,7 +1593,7 @@ addInteractionHandler('post test-summary with beats to teams with ai failure sum "body": [ { "type": "TextBlock", - "text": "[❌ Default suite](http://localhost:9393/reports/test-run-id)", + "text": "[❌ build-name](http://localhost:9393/reports/test-run-id)", "size": "medium", "weight": "bolder", "wrap": true