Skip to content

Commit

Permalink
Add healthcheck function to avoid breaking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan-Carvalheiro committed Sep 30, 2022
1 parent 0e6369e commit 3d74cc0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3d74cc0

Please sign in to comment.