From 23a8906e7e0316665a8916fca7e9b83bc90eff28 Mon Sep 17 00:00:00 2001 From: KobeNguyenT <7845001+kobenguyent@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:26:43 +0100 Subject: [PATCH] feat: expose launch link (#20) --- index.js | 17 +++++++++++++++-- package.json | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index cd6b66b..72ecff4 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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(); }); } @@ -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 = []; @@ -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, }) { diff --git a/package.json b/package.json index d59b28b..642f526 100644 --- a/package.json +++ b/package.json @@ -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"