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

qase-javascript-commons: add support for standard config #525

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ jspm_packages/

# macos artifacts
.DS_Store

# IDE files
.idea
.vscode
36 changes: 27 additions & 9 deletions qase-javascript-commons/src/config/config-validation-schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { JSONSchemaType } from 'ajv';

import { ModeEnum } from '../options';
import { DriverEnum } from '../writer';

import { DriverEnum, FormatEnum } from '../writer';
import { ConfigType } from './config-type';

/**
Expand All @@ -17,6 +16,11 @@ export const configValidationSchema: JSONSchemaType<ConfigType> = {
enum: [ModeEnum.report, ModeEnum.testops, ModeEnum.off],
nullable: true,
},
fallback: {
type: 'string',
enum: [ModeEnum.report, ModeEnum.testops, ModeEnum.off],
nullable: true,
},
debug: {
type: 'boolean',
nullable: true,
Expand Down Expand Up @@ -79,11 +83,6 @@ export const configValidationSchema: JSONSchemaType<ConfigType> = {
nullable: true,
},

baseUrl: {
type: 'string',
nullable: true,
},

run: {
type: 'object',
nullable: true,
Expand All @@ -105,12 +104,30 @@ export const configValidationSchema: JSONSchemaType<ConfigType> = {
type: 'boolean',
nullable: true,
},
environment: {
},
},

plan: {
type: 'object',
nullable: true,

properties: {
id: {
type: 'number',
nullable: true,
},
},
},

chunk: {
type: 'number',
nullable: true,
},

defect: {
type: 'boolean',
nullable: true,
},
},
},

Expand Down Expand Up @@ -140,8 +157,9 @@ export const configValidationSchema: JSONSchemaType<ConfigType> = {
nullable: true,
},

ext: {
format: {
type: 'string',
enum: [FormatEnum.json, FormatEnum.jsonb],
nullable: true,
},
},
Expand Down
20 changes: 14 additions & 6 deletions qase-javascript-commons/src/env/env-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
export enum EnvEnum {
mode = 'QASE_MODE',
fallback = 'QASE_FALLBACK',
debug = 'QASE_DEBUG',
environment = 'QASE_ENVIRONMENT',
}
Expand All @@ -12,16 +13,17 @@ export enum EnvEnum {
*/
export enum EnvTestOpsEnum {
project = 'QASE_TESTOPS_PROJECT',
baseUrl = 'QASE_TESTOPS_BASE_URL',
uploadAttachments = 'QASE_TESTOPS_UPLOAD_ATTACHMENTS',
chunk = 'QASE_TESTOPS_CHUNK',
defect = 'QASE_TESTOPS_DEFECT',
}

/**
* @enum {string}
*/
export enum EnvApiEnum {
token = 'QASE_TESTOPS_API_TOKEN',
baseUrl = 'QASE_TESTOPS_API_BASE_URL',
baseUrl = 'QASE_TESTOPS_API_HOST',
}

/**
Expand All @@ -31,14 +33,20 @@ export enum EnvRunEnum {
id = 'QASE_TESTOPS_RUN_ID',
title = 'QASE_TESTOPS_RUN_TITLE',
description = 'QASE_TESTOPS_RUN_DESCRIPTION',
complete = 'QASE_TESTOPS_RUN_COMPLETE',
environment = 'QASE_TESTOPS_ENVIRONMENT',
complete = 'QASE_TESTOPS_RUN_COMPLETE'
}

/**
* @enum {string}
*/
export enum EnvPlanEnum {
id = 'QASE_TESTOPS_PLAN_ID',
}

/**
* @enum {string}
*/
export enum EnvLocalEnum {
path = 'QASE_REPORT_CONNECTIONS_LOCAL_PATH',
ext = 'QASE_REPORT_CONNECTIONS_LOCAL_EXT',
path = 'QASE_REPORT_CONNECTION_PATH',
format = 'QASE_REPORT_CONNECTION_FORMAT',
}
12 changes: 9 additions & 3 deletions qase-javascript-commons/src/env/env-to-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EnvApiEnum,
EnvRunEnum,
EnvLocalEnum,
EnvPlanEnum,
} from './env-enum';

