-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e292ae
commit 872e4f7
Showing
9 changed files
with
326 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const request = require('phin-retry'); | ||
const TestResult = require('test-results-parser/src/models/TestResult'); | ||
|
||
const BASE_URL = "http://localhost:9393"; | ||
|
||
/** | ||
* @param {import('../index').PublishReport} config | ||
* @param {TestResult} result | ||
*/ | ||
async function run(config, result) { | ||
if (config.project && config.build && config.api_key) { | ||
const run_id = await publishTestResults(config, result); | ||
if (run_id) { | ||
attachTestBeatsReportHyperLink(config, run_id); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param {import('../index').PublishReport} config | ||
* @param {TestResult} result | ||
*/ | ||
async function publishTestResults(config, result) { | ||
try { | ||
const response = await request.post({ | ||
url: `${BASE_URL}/api/core/v1/test-runs`, | ||
headers: { | ||
'x-api-key': config.api_key | ||
}, | ||
body: { | ||
project: config.project, | ||
build: config.build, | ||
...result | ||
} | ||
}); | ||
return response.id; | ||
} catch (error) { | ||
console.log("Unable to publish results to TestBeats"); | ||
console.log(error); | ||
} | ||
} | ||
|
||
/** | ||
* @param {import('../index').PublishReport} config | ||
* @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]; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} run_id | ||
* @returns | ||
*/ | ||
function getTestBeatsReportHyperLink(run_id) { | ||
return { | ||
"name": "hyperlinks", | ||
"inputs": { | ||
"links": [ | ||
{ | ||
"text": "Test Beats Report", | ||
"url": `${BASE_URL}/reports/${run_id}` | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
||
module.exports = { run } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const { mock } = require('pactum'); | ||
const assert = require('assert'); | ||
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'); | ||
await publish({ | ||
config: { | ||
api_key: 'api-key', | ||
project: 'project-name', | ||
build: 'build-name', | ||
targets: [ | ||
{ | ||
name: 'teams', | ||
inputs: { | ||
url: 'http://localhost:9393/message' | ||
} | ||
} | ||
], | ||
results: [ | ||
{ | ||
type: 'testng', | ||
files: [ | ||
'test/data/testng/single-suite.xml' | ||
] | ||
} | ||
] | ||
} | ||
}); | ||
assert.equal(mock.getInteraction(id1).exercised, true); | ||
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', | ||
build: '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(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { addInteractionHandler } = require('pactum').handler; | ||
|
||
addInteractionHandler('post test results to testbeats', () => { | ||
return { | ||
strict: false, | ||
request: { | ||
method: 'POST', | ||
path: '/api/core/v1/test-runs' | ||
}, | ||
response: { | ||
status: 200, | ||
body: { | ||
id: 'test-run-id' | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require('./beats.mock'); | ||
require('./custom.mock'); | ||
require('./rp.mock'); | ||
require('./slack.mock'); | ||
|
Oops, something went wrong.