qase-javascript-commons 2.4.13 → 2.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,13 +3,15 @@ import { StepStatusEnum, TestResultType, TestStatusEnum } from "../models";
3
3
  import { LoggerInterface } from "../utils/logger";
4
4
  import { ClientV1 } from "./clientV1";
5
5
  import { TestOpsOptionsType } from "../models/config/TestOpsOptionsType";
6
+ import { HostData } from "../models/host-data";
6
7
  export declare class ClientV2 extends ClientV1 {
7
8
  private readonly rootSuite;
8
9
  static statusMap: Record<TestStatusEnum, string>;
9
10
  static stepStatusMap: Record<StepStatusEnum, ResultStepStatus>;
10
11
  private readonly resultsClient;
11
- constructor(logger: LoggerInterface, config: TestOpsOptionsType, environment: string | undefined, rootSuite: string | undefined);
12
+ constructor(logger: LoggerInterface, config: TestOpsOptionsType, environment: string | undefined, rootSuite: string | undefined, hostData?: HostData, reporterName?: string, frameworkName?: string);
12
13
  private createApiConfigV2;
14
+ private buildHeaders;
13
15
  uploadResults(runId: number, results: TestResultType[]): Promise<void>;
14
16
  private transformTestResult;
15
17
  private transformParams;
@@ -31,19 +31,79 @@ class ClientV2 extends clientV1_1.ClientV1 {
31
31
  [models_1.StepStatusEnum.skipped]: qase_api_v2_client_1.ResultStepStatus.SKIPPED,
32
32
  };
33
33
  resultsClient;
34
- constructor(logger, config, environment, rootSuite) {
34
+ constructor(logger, config, environment, rootSuite, hostData, reporterName, frameworkName) {
35
35
  super(logger, config, environment);
36
36
  this.rootSuite = rootSuite;
37
- const apiConfig = this.createApiConfigV2();
37
+ const apiConfig = this.createApiConfigV2(hostData, reporterName, frameworkName);
38
38
  this.resultsClient = new qase_api_v2_client_1.ResultsApi(apiConfig);
39
39
  }
40
- createApiConfigV2() {
40
+ createApiConfigV2(hostData, reporterName, frameworkName) {
41
41
  const apiConfig = new qase_api_v2_client_1.Configuration({ apiKey: this.config.api.token, formDataCtor: form_data_1.default });
42
42
  apiConfig.basePath = this.config.api.host && this.config.api.host != API_CONFIG.DEFAULT_HOST
43
43
  ? `${API_CONFIG.BASE_URL}${this.config.api.host}${API_CONFIG.VERSION}`
44
44
  : `https://api.${API_CONFIG.DEFAULT_HOST}${API_CONFIG.VERSION}`;
45
+ // Set default headers for all requests
46
+ if (hostData) {
47
+ const headers = this.buildHeaders(hostData, reporterName, frameworkName);
48
+ const existingHeaders = apiConfig.baseOptions?.headers || {};
49
+ const baseOptionsWithHeaders = {
50
+ ...(apiConfig.baseOptions || {}),
51
+ headers: {
52
+ ...existingHeaders,
53
+ ...headers,
54
+ },
55
+ };
56
+ apiConfig.baseOptions = baseOptionsWithHeaders;
57
+ }
45
58
  return apiConfig;
46
59
  }
60
+ buildHeaders(hostData, reporterName, frameworkName) {
61
+ const headers = {};
62
+ // Build X-Client header
63
+ const clientParts = [];
64
+ if (reporterName && reporterName.trim()) {
65
+ clientParts.push(`reporter=${reporterName}`);
66
+ }
67
+ if (hostData.reporter && hostData.reporter.trim()) {
68
+ clientParts.push(`reporter_version=${hostData.reporter}`);
69
+ }
70
+ if (frameworkName && frameworkName.trim()) {
71
+ clientParts.push(`framework=${frameworkName}`);
72
+ }
73
+ if (hostData.framework && hostData.framework.trim()) {
74
+ clientParts.push(`framework_version=${hostData.framework}`);
75
+ }
76
+ if (hostData.apiClientV1 && hostData.apiClientV1.trim()) {
77
+ clientParts.push(`client_version_v1=${hostData.apiClientV1}`);
78
+ }
79
+ if (hostData.apiClientV2 && hostData.apiClientV2.trim()) {
80
+ clientParts.push(`client_version_v2=${hostData.apiClientV2}`);
81
+ }
82
+ if (hostData.commons && hostData.commons.trim()) {
83
+ clientParts.push(`core_version=${hostData.commons}`);
84
+ }
85
+ if (clientParts.length > 0) {
86
+ headers['X-Client'] = clientParts.join(';');
87
+ }
88
+ // Build X-Platform header
89
+ const platformParts = [];
90
+ if (hostData.system && hostData.system.trim()) {
91
+ platformParts.push(`os=${hostData.system}`);
92
+ }
93
+ if (hostData.arch && hostData.arch.trim()) {
94
+ platformParts.push(`arch=${hostData.arch}`);
95
+ }
96
+ if (hostData.node && hostData.node.trim()) {
97
+ platformParts.push(`node=${hostData.node}`);
98
+ }
99
+ if (hostData.npm && hostData.npm.trim()) {
100
+ platformParts.push(`npm=${hostData.npm}`);
101
+ }
102
+ if (platformParts.length > 0) {
103
+ headers['X-Platform'] = platformParts.join(';');
104
+ }
105
+ return headers;
106
+ }
47
107
  async uploadResults(runId, results) {
48
108
  try {
49
109
  const models = await Promise.all(results.map(result => this.transformTestResult(result)));
@@ -1,9 +1,11 @@
1
- export { TestResultType, Relation, Suite, SuiteData } from './test-result';
1
+ export { TestResultType } from './test-result';
2
+ export type { Relation, Suite, SuiteData } from './test-result';
2
3
  export { TestExecution, TestStatusEnum } from './test-execution';
3
4
  export { TestStepType, StepType } from './test-step';
4
5
  export { StepStatusEnum } from './step-execution';
5
- export { Attachment } from './attachment';
6
- export { Report } from './report';
6
+ export type { Attachment } from './attachment';
7
+ export type { Report } from './report';
7
8
  export { CompoundError } from './error';
8
- export { ConfigurationGroup, ConfigurationItem, ConfigurationGroupResponse } from './configuration';
9
- export { ExternalLinkType, TestOpsOptionsType, TestOpsApiType, TestOpsRunType, TestOpsPlanType, TestOpsBatchType, TestOpsConfigurationType, TestOpsConfigurationValueType, TestOpsExternalLinkType } from './config/TestOpsOptionsType';
9
+ export type { ConfigurationGroup, ConfigurationItem, ConfigurationGroupResponse } from './configuration';
10
+ export { ExternalLinkType } from './config/TestOpsOptionsType';
11
+ export type { TestOpsOptionsType, TestOpsApiType, TestOpsRunType, TestOpsPlanType, TestOpsBatchType, TestOpsConfigurationType, TestOpsConfigurationValueType, TestOpsExternalLinkType } from './config/TestOpsOptionsType';
package/dist/qase.d.ts CHANGED
@@ -46,6 +46,7 @@ export declare class QaseReporter implements ReporterInterface {
46
46
  private startTestRunOperation?;
47
47
  private options;
48
48
  private withState;
49
+ private readonly hostData;
49
50
  /**
50
51
  * @param {OptionsType} options
51
52
  */
package/dist/qase.js CHANGED
@@ -63,6 +63,7 @@ class QaseReporter {
63
63
  startTestRunOperation;
64
64
  options;
65
65
  withState;
66
+ hostData;
66
67
  /**
67
68
  * @param {OptionsType} options
68
69
  */
@@ -94,8 +95,8 @@ class QaseReporter {
94
95
  }
95
96
  this.logger = new logger_1.Logger(loggerOptions);
96
97
  this.logger.logDebug(`Config: ${JSON.stringify(this.sanitizeOptions(composedOptions))}`);
97
- const hostData = (0, hostData_1.getHostInfo)(options.frameworkPackage, options.reporterName);
98
- this.logger.logDebug(`Host data: ${JSON.stringify(hostData)}`);
98
+ this.hostData = (0, hostData_1.getHostInfo)(options.frameworkPackage, options.reporterName);
99
+ this.logger.logDebug(`Host data: ${JSON.stringify(this.hostData)}`);
99
100
  this.captureLogs = composedOptions.captureLogs;
100
101
  try {
101
102
  this.upstreamReporter = this.createReporter(
@@ -448,7 +449,7 @@ class QaseReporter {
448
449
  if (!options.testops.project) {
449
450
  throw new Error(`Either "testops.project" parameter or "${env_1.EnvTestOpsEnum.project}" environment variable is required in "testops" mode`);
450
451
  }
451
- const apiClient = new clientV2_1.ClientV2(this.logger, options.testops, options.environment, options.rootSuite);
452
+ const apiClient = new clientV2_1.ClientV2(this.logger, options.testops, options.environment, options.rootSuite, this.hostData, options.reporterName, options.frameworkPackage);
452
453
  return new reporters_1.TestOpsReporter(this.logger, apiClient, this.withState, options.testops.project, options.testops.api.host, options.testops.batch?.size, options.testops.run?.id, options.testops.showPublicReportLink);
453
454
  }
454
455
  case options_1.ModeEnum.report: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.4.13",
3
+ "version": "2.4.15",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",