Skip to content

Commit

Permalink
feat: global extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep committed Jun 2, 2024
1 parent 25bcd29 commit d1f49d8
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export interface PublishReport {
run?: string;
show_failure_summary?: boolean;
targets?: Target[];
extensions?: Extension[];
results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[];
}

Expand All @@ -236,6 +237,7 @@ export interface PublishConfig {
project?: string;
run?: string;
targets?: Target[];
extensions?: Extension[];
results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[];
}

Expand Down
129 changes: 129 additions & 0 deletions test/ext-global.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});

});
46 changes: 46 additions & 0 deletions test/mocks/teams.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
});

0 comments on commit d1f49d8

Please sign in to comment.