Skip to content

Commit

Permalink
feat: testbeats title link (#166)
Browse files Browse the repository at this point in the history
* feat: testbeats title link

* fix env
  • Loading branch information
ASaiAnudeep committed Apr 7, 2024
1 parent f2b291d commit 981211e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 139 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": "test-results-reporter",
"version": "1.1.5",
"version": "1.1.6",
"description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB",
"main": "src/index.js",
"types": "./src/index.d.ts",
Expand Down
35 changes: 10 additions & 25 deletions src/beats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const request = require('phin-retry');
const TestResult = require('test-results-parser/src/models/TestResult');
const { getCIInformation } = require('../helpers/ci');

const BASE_URL = process.env.TEST_BEATS_URL || "http://localhost:9393";
function get_base_url() {
return process.env.TEST_BEATS_URL || "https://app.testbeats.com";
}

/**
* @param {import('../index').PublishReport} config
Expand Down Expand Up @@ -34,7 +36,7 @@ async function publishTestResults(config, result) {
}

const response = await request.post({
url: `${BASE_URL}/api/core/v1/test-runs`,
url: `${get_base_url()}/api/core/v1/test-runs`,
headers: {
'x-api-key': config.api_key
},
Expand All @@ -52,17 +54,10 @@ async function publishTestResults(config, result) {
* @param {string} run_id
*/
function attachTestBeatsReportHyperLink(config, run_id) {
const hyperlink_to_test_beats = getTestBeatsReportHyperLink(run_id);
for (const target of config.targets) {
if (target.name === 'chat' || target.name === 'teams' || target.name === 'slack') {
target.extensions = target.extensions || [];
if (target.extensions.length > 0) {
if (target.extensions[0].name === 'hyperlinks' && target.extensions[0].inputs.links[0].name === 'Test Beats Report') {
target.extensions[0].inputs.links[0].url = `${BASE_URL}/reports/${run_id}`;
continue;
}
}
target.extensions = [hyperlink_to_test_beats, ...target.extensions];
const beats_link = get_test_beats_report_link(run_id);
if (config.targets) {
for (const target of config.targets) {
target.inputs.title_link = beats_link;
}
}
}
Expand All @@ -72,18 +67,8 @@ function attachTestBeatsReportHyperLink(config, run_id) {
* @param {string} run_id
* @returns
*/
function getTestBeatsReportHyperLink(run_id) {
return {
"name": "hyperlinks",
"inputs": {
"links": [
{
"text": "Test Beats Report",
"url": `${BASE_URL}/reports/${run_id}`
}
]
}
}
function get_test_beats_report_link(run_id) {
return `${get_base_url()}/reports/${run_id}`;
}

module.exports = { run }
1 change: 1 addition & 0 deletions test/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ before(async () => {
await mock.start();
// require('./helpers/interactions');
require('./mocks');
process.env.TEST_BEATS_URL = 'http://localhost:9393';
});

after(async () => {
Expand Down
59 changes: 2 additions & 57 deletions test/beats.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const { publish } = require("../src");
describe('TestBeats', () => {

it('should send results to beats', async () => {
const id1 = mock.addInteraction('post test results to testbeats');
const id2 = mock.addInteraction('post test-summary with testbeats to teams');
const id1 = mock.addInteraction('post test results to beats');
const id2 = mock.addInteraction('post test-summary with beats to teams');
await publish({
config: {
api_key: 'api-key',
Expand Down Expand Up @@ -34,61 +34,6 @@ describe('TestBeats', () => {
assert.equal(mock.getInteraction(id2).exercised, true);
});

it('should send results to beats with extensions', async () => {
const id1 = mock.addInteraction('post test results to testbeats');
const id2 = mock.addInteraction('post test-summary with extensions and testbeats to teams');
await publish({
config: {
api_key: 'api-key',
project: 'project-name',
run: 'build-name',
targets: [
{
name: 'teams',
inputs: {
url: 'http://localhost:9393/message'
},
"extensions": [
{
"name": "metadata",
"inputs": {
"data": [
{
"key": "Browser",
"value": "Chrome"
},
{
"value": "1920*1080"
},
{
"value": "1920*1080",
"condition": "never"
},
{
"key": "Pipeline",
"value": "some-url",
"type": "hyperlink"
},
]
}
}
]
}
],
results: [
{
type: 'testng',
files: [
'test/data/testng/single-suite.xml'
]
}
]
}
});
assert.equal(mock.getInteraction(id1).exercised, true);
assert.equal(mock.getInteraction(id2).exercised, true);
});

afterEach(() => {
mock.clearInteractions();
});
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/beats.mock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { addInteractionHandler } = require('pactum').handler;

addInteractionHandler('post test results to testbeats', () => {
addInteractionHandler('post test results to beats', () => {
return {
strict: false,
request: {
Expand Down
58 changes: 5 additions & 53 deletions test/mocks/teams.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ addInteractionHandler('post test-summary with metadata to teams', () => {
}
});

addInteractionHandler('post test-summary with testbeats to teams', () => {
addInteractionHandler('post test-summary with beats to teams', () => {
return {
request: {
method: 'POST',
Expand All @@ -1462,63 +1462,15 @@ addInteractionHandler('post test-summary with testbeats to teams', () => {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE"
},
{
"@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE",
},
{
"type": "TextBlock",
"text": "[Test Beats Report](http://localhost:9393/reports/test-run-id)",
"wrap": true,
"separator": true
}
],
"actions": []
}
}
]
}
},
response: {
status: 200
}
}
});

addInteractionHandler('post test-summary with extensions and testbeats to teams', () => {
return {
request: {
method: 'POST',
path: '/message',
body: {
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE"
"text": "[✅ Default suite](http://localhost:9393/reports/test-run-id)",
"size": "medium",
"weight": "bolder",
"wrap": true
},
{
"@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE",
},
{
"type": "TextBlock",
"text": "[Test Beats Report](http://localhost:9393/reports/test-run-id)",
"wrap": true,
"separator": true
},
{
"type": "TextBlock",
"text": "**Browser:** Chrome | 1920*1080 | [Pipeline](some-url)",
"wrap": true,
"separator": true
}
],
"actions": []
Expand Down

0 comments on commit 981211e

Please sign in to comment.