Skip to content

Commit

Permalink
feature: show a link if a test is failed
Browse files Browse the repository at this point in the history
Show the link to the test result in the Qase if the test is failed.
  • Loading branch information
gibiw committed Jun 21, 2024
1 parent cab1d61 commit 6da3d08
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
3 changes: 3 additions & 0 deletions qase-javascript-commons/src/qase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export class QaseReporter implements ReporterInterface {
*/
public async addTestResult(result: TestResultType) {
if (!this.disabled) {
await this.startTestRunOperation;

this.logTestItem(result);

if (this.useFallback) {
Expand Down Expand Up @@ -410,6 +412,7 @@ export class QaseReporter implements ReporterInterface {
apiClient,
environment,
rootSuite,
api.host,
);
}

Expand Down
47 changes: 44 additions & 3 deletions qase-javascript-commons/src/reporters/testops-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ export class TestOpsReporter extends AbstractReporter {
* @param {QaseApiInterface} api
* @param {string | undefined} environment
* @param {string | undefined} rootSuite
* @param {string | undefined} baseUrl
*/
constructor(
logger: LoggerInterface,
options: TestOpsOptionsType,
private api: QaseApiInterface,
environment?: string,
rootSuite?: string,
baseUrl?: string,
) {
const {
project,
Expand All @@ -180,9 +182,7 @@ export class TestOpsReporter extends AbstractReporter {

super(logger);

const baseUrl = 'https://app.qase.io';

this.baseUrl = baseUrl.replace(/\/$/, '');
this.baseUrl = this.getBaseUrl(baseUrl);
this.projectCode = project;
this.isUploadAttachments = uploadAttachments;
this.run = { complete: true, ...run };
Expand All @@ -205,6 +205,19 @@ export class TestOpsReporter extends AbstractReporter {
* @returns {Promise<void>}
*/
public override async addTestResult(result: TestResultType): Promise<void> {
if (result.execution.status === TestStatusEnum.failed) {

if (Array.isArray(result.testops_id)) {
for (const id of result.testops_id) {
const link = this.prepareFailedTestLink(id, result.title);
this.logger.log(chalk`{blue You can see the failed test in Qase: ${link}}`);
}
} else {
const link = this.prepareFailedTestLink(result.testops_id, result.title);
this.logger.log(chalk`{blue You can see the failed test in Qase: ${link}}`);
}
}

await super.addTestResult(result);

if (!this.isTestRunReady) {
Expand Down Expand Up @@ -698,4 +711,32 @@ export class TestOpsReporter extends AbstractReporter {

return new QaseError(message, { cause: error });
}

/**
* @param {string | undefined} url
* @return string
* @private
*/
private getBaseUrl(url: string | undefined): string {
if (!url || url === 'qase.io') {
return 'https://app.qase.io';
}

return `https://${url.replace('api', 'app')}`;
}

/**
* @param {number | null} id
* @param {string} title
* @return string
* @private
*/
private prepareFailedTestLink(id: number | null, title: string): string {
const baseLink = `${this.baseUrl}/run/${this.projectCode}/dashboard/${this.run.id!}?status=%5B2%5D&search=`;
if (id) {
return `${baseLink}${id}`;
}

return `${baseLink}${encodeURI(title)}`;
}
}

0 comments on commit 6da3d08

Please sign in to comment.