diff --git a/src/commands/publish.js b/src/commands/publish.js index 3669fc9..9e3ad2d 100644 --- a/src/commands/publish.js +++ b/src/commands/publish.js @@ -60,9 +60,12 @@ async function processReport(report) { for (let i = 0; i < parsed_results.length; i++) { const result = parsed_results[i]; + const global_extensions = report.extensions || []; await beats.run(report, result); if (report.targets) { for (const target of report.targets) { + target.extensions = target.extensions || []; + target.extensions = global_extensions.concat(target.extensions); await target_manager.run(target, result); } } else { diff --git a/src/index.d.ts b/src/index.d.ts index 3c0be10..d4d391f 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -228,6 +228,7 @@ export interface PublishReport { run?: string; show_failure_summary?: boolean; targets?: Target[]; + extensions?: Extension[]; results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[]; } @@ -236,6 +237,7 @@ export interface PublishConfig { project?: string; run?: string; targets?: Target[]; + extensions?: Extension[]; results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[]; } diff --git a/test/ext-global.spec.js b/test/ext-global.spec.js new file mode 100644 index 0000000..3d81dcf --- /dev/null +++ b/test/ext-global.spec.js @@ -0,0 +1,129 @@ +const { mock } = require('pactum'); +const assert = require('assert'); +const { publish } = require('../src'); + +describe('global extensions', () => { + + afterEach(() => { + mock.clearInteractions(); + }); + + it('with global extensions', async () => { + const id = mock.addInteraction('post test-summary with metadata to teams'); + await publish({ + config: { + "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(id).exercised, true); + }); + + it('with global and normal extensions', async () => { + const id = mock.addInteraction('post test-summary with metadata and hyperlinks to teams'); + await publish({ + config: { + "targets": [ + { + "name": "teams", + "inputs": { + "url": "http://localhost:9393/message" + }, + "extensions": [ + { + "name": "hyperlinks", + "inputs": { + "links": [ + { + "text": "Pipeline", + "url": "some-url" + }, + { + "text": "Video", + "url": "some-url", + "condition": "pass" + } + ] + } + } + ], + } + ], + "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(id).exercised, true); + }); + +}); \ No newline at end of file diff --git a/test/mocks/teams.mock.js b/test/mocks/teams.mock.js index 7f7e9e1..1a353cb 100644 --- a/test/mocks/teams.mock.js +++ b/test/mocks/teams.mock.js @@ -1587,4 +1587,50 @@ addInteractionHandler('post test-summary to teams with strict as false', () => { status: 200 } } +}); + +addInteractionHandler('post test-summary with metadata and hyperlinks 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" + }, + { + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE", + }, + { + "type": "TextBlock", + "text": "**Browser:** Chrome | 1920*1080 | [Pipeline](some-url)", + "wrap": true, + "separator": true + }, + { + "type": "TextBlock", + "text": "[Pipeline](some-url) | [Video](some-url)", + "separator": true, + "wrap": true + } + ], + "actions": [] + } + } + ] + } + }, + response: { + status: 200 + } + } }); \ No newline at end of file