diff --git a/index.js b/index.js index 6cbd07d..01c5de9 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(); @@ -46,10 +57,17 @@ class JestReportPortal { this.tempTestIds = new Map(); this.tempStepId = null; this.promises = []; + this.stop = false; } // eslint-disable-next-line no-unused-vars 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); @@ -60,6 +78,7 @@ class JestReportPortal { // eslint-disable-next-line no-unused-vars onTestResult(test, testResult) { + if (this.stop) return {invalid: true}; let suiteDuration = 0; let testDuration = 0; for (let result = 0; result < testResult.testResults.length; result++) { @@ -101,6 +120,7 @@ class JestReportPortal { // eslint-disable-next-line no-unused-vars async onRunComplete() { + if (this.stop) return {invalid: true}; await Promise.all(this.promises); if (this.reportOptions.launchId) return; const { promise } = this.client.finishLaunch(this.tempLaunchId);