Skip to content

Commit

Permalink
chore: update result name to run name (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored Jul 21, 2024
1 parent e62a5ff commit 0fa1a5c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 44 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 6 additions & 17 deletions src/beats/beats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/targets/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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 });
Expand All @@ -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) {
Expand Down
23 changes: 13 additions & 10 deletions src/targets/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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`;
Expand All @@ -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) {
Expand Down
16 changes: 9 additions & 7 deletions src/targets/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/mocks/teams.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0fa1a5c

Please sign in to comment.