Skip to content

Commit

Permalink
chore: suite metadata hostname and device (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored Sep 1, 2024
1 parent 0f471ae commit e58016e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/error-clusters.extension.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { BaseExtension } = require('./base.extension');
const { STATUS, HOOK } = require("../helpers/constants");
const { truncate } = require('../helpers/helper');

class ErrorClustersExtension extends BaseExtension {

Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 7 additions & 1 deletion src/helpers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 12 additions & 2 deletions src/platforms/base.platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' • ');
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/chat.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ addInteractionHandler('post test-summary with suite metadata to chat', () => {
"widgets": [
{
"textParagraph": {
"text": "<b>✅ Addition</b><br><br><b>Results</b>: 1 / 1 Passed (100%)<br><b>Duration</b>: 1ms<br><br>Windows 11 • firefox 129.0<br><br><b>✅ Addition</b><br><br><b>Results</b>: 1 / 1 Passed (100%)<br><b>Duration</b>: 1ms<br><br>Windows 11 • chrome 129.0"
"text": "<b>✅ Addition</b><br><br><b>Results</b>: 1 / 1 Passed (100%)<br><b>Duration</b>: 1ms<br><br>Desktop • Windows 11 • firefox 129.0<br><br><b>✅ Addition</b><br><br><b>Results</b>: 1 / 1 Passed (100%)<br><b>Duration</b>: 1ms<br><br>Desktop • Windows 11 • chrome 129.0"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions test/mocks/slack.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions test/mocks/teams.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
{
Expand All @@ -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
}
],
Expand Down

0 comments on commit e58016e

Please sign in to comment.