import { DriverEnum } from '../writer';
Expand All @@ -21,7 +22,6 @@ export const envToConfig = (env: EnvType): ConfigType => ({

testops: {
project: env[EnvTestOpsEnum.project],
baseUrl: env[EnvTestOpsEnum.baseUrl],
uploadAttachments: env[EnvTestOpsEnum.uploadAttachments],

api: {
Expand All @@ -34,15 +34,21 @@ export const envToConfig = (env: EnvType): ConfigType => ({
title: env[EnvRunEnum.title],
description: env[EnvRunEnum.description],
complete: env[EnvRunEnum.complete],
environment: env[EnvRunEnum.environment],
},

plan: {
id: env[EnvPlanEnum.id],
},

chunk: env[EnvTestOpsEnum.chunk],
defect: env[EnvTestOpsEnum.defect],
},

report: {
connections: {
[DriverEnum.local]: {
path: env[EnvLocalEnum.path],
ext: env[EnvLocalEnum.ext],
format: env[EnvLocalEnum.format],
},
},
},
Expand Down
11 changes: 8 additions & 3 deletions qase-javascript-commons/src/env/env-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
EnvApiEnum,
EnvRunEnum,
EnvLocalEnum,
EnvPlanEnum,
} from './env-enum';

import { ModeEnum } from '../options';
import { FormatEnum } from '../writer';

export type EnvType = {

Check warning on line 13 in qase-javascript-commons/src/env/env-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 16

Use an `interface` instead of a `type`

Check warning on line 13 in qase-javascript-commons/src/env/env-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 18

Use an `interface` instead of a `type`
[EnvEnum.mode]?: `${ModeEnum}`;
[EnvEnum.fallback]?: `${ModeEnum}`;
[EnvEnum.debug]?: boolean;
[EnvEnum.environment]?: string | number;

[EnvTestOpsEnum.project]?: string;
[EnvTestOpsEnum.baseUrl]?: string;
[EnvTestOpsEnum.uploadAttachments]?: boolean;
[EnvTestOpsEnum.chunk]?: number;
[EnvTestOpsEnum.defect]?: boolean;

[EnvApiEnum.token]?: string;
[EnvApiEnum.baseUrl]?: string;
Expand All @@ -24,8 +28,9 @@
[EnvRunEnum.title]?: string;
[EnvRunEnum.description]?: string;
[EnvRunEnum.complete]?: boolean;
[EnvRunEnum.environment]?: number;

[EnvPlanEnum.id]?: number;

[EnvLocalEnum.path]?: string;
[EnvLocalEnum.ext]?: string;
[EnvLocalEnum.format]?: `${FormatEnum}`;
};
21 changes: 17 additions & 4 deletions qase-javascript-commons/src/env/env-validation-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
EnvApiEnum,
EnvEnum,
EnvLocalEnum,
EnvPlanEnum,
EnvRunEnum,
EnvTestOpsEnum,
} from './env-enum';

import { ModeEnum } from '../options';
import { FormatEnum } from '../writer';

/**
* @type {JSONSchemaType<EnvType>}
Expand All @@ -23,6 +25,11 @@ export const envValidationSchema: JSONSchemaType<EnvType> = {
enum: [ModeEnum.report, ModeEnum.testops, ModeEnum.off],
nullable: true,
},
[EnvEnum.fallback]: {
type: 'string',
enum: [ModeEnum.report, ModeEnum.testops, ModeEnum.off],
nullable: true,
},
[EnvEnum.debug]: {
type: 'boolean',
nullable: true,
Expand All @@ -40,8 +47,12 @@ export const envValidationSchema: JSONSchemaType<EnvType> = {
type: 'boolean',
nullable: true,
},
[EnvTestOpsEnum.baseUrl]: {
type: 'string',
[EnvTestOpsEnum.chunk]: {
type: 'number',
nullable: true,
},
[EnvTestOpsEnum.defect]: {
type: 'boolean',
nullable: true,
},

Expand Down Expand Up @@ -70,7 +81,8 @@ export const envValidationSchema: JSONSchemaType<EnvType> = {
type: 'boolean',
nullable: true,
},
[EnvRunEnum.environment]: {

[EnvPlanEnum.id]: {
type: 'number',
nullable: true,
},
Expand All @@ -79,8 +91,9 @@ export const envValidationSchema: JSONSchemaType<EnvType> = {
type: 'string',
nullable: true,
},
[EnvLocalEnum.ext]: {
[EnvLocalEnum.format]: {
type: 'string',
enum: [FormatEnum.json, FormatEnum.jsonb],
nullable: true,
},
},
Expand Down
1 change: 1 addition & 0 deletions qase-javascript-commons/src/options/options-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
[K in keyof T]?: RecursivePartial<T[K]> | undefined;
};

export type AdditionalTestOpsOptionsType = {

Check warning on line 12 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 16

Use an `interface` instead of a `type`

Check warning on line 12 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 18

Use an `interface` instead of a `type`
api?: RecursivePartial<QaseApiOptionsType>;
};

export type ConnectionsType = {

Check warning on line 16 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 16

Use an `interface` instead of a `type`

Check warning on line 16 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 18

Use an `interface` instead of a `type`
[DriverEnum.local]?: FsWriterOptionsType;
};

export type AdditionalReportOptionsType = {

Check warning on line 20 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 16

Use an `interface` instead of a `type`

Check warning on line 20 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 18

Use an `interface` instead of a `type`
driver?: `${DriverEnum}`;
connections?: ConnectionsType;
};

export type OptionsType = {

Check warning on line 25 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 16

Use an `interface` instead of a `type`

Check warning on line 25 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 18

Use an `interface` instead of a `type`
frameworkPackage: string;
frameworkName: string;
reporterName: string;
mode?: `${ModeEnum}` | undefined;
fallback?: `${ModeEnum}` | undefined;
debug?: boolean | undefined;
environment?: string | number | undefined;
testops?:
Expand All @@ -35,6 +36,6 @@
report?: RecursivePartial<AdditionalReportOptionsType> | undefined;
};

export type FrameworkOptionsType<F extends string, O> = {

Check warning on line 39 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 16

Use an `interface` instead of a `type`

Check warning on line 39 in qase-javascript-commons/src/options/options-type.ts

View workflow job for this annotation

GitHub Actions / Project qase-javascript-commons - Node 18

Use an `interface` instead of a `type`
framework?: Partial<Record<F, O>>
}
6 changes: 3 additions & 3 deletions qase-javascript-commons/src/qase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ export class QaseReporter extends AbstractReporter {
headers,
...api
} = {},
baseUrl,
project,
run: {
title,
description,
...run
} = {},
plan = {},
uploadAttachments,
} = testops;

Expand Down Expand Up @@ -223,19 +223,19 @@ export class QaseReporter extends AbstractReporter {

return new TestOpsReporter(
{
baseUrl,
project,
uploadAttachments,
run: {
title: title ?? `Automated run ${new Date().toISOString()}`,
description: description ?? `${reporterName} automated run`,
environment: typeof environment === 'number' ? environment : undefined,
...run,
},
plan,
...commonOptions,
},
apiClient,
logger,
typeof environment === 'number' ? environment : undefined
);
}

Expand Down
22 changes: 18 additions & 4 deletions qase-javascript-commons/src/reporters/testops-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ export type TestOpsRunType = {
title: string;
description: string;
complete?: boolean | undefined;
environment?: number | undefined;
};

export type TestOpsPlanType = {
id?: number | undefined;
};

export type TestOpsOptionsType = {
project: string;
baseUrl?: string | undefined;
uploadAttachments?: boolean | undefined;
run: TestOpsRunType;
plan: TestOpsPlanType;
chunk?: number | undefined;
defect?: boolean | undefined;
};

/**
Expand Down Expand Up @@ -92,6 +97,12 @@ export class TestOpsReporter extends AbstractReporter {
*/
private run: TestOpsRunType;

/**
* @type { number | undefined}
* @private
*/
private environment: number | undefined;

/**
* @type {TestResultType[]}
* @private
Expand All @@ -117,10 +128,10 @@ export class TestOpsReporter extends AbstractReporter {
options: ReporterOptionsType & TestOpsOptionsType,
private api: QaseApiInterface,
logger?: LoggerInterface,
environment?: number,
) {
const {
project,
baseUrl = 'https://app.qase.io',
uploadAttachments,
run,

Expand All @@ -129,10 +140,13 @@ export class TestOpsReporter extends AbstractReporter {

super(restOptions, logger);

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

this.baseUrl = baseUrl.replace(/\/$/, '');
this.projectCode = project;
this.uploadAttachments = uploadAttachments;
this.run = { complete: true, ...run };
this.environment = environment;
}

/**
Expand Down Expand Up @@ -169,7 +183,7 @@ export class TestOpsReporter extends AbstractReporter {
const { result } = await this.createRun(
this.run.title,
this.run.description,
this.run.environment,
this.environment,
);

if (!result?.id) {
Expand Down
Loading
Loading