diff --git a/package-lock.json b/package-lock.json index 8a587fe..f914cad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "test-results-reporter", - "version": "1.1.5", + "version": "1.1.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "test-results-reporter", - "version": "1.1.5", + "version": "1.1.6", "license": "ISC", "dependencies": { "async-retry": "^1.3.3", diff --git a/package.json b/package.json index c7aeb1b..8ecdaa2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/beats/index.js b/src/beats/index.js index 8697822..24073e4 100644 --- a/src/beats/index.js +++ b/src/beats/index.js @@ -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 @@ -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 }, @@ -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; } } } @@ -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 } \ No newline at end of file diff --git a/test/base.spec.js b/test/base.spec.js index 313d184..e02e1a4 100644 --- a/test/base.spec.js +++ b/test/base.spec.js @@ -4,6 +4,7 @@ before(async () => { await mock.start(); // require('./helpers/interactions'); require('./mocks'); + process.env.TEST_BEATS_URL = 'http://localhost:9393'; }); after(async () => { diff --git a/test/beats.spec.js b/test/beats.spec.js index 459e62a..36e1940 100644 --- a/test/beats.spec.js +++ b/test/beats.spec.js @@ -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', @@ -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(); }); diff --git a/test/mocks/beats.mock.js b/test/mocks/beats.mock.js index 7bcb0ad..ef7c777 100644 --- a/test/mocks/beats.mock.js +++ b/test/mocks/beats.mock.js @@ -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: { diff --git a/test/mocks/teams.mock.js b/test/mocks/teams.mock.js index 534e15d..488bcca 100644 --- a/test/mocks/teams.mock.js +++ b/test/mocks/teams.mock.js @@ -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', @@ -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": []