Skip to content

Commit

Permalink
feat: expose launch link (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Dec 16, 2023
1 parent 152fc0a commit 23a8906
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const path = require('path');
const debug = require('debug')('codeceptjs:reportportal');
const { isMainThread } = require('worker_threads');
const { clearString } = require('codeceptjs/lib/utils');
const axios = require('axios').default;
const restClient = axios.create();

const {
event, recorder, output, container,
Expand Down Expand Up @@ -94,14 +96,16 @@ module.exports = (config) => {
}

event.dispatcher.on(event.workers.result, async (result) => {
recorder.add(async () => {
await recorder.add(async () => {
output.print(`📋 Writing results to ReportPortal: ${config.projectName} > ${config.endpoint}`);
await _sendResultsToRP(result);
});
});

event.dispatcher.on(event.all.result, async () => {
if (!process.env.RUNS_WITH_WORKERS) {
recorder.add(async () => {
await recorder.add(async () => {
output.print(`📋 Writing results to ReportPortal: ${config.projectName} > ${config.endpoint}`);
await _sendResultsToRP();
});
}
Expand All @@ -117,6 +121,9 @@ module.exports = (config) => {

launchObj = await startLaunch();
await launchObj.promise;
const launchId = (await launchObj.promise).id;
const launchLink = await getRPLink(launchId);
output.print(`📋 ReportPortal Launch Link: ${launchLink}`);

const suiteTempIdArr = [];
const testTempIdArr = [];
Expand Down Expand Up @@ -231,6 +238,12 @@ module.exports = (config) => {
return rpClient.startLaunch(launchOpts);
}

async function getRPLink(launchId) {
const res = await restClient.get(`${config.endpoint}/${config.projectName}/launch?page.page=1&page.size=50&page.sort=startTime%2Cnumber%2CDESC`, { headers: { Authorization: `Bearer ${config.token }`}});
const launch = res.data.content.filter(item => item.uuid === launchId);
return `${config.endpoint.split('api')[0]}ui/#${config.projectName}/launches/all/${launch[0].id}`;
}

async function sendLogToRP({
tempId, level, message, screenshotData,
}) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"dependencies": {
"@reportportal/client-javascript": "5.0.14",
"assert": "2.1.0",
"axios": "1.6.2",
"chai": "4.3.10",
"mocha": "10.2.0",
"playwright": "1.39.0"
Expand Down

0 comments on commit 23a8906

Please sign in to comment.