From 5bf81fa78c1e918df57015b3d33dc8acce75dddb Mon Sep 17 00:00:00 2001 From: Anudeep Date: Sun, 1 Sep 2024 18:21:52 +0530 Subject: [PATCH] chore: suite metadata hostname and device --- package-lock.json | 18 +++++++++--------- package.json | 4 ++-- src/extensions/error-clusters.extension.js | 3 ++- src/helpers/helper.js | 8 +++++++- src/platforms/base.platform.js | 14 ++++++++++++-- test/mocks/chat.mock.js | 2 +- test/mocks/slack.mock.js | 4 ++-- test/mocks/teams.mock.js | 4 ++-- 8 files changed, 37 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index caf7f24..f5f4f0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "testbeats", - "version": "2.1.1", + "version": "2.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "testbeats", - "version": "2.1.1", + "version": "2.1.2", "license": "ISC", "dependencies": { "async-retry": "^1.3.3", @@ -18,7 +18,7 @@ "pretty-ms": "^7.0.1", "rosters": "0.0.1", "sade": "^1.8.1", - "test-results-parser": "0.2.4" + "test-results-parser": "0.2.5" }, "bin": { "testbeats": "src/cli.js" @@ -2440,9 +2440,9 @@ } }, "node_modules/test-results-parser": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/test-results-parser/-/test-results-parser-0.2.4.tgz", - "integrity": "sha512-hVGHxyvQ0TrtbRlyriMyA9ntiTldcyWcRzRGPDMYjtcRcNY3Bfnuv5SCcTulgqTsVDvM673Sx7J1YSV3j/PiJA==", + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/test-results-parser/-/test-results-parser-0.2.5.tgz", + "integrity": "sha512-hCrquOqISLzPOj9YST/4s5tLX0d5kOKIlbpmQ0DzsVZz2ag83ZBp/H637jZh6Endjqrg1MjsEYfHMCGM5uzvhQ==", "dependencies": { "fast-xml-parser": "^4.4.1", "globrex": "^0.1.2", @@ -4163,9 +4163,9 @@ } }, "test-results-parser": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/test-results-parser/-/test-results-parser-0.2.4.tgz", - "integrity": "sha512-hVGHxyvQ0TrtbRlyriMyA9ntiTldcyWcRzRGPDMYjtcRcNY3Bfnuv5SCcTulgqTsVDvM673Sx7J1YSV3j/PiJA==", + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/test-results-parser/-/test-results-parser-0.2.5.tgz", + "integrity": "sha512-hCrquOqISLzPOj9YST/4s5tLX0d5kOKIlbpmQ0DzsVZz2ag83ZBp/H637jZh6Endjqrg1MjsEYfHMCGM5uzvhQ==", "requires": { "fast-xml-parser": "^4.4.1", "globrex": "^0.1.2", diff --git a/package.json b/package.json index fb26683..3c873b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "testbeats", - "version": "2.1.1", + "version": "2.1.2", "description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB", "main": "src/index.js", "types": "./src/index.d.ts", @@ -55,7 +55,7 @@ "pretty-ms": "^7.0.1", "rosters": "0.0.1", "sade": "^1.8.1", - "test-results-parser": "0.2.4" + "test-results-parser": "0.2.5" }, "devDependencies": { "c8": "^7.12.0", diff --git a/src/extensions/error-clusters.extension.js b/src/extensions/error-clusters.extension.js index 5bec801..21f4f73 100644 --- a/src/extensions/error-clusters.extension.js +++ b/src/extensions/error-clusters.extension.js @@ -1,5 +1,6 @@ const { BaseExtension } = require('./base.extension'); const { STATUS, HOOK } = require("../helpers/constants"); +const { truncate } = require('../helpers/helper'); class ErrorClustersExtension extends BaseExtension { @@ -35,7 +36,7 @@ class ErrorClustersExtension extends BaseExtension { const texts = []; for (const cluster of clusters) { - texts.push(`${cluster.failure} - ${this.bold(`(x${cluster.count})`)}`); + texts.push(`${truncate(cluster.failure, 150)} - ${this.bold(`(x${cluster.count})`)}`); } this.text = this.mergeTexts(texts); } diff --git a/src/helpers/helper.js b/src/helpers/helper.js index 41ec01b..b632841 100644 --- a/src/helpers/helper.js +++ b/src/helpers/helper.js @@ -46,9 +46,15 @@ function processData(data) { return data; } +/** + * + * @param {string} text + * @param {number} length + * @returns + */ function truncate(text, length) { if (text && text.length > length) { - return text.slice(0, length) + "..."; + return text.slice(0, length).trim() + "..."; } else { return text; } diff --git a/src/platforms/base.platform.js b/src/platforms/base.platform.js index b4c0417..2696f37 100644 --- a/src/platforms/base.platform.js +++ b/src/platforms/base.platform.js @@ -103,12 +103,22 @@ class BasePlatform { const texts = []; + // webdriver io + if (suite.metadata.device && typeof suite.metadata.device === 'string') { + texts.push(`${suite.metadata.device}`); + } + if (suite.metadata.platform && suite.metadata.platform.name && suite.metadata.platform.version) { - texts.push(`${suite.metadata.platform.name} ${suite.metadata.platform.version}`) + texts.push(`${suite.metadata.platform.name} ${suite.metadata.platform.version}`); } if (suite.metadata.browser && suite.metadata.browser.name && suite.metadata.browser.version) { - texts.push(`${suite.metadata.browser.name} ${suite.metadata.browser.version}`) + texts.push(`${suite.metadata.browser.name} ${suite.metadata.browser.version}`); + } + + // playwright + if (suite.metadata.hostname && typeof suite.metadata.hostname === 'string') { + texts.push(`${suite.metadata.hostname}`); } return texts.join(' • '); diff --git a/test/mocks/chat.mock.js b/test/mocks/chat.mock.js index d6c4270..f6b83d6 100644 --- a/test/mocks/chat.mock.js +++ b/test/mocks/chat.mock.js @@ -605,7 +605,7 @@ addInteractionHandler('post test-summary with suite metadata to chat', () => { "widgets": [ { "textParagraph": { - "text": "✅ Addition

