Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add healthcheck function to avoid breaking tests #117

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that for one test run it will be enough to check connection once and write the connection status to the class property to check it inside of other methods.
In this case, even when the RP goes up during the test run, the reporter will not send events to a non-existent run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the problem I found on testing that approach was, when RP is unavailable during the run, it failed the test suite even if the tests passed. So I choose to add that verification in all methods

} 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