From 8ccf666a326e4a09dc386e4e0eadc55c08433ea7 Mon Sep 17 00:00:00 2001 From: Jonathan Carvalheiro <97020098+Jonathan-Carvalheiro@users.noreply.github.com> Date: Fri, 30 Sep 2022 11:02:52 +0100 Subject: [PATCH] Add healthcheck function to avoid breaking tests --- index.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6cbd07d..5e65565 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,17 @@ const promiseErrorHandler = (promise) => { }); }; +async function healthCheck(rpClient) { + await rpClient.checkConnect().then((response) => { + console.log('You have successfully connected to the server.'); + console.log(`You are using an account: ${response.fullName}`); + }, (error) => { + console.log('Error connection to server'); + console.dir(error); + throw error; + }); +} + class JestReportPortal { constructor(globalConfig, options) { const agentInfo = getAgentInfo(); @@ -49,7 +60,13 @@ class JestReportPortal { } // eslint-disable-next-line no-unused-vars - onRunStart() { + async onRunStart() { + try { + await healthCheck(this.client); + } catch (e) { + this.stop = true; + return {invalid: true} + } const startLaunchObj = getStartLaunchObject(this.reportOptions); const { tempId, promise } = this.client.startLaunch(startLaunchObj); @@ -59,7 +76,13 @@ class JestReportPortal { } // eslint-disable-next-line no-unused-vars - onTestResult(test, testResult) { + async onTestResult(test, testResult) { + try { + await healthCheck(this.client); + } catch (e) { + this.stop = true; + return {invalid: true} + } let suiteDuration = 0; let testDuration = 0; for (let result = 0; result < testResult.testResults.length; result++) { @@ -101,6 +124,12 @@ class JestReportPortal { // eslint-disable-next-line no-unused-vars async onRunComplete() { + try { + await healthCheck(this.client); + } catch (e) { + this.stop = true; + return {invalid: true} + } await Promise.all(this.promises); if (this.reportOptions.launchId) return; const { promise } = this.client.finishLaunch(this.tempLaunchId);