Results: 1 / 1 Passed (100%)
Duration: 1ms

Windows 11 • firefox 129.0

✅ Addition

Results: 1 / 1 Passed (100%)
Duration: 1ms

Windows 11 • chrome 129.0" + "text": "✅ Addition

Results: 1 / 1 Passed (100%)
Duration: 1ms

Desktop • Windows 11 • firefox 129.0

✅ Addition

Results: 1 / 1 Passed (100%)
Duration: 1ms

Desktop • Windows 11 • chrome 129.0" } } ] diff --git a/test/mocks/slack.mock.js b/test/mocks/slack.mock.js index bcfce9c..7a7f33e 100644 --- a/test/mocks/slack.mock.js +++ b/test/mocks/slack.mock.js @@ -853,14 +853,14 @@ addInteractionHandler('post test-summary to slack with suite metadata', () => { "type": "section", "text": { "type": "mrkdwn", - "text": "*✅ Addition*\n\n*Results*: 1 / 1 Passed (100%)\n*Duration*: 1ms\n\nWindows 11 • firefox 129.0" + "text": "*✅ Addition*\n\n*Results*: 1 / 1 Passed (100%)\n*Duration*: 1ms\n\nDesktop • Windows 11 • firefox 129.0" } }, { "type": "section", "text": { "type": "mrkdwn", - "text": "*✅ Addition*\n\n*Results*: 1 / 1 Passed (100%)\n*Duration*: 1ms\n\nWindows 11 • chrome 129.0" + "text": "*✅ Addition*\n\n*Results*: 1 / 1 Passed (100%)\n*Duration*: 1ms\n\nDesktop • Windows 11 • chrome 129.0" } } ], diff --git a/test/mocks/teams.mock.js b/test/mocks/teams.mock.js index 90c3abb..486772e 100644 --- a/test/mocks/teams.mock.js +++ b/test/mocks/teams.mock.js @@ -1849,7 +1849,7 @@ addInteractionHandler('post test-summary with suite metadata to teams', () => { }, { "type": "TextBlock", - "text": "Windows 11 • firefox 129.0", + "text": "Desktop • Windows 11 • firefox 129.0", "wrap": true }, { @@ -1874,7 +1874,7 @@ addInteractionHandler('post test-summary with suite metadata to teams', () => { }, { "type": "TextBlock", - "text": "Windows 11 • chrome 129.0", + "text": "Desktop • Windows 11 • chrome 129.0", "wrap": true } ],