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 8ccf666
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 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 @@ -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);

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

0 comments on commit 8ccf666

Please sign in to comment.