Skip to content

Commit

Permalink
qase-javascript-commons: add logic for supporting multiple IDs
Browse files Browse the repository at this point in the history
Move this logic from the Playwright reporter to the abstract reporter
  • Loading branch information
Dmitrii Gridnev committed Apr 4, 2024
1 parent cc2e34f commit 130c462
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
3 changes: 1 addition & 2 deletions qase-javascript-commons/src/models/test-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Attachment } from './attachment';
import { TestExecution } from './test-execution';



// export type TestResultType = {
// id: string;
// testOpsId: number[];
Expand All @@ -23,7 +22,7 @@ export type TestResultType = {
title: string
signature: string
run_id: number | null
testops_id: number | null
testops_id: number | number[] | null
execution: TestExecution
fields: Map<string, string>
attachments: Attachment[]
Expand Down
2 changes: 1 addition & 1 deletion qase-javascript-commons/src/qase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class QaseReporter extends AbstractReporter {
/**
* @param {TestResultType} result
*/
public addTestResult(result: TestResultType) {
public override addTestResult(result: TestResultType) {
if (!this.disabled) {
this.logTestItem(result);

Expand Down
40 changes: 30 additions & 10 deletions qase-javascript-commons/src/reporters/abstract-reporter.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { AxiosError } from 'axios';
import get from 'lodash.get';

import { TestResultType } from '../models';

import { QaseError } from '../utils/qase-error';
import { isAxiosError } from '../utils/is-axios-error';
import { v4 as uuidv4 } from 'uuid';

export interface LoggerInterface {
log(message: string): void;
group(): void;
groupEnd(): void;
}

export type ReporterOptionsType = {
export interface ReporterOptionsType {
debug?: boolean | undefined;
};
}

export interface ReporterInterface {
addTestResult(result: TestResultType): void;
Expand All @@ -33,15 +32,10 @@ export abstract class AbstractReporter implements ReporterInterface {
* @type {boolean | undefined}
* @private
*/
private debug: boolean | undefined;
private readonly debug: boolean | undefined;

protected results: TestResultType[] = [];

/**
* @param {TestResultType} result
*/
abstract addTestResult(result: TestResultType): void;

/**
* @returns {Promise<void>}
*/
Expand All @@ -68,6 +62,32 @@ export abstract class AbstractReporter implements ReporterInterface {
return this.results;
}

/**
* @param {TestResultType} result
*/
public addTestResult(result: TestResultType) {
if (result.testops_id === null || !Array.isArray(result.testops_id)) {
this.results.push(result);
return;
}

// if we have multiple ids, we need to create multiple test results and set duration to 0 for all but the first one
let firstCase = true;

for (const id of result.testops_id) {
const testResultCopy = { ...result };
testResultCopy.testops_id = id;
testResultCopy.id = uuidv4();

if (!firstCase) {
testResultCopy.execution.duration = 0;
}

firstCase = false;
this.results.push(testResultCopy);
}
}

/**
* @param {TestResultType[]} results
*/
Expand Down
9 changes: 1 addition & 8 deletions qase-javascript-commons/src/reporters/report-reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractReporter, LoggerInterface, ReporterOptionsType } from './abstract-reporter';
import { Report, TestResultType, TestStatusEnum, TestStepType } from '../models';
import { Report, TestStatusEnum, TestStepType } from '../models';
import { WriterInterface } from '../writer';
import { HostData } from '../models/host-data';
import * as os from 'os';
Expand Down Expand Up @@ -34,13 +34,6 @@ export class ReportReporter extends AbstractReporter {
this.runId = runId;
}

/**
* @param {TestResultType} result
*/
public addTestResult(result: TestResultType) {
this.results.push(result);
}

/**
* @returns {Promise<void>}
*
Expand Down
9 changes: 1 addition & 8 deletions qase-javascript-commons/src/reporters/testops-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ export class TestOpsReporter extends AbstractReporter {
this.chunk = options.chunk ?? defaultChunkSize;
}

/**
* @param {TestResultType} result
*/
public addTestResult(result: TestResultType) {
this.results.push(result);
}

/**
* @returns {Promise<void>}
*/
Expand Down Expand Up @@ -210,7 +203,7 @@ export class TestOpsReporter extends AbstractReporter {
return {
title: result.title,
execution: this.getExecution(result.execution),
testops_id: result.testops_id,
testops_id: Array.isArray(result.testops_id) ? null : result.testops_id,
attachments: attachments,
steps: steps,
params: {},
Expand Down

0 comments on commit 130c462

Please sign in to comment.