qase-javascript-commons 2.2.18 → 2.3.0

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.
Files changed (41) hide show
  1. package/changelog.md +21 -15
  2. package/dist/client/clientV1.d.ts +31 -0
  3. package/dist/client/clientV1.js +177 -0
  4. package/dist/client/clientV2.d.ts +26 -0
  5. package/dist/client/clientV2.js +197 -0
  6. package/dist/client/dateUtils.d.ts +2 -0
  7. package/dist/client/dateUtils.js +21 -0
  8. package/dist/client/interface.d.ts +6 -0
  9. package/dist/client/interface.js +2 -0
  10. package/dist/config/config-validation-schema.js +0 -22
  11. package/dist/env/env-enum.d.ts +1 -2
  12. package/dist/env/env-enum.js +0 -1
  13. package/dist/env/env-to-config.js +0 -1
  14. package/dist/env/env-type.d.ts +2 -3
  15. package/dist/env/env-validation-schema.js +0 -4
  16. package/dist/formatter/json-formatter.d.ts +2 -2
  17. package/dist/formatter/jsonp-formatter.d.ts +2 -2
  18. package/dist/models/attachment.d.ts +2 -2
  19. package/dist/models/config/TestOpsOptionsType.d.ts +25 -0
  20. package/dist/models/config/TestOpsOptionsType.js +2 -0
  21. package/dist/models/execution-sum.d.ts +2 -2
  22. package/dist/models/host-data.d.ts +2 -1
  23. package/dist/models/report.d.ts +3 -3
  24. package/dist/models/short-result.d.ts +2 -2
  25. package/dist/models/stats.d.ts +2 -2
  26. package/dist/models/test-result.d.ts +6 -6
  27. package/dist/options/options-type.d.ts +2 -6
  28. package/dist/qase.d.ts +1 -0
  29. package/dist/qase.js +16 -53
  30. package/dist/reporters/index.d.ts +1 -1
  31. package/dist/reporters/testops-reporter.d.ts +8 -161
  32. package/dist/reporters/testops-reporter.js +24 -537
  33. package/dist/state/state.js +1 -0
  34. package/dist/steps/step.d.ts +1 -1
  35. package/dist/steps/step.js +2 -2
  36. package/dist/utils/hostData.js +6 -3
  37. package/dist/utils/logger.js +17 -23
  38. package/dist/writer/fs-writer.d.ts +3 -3
  39. package/package.json +3 -2
  40. package/dist/utils/custom-boundary.d.ts +0 -26
  41. package/dist/utils/custom-boundary.js +0 -30
@@ -1,7 +1,7 @@
1
1
  import { FormatterInterface } from './formatter-interface';
2
- export type JsonpFormatterOptionsType = {
2
+ export interface JsonpFormatterOptionsType {
3
3
  space?: number | undefined;
4
- };
4
+ }
5
5
  /**
6
6
  * @class JsonFormatter
7
7
  * @implements FormatterInterface
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
- export type Attachment = {
2
+ export interface Attachment {
3
3
  file_name: string;
4
4
  mime_type: string;
5
5
  file_path: string | null;
6
6
  content: string | Buffer;
7
7
  size: number;
8
8
  id: string;
9
- };
9
+ }
@@ -0,0 +1,25 @@
1
+ export interface TestOpsOptionsType {
2
+ project: string;
3
+ uploadAttachments?: boolean | undefined;
4
+ api: TestOpsApiType;
5
+ run: TestOpsRunType;
6
+ plan: TestOpsPlanType;
7
+ batch?: TestOpsBatchType;
8
+ defect?: boolean | undefined;
9
+ }
10
+ export interface TestOpsRunType {
11
+ id?: number | undefined;
12
+ title?: string;
13
+ description?: string;
14
+ complete?: boolean | undefined;
15
+ }
16
+ export interface TestOpsPlanType {
17
+ id?: number | undefined;
18
+ }
19
+ export interface TestOpsBatchType {
20
+ size?: number | undefined;
21
+ }
22
+ export interface TestOpsApiType {
23
+ token: string;
24
+ host?: string | undefined;
25
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
- export type ExecutionSum = {
1
+ export interface ExecutionSum {
2
2
  start_time: number;
3
3
  end_time: number;
4
4
  duration: number;
5
5
  cumulative_duration: number;
6
- };
6
+ }
@@ -9,5 +9,6 @@ export interface HostData {
9
9
  framework: string;
10
10
  reporter: string;
11
11
  commons: string;
12
- apiClient: string;
12
+ apiClientV1: string;
13
+ apiClientV2: string;
13
14
  }
@@ -2,13 +2,13 @@ import { HostData } from './host-data';
2
2
  import { ShortResult } from './short-result';
3
3
  import { Stats } from './stats';
4
4
  import { ExecutionSum } from './execution-sum';
5
- export type Report = {
5
+ export interface Report {
6
6
  environment: string;
7
7
  execution: ExecutionSum;
8
8
  host_data: HostData;
9
9
  results: ShortResult[];
10
10
  stats: Stats;
11
- suites: any[];
11
+ suites: string[];
12
12
  threads: string[];
13
13
  title: string;
14
- };
14
+ }
@@ -1,7 +1,7 @@
1
- export type ShortResult = {
1
+ export interface ShortResult {
2
2
  id: string;
3
3
  title: string;
4
4
  status: string;
5
5
  duration: number;
6
6
  thread: string | null;
7
- };
7
+ }
@@ -1,8 +1,8 @@
1
- export type Stats = {
1
+ export interface Stats {
2
2
  passed: number;
3
3
  failed: number;
4
4
  skipped: number;
5
5
  broken: number;
6
6
  muted: number;
7
7
  total: number;
8
- };
8
+ }
@@ -19,13 +19,13 @@ export declare class TestResultType {
19
19
  message: string | null;
20
20
  constructor(title: string);
21
21
  }
22
- export type Relation = {
22
+ export interface Relation {
23
23
  suite?: Suite;
24
- };
25
- export type Suite = {
24
+ }
25
+ export interface Suite {
26
26
  data: SuiteData[];
27
- };
28
- export type SuiteData = {
27
+ }
28
+ export interface SuiteData {
29
29
  title: string;
30
30
  public_id: number | null;
31
- };
31
+ }
@@ -1,13 +1,9 @@
1
- import { QaseApiOptionsType } from 'qaseio/dist/qaseio';
2
1
  import { ModeEnum } from './mode-enum';
3
- import { TestOpsOptionsType } from '../reporters';
4
2
  import { DriverEnum, FsWriterOptionsType } from '../writer';
3
+ import { TestOpsOptionsType } from '../models/config/TestOpsOptionsType';
5
4
  type RecursivePartial<T> = {
6
5
  [K in keyof T]?: RecursivePartial<T[K]> | undefined;
7
6
  };
8
- export type AdditionalTestOpsOptionsType = {
9
- api?: RecursivePartial<QaseApiOptionsType>;
10
- };
11
7
  export type ConnectionsType = {
12
8
  [DriverEnum.local]?: FsWriterOptionsType;
13
9
  };
@@ -25,7 +21,7 @@ export type OptionsType = {
25
21
  debug?: boolean | undefined;
26
22
  environment?: string | undefined;
27
23
  rootSuite?: string | undefined;
28
- testops?: (RecursivePartial<TestOpsOptionsType> & AdditionalTestOpsOptionsType) | undefined;
24
+ testops?: RecursivePartial<TestOpsOptionsType> | undefined;
29
25
  report?: RecursivePartial<AdditionalReportOptionsType> | undefined;
30
26
  };
31
27
  export type FrameworkOptionsType<F extends string, O> = {
package/dist/qase.d.ts CHANGED
@@ -4,6 +4,7 @@ export interface ReporterInterface {
4
4
  addTestResult(result: TestResultType): Promise<void>;
5
5
  publish(): Promise<void>;
6
6
  startTestRun(): void;
7
+ startTestRunAsync(): Promise<void>;
7
8
  isCaptureLogs(): boolean;
8
9
  getResults(): TestResultType[];
9
10
  sendResults(): Promise<void>;
package/dist/qase.js CHANGED
@@ -6,17 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.QaseReporter = void 0;
7
7
  const env_schema_1 = __importDefault(require("env-schema"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
- const qaseio_1 = require("qaseio");
10
9
  const reporters_1 = require("./reporters");
11
10
  const options_1 = require("./options");
12
11
  const env_1 = require("./env");
13
12
  const models_1 = require("./models");
14
13
  const writer_1 = require("./writer");
15
- const custom_boundary_1 = require("./utils/custom-boundary");
16
14
  const disabled_exception_1 = require("./utils/disabled-exception");
17
15
  const logger_1 = require("./utils/logger");
18
16
  const state_1 = require("./state/state");
19
17
  const hostData_1 = require("./utils/hostData");
18
+ const clientV2_1 = require("./client/clientV2");
20
19
  /**
21
20
  * @type {Record<TestStatusEnum, (test: TestResultType) => string>}
22
21
  */
@@ -177,7 +176,7 @@ class QaseReporter {
177
176
  this.useFallback = true;
178
177
  }
179
178
  try {
180
- await this.fallbackReporter?.sendResults();
179
+ await this.fallbackReporter.sendResults();
181
180
  if (this.withState) {
182
181
  state_1.StateManager.setMode(this.options.fallback);
183
182
  }
@@ -210,7 +209,7 @@ class QaseReporter {
210
209
  this.useFallback = true;
211
210
  }
212
211
  try {
213
- await this.fallbackReporter?.complete();
212
+ await this.fallbackReporter.complete();
214
213
  }
215
214
  catch (error) {
216
215
  this.logger.logError('Unable to complete the run in the fallback reporter:', error);
@@ -239,7 +238,7 @@ class QaseReporter {
239
238
  return;
240
239
  }
241
240
  try {
242
- this.startTestRunOperation = this.fallbackReporter?.startTestRun();
241
+ this.startTestRunOperation = this.fallbackReporter.startTestRun();
243
242
  if (this.withState) {
244
243
  state_1.StateManager.setMode(this.options.fallback);
245
244
  }
@@ -291,6 +290,7 @@ class QaseReporter {
291
290
  }
292
291
  return;
293
292
  }
293
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
294
294
  if (!this.useFallback) {
295
295
  this.fallbackReporter.setTestResults(this.upstreamReporter?.getTestResults() ?? []);
296
296
  this.useFallback = true;
@@ -381,41 +381,21 @@ class QaseReporter {
381
381
  * @private
382
382
  */
383
383
  createReporter(mode, options) {
384
- const { frameworkPackage, reporterName, environment, rootSuite, report = {}, testops = {}, } = options;
385
384
  switch (mode) {
386
385
  case options_1.ModeEnum.testops: {
387
- const { api: { token, headers, ...api } = {}, project, run: { title, description, ...run } = {}, plan = {}, batch = {}, useV2, defect, uploadAttachments, } = testops;
388
- if (!token) {
386
+ if (!options.testops?.api?.token) {
389
387
  throw new Error(`Either "testops.api.token" parameter or "${env_1.EnvApiEnum.token}" environment variable is required in "testops" mode`);
390
388
  }
391
- if (!project) {
389
+ if (!options.testops.project) {
392
390
  throw new Error(`Either "testops.project" parameter or "${env_1.EnvTestOpsEnum.project}" environment variable is required in "testops" mode`);
393
391
  }
394
- const apiClient = new qaseio_1.QaseApi({
395
- token,
396
- headers: {
397
- ...headers,
398
- },
399
- ...api,
400
- }, custom_boundary_1.CustomBoundaryFormData);
401
- return new reporters_1.TestOpsReporter(this.logger, {
402
- project,
403
- uploadAttachments,
404
- run: {
405
- title: title ?? `Automated run ${new Date().toISOString()}`,
406
- description: description ?? `${reporterName} automated run`,
407
- ...run,
408
- },
409
- plan,
410
- batch,
411
- useV2,
412
- defect,
413
- }, apiClient, this.withState, environment, rootSuite, api.host);
392
+ const apiClient = new clientV2_1.ClientV2(this.logger, options.testops, options.environment, options.rootSuite);
393
+ 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);
414
394
  }
415
395
  case options_1.ModeEnum.report: {
416
- const localOptions = report.connections?.[writer_1.DriverEnum.local];
396
+ const localOptions = options.report?.connections?.[writer_1.DriverEnum.local];
417
397
  const writer = new writer_1.FsWriter(localOptions);
418
- return new reporters_1.ReportReporter(this.logger, writer, frameworkPackage, reporterName, environment, rootSuite, testops.run?.id);
398
+ return new reporters_1.ReportReporter(this.logger, writer, options.frameworkPackage, options.reporterName, options.environment, options.rootSuite, options.testops?.run?.id);
419
399
  }
420
400
  case options_1.ModeEnum.off:
421
401
  throw new disabled_exception_1.DisabledException();
@@ -431,10 +411,7 @@ class QaseReporter {
431
411
  this.logger.log(resultLogMap[test.execution.status](test));
432
412
  }
433
413
  setWithState(options) {
434
- return options.frameworkName == 'cypress'
435
- || options.frameworkName == ''
436
- || options.frameworkName == null
437
- || options.frameworkName == undefined;
414
+ return options.frameworkName === 'cypress' || !options.frameworkName;
438
415
  }
439
416
  maskToken(token) {
440
417
  if (token.length <= 7) {
@@ -443,25 +420,11 @@ class QaseReporter {
443
420
  return `${token.slice(0, 3)}****${token.slice(-4)}`;
444
421
  }
445
422
  sanitizeOptions(options) {
446
- if (typeof options !== 'object' || options === null) {
447
- return options;
423
+ const sanitized = JSON.parse(JSON.stringify(options));
424
+ if (sanitized.testops?.api?.token) {
425
+ sanitized.testops.api.token = this.maskToken(sanitized.testops.api.token);
448
426
  }
449
- const sanitizedObject = {};
450
- for (const key in options) {
451
- if (Object.prototype.hasOwnProperty.call(options, key)) {
452
- const value = options[key];
453
- if (key === 'token' && typeof value === 'string') {
454
- sanitizedObject[key] = this.maskToken(value);
455
- }
456
- else if (typeof value === 'object' && value !== null) {
457
- sanitizedObject[key] = this.sanitizeOptions(value);
458
- }
459
- else {
460
- sanitizedObject[key] = value;
461
- }
462
- }
463
- }
464
- return sanitizedObject;
427
+ return sanitized;
465
428
  }
466
429
  }
467
430
  exports.QaseReporter = QaseReporter;
@@ -1,3 +1,3 @@
1
1
  export { AbstractReporter, type InternalReporterInterface, } from './abstract-reporter';
2
2
  export { ReportReporter } from './report-reporter';
3
- export { TestOpsReporter, type TestOpsOptionsType } from './testops-reporter';
3
+ export { TestOpsReporter } from './testops-reporter';
@@ -1,28 +1,7 @@
1
- import { QaseApiInterface, ResultStepStatus, TestStepResultCreateStatusEnum } from 'qaseio';
2
1
  import { AbstractReporter } from './abstract-reporter';
3
- import { StepStatusEnum, TestResultType, TestStatusEnum } from '../models';
2
+ import { TestResultType } from '../models';
4
3
  import { LoggerInterface } from '../utils/logger';
5
- export interface TestOpsRunType {
6
- id?: number | undefined;
7
- title: string;
8
- description: string;
9
- complete?: boolean | undefined;
10
- }
11
- export interface TestOpsPlanType {
12
- id?: number | undefined;
13
- }
14
- export interface TestOpsBatchType {
15
- size?: number | undefined;
16
- }
17
- export interface TestOpsOptionsType {
18
- project: string;
19
- uploadAttachments?: boolean | undefined;
20
- run: TestOpsRunType;
21
- plan: TestOpsPlanType;
22
- batch?: TestOpsBatchType;
23
- defect?: boolean | undefined;
24
- useV2?: boolean | undefined;
25
- }
4
+ import { IClient } from '../client/interface';
26
5
  /**
27
6
  * @class TestOpsReporter
28
7
  * @extends AbstractReporter
@@ -30,89 +9,22 @@ export interface TestOpsOptionsType {
30
9
  export declare class TestOpsReporter extends AbstractReporter {
31
10
  private api;
32
11
  private withState;
33
- /**
34
- * @type {Record<TestStatusEnum, string>}
35
- */
36
- static statusMap: Record<TestStatusEnum, string>;
37
- /**
38
- * @type {Record<StepStatusEnum, ResultStepStatus>}
39
- */
40
- static stepStatusMap: Record<StepStatusEnum, ResultStepStatus>;
41
- /**
42
- * @type {Record<StepStatusEnum, ResultStepStatus>}
43
- */
44
- static stepStatusMapV1: Record<StepStatusEnum, TestStepResultCreateStatusEnum>;
45
- /**
46
- * @type {string}
47
- * @private
48
- */
12
+ private projectCode;
49
13
  private readonly baseUrl;
50
- /**
51
- * @type {string}
52
- * @private
53
- */
54
- private readonly projectCode;
55
- /**
56
- * @type {boolean | undefined}
57
- * @private
58
- */
59
- private readonly isUploadAttachments;
60
- /**
61
- * @type {TestOpsRunType}
62
- * @private
63
- */
64
- private run;
65
- /**
66
- * @type { string | undefined}
67
- * @private
68
- */
69
- private readonly environment;
70
- /**
71
- * @type { number | undefined}
72
- * @private
73
- */
74
- private readonly planId;
75
- /**
76
- * @type {TestResultType[]}
77
- * @private
78
- */
79
14
  private readonly batchSize;
80
- /**
81
- * @type {boolean | undefined}
82
- * @private
83
- */
84
- private readonly useV2;
85
- /**
86
- * @type {boolean | undefined}
87
- * @private
88
- */
89
- private readonly defect;
90
- /**
91
- * @type {string | undefined}
92
- * @private
93
- */
94
- private readonly rootSuite;
95
- /**
96
- * @type {number}
97
- * @private
98
- */
15
+ private runId;
99
16
  private firstIndex;
100
- /**
101
- * @type {boolean}
102
- * @private
103
- */
104
17
  private isTestRunReady;
105
18
  private mutex;
106
19
  /**
107
20
  * @param {LoggerInterface} logger
108
- * @param {ReporterOptionsType & TestOpsOptionsType} options
109
- * @param {QaseApiInterface} api
21
+ * @param {IClient} api
110
22
  * @param {boolean} withState
111
- * @param {string | undefined} environment
112
- * @param {string | undefined} rootSuite
23
+ * @param {string} projectCode
113
24
  * @param {string | undefined} baseUrl
25
+ * @param {number | undefined} batchSize
114
26
  */
115
- constructor(logger: LoggerInterface, options: TestOpsOptionsType, api: QaseApiInterface, withState: boolean, environment?: string, rootSuite?: string, baseUrl?: string);
27
+ constructor(logger: LoggerInterface, api: IClient, withState: boolean, projectCode: string, baseUrl?: string, batchSize?: number, runId?: number);
116
28
  /**
117
29
  * @returns {Promise<void>}
118
30
  */
@@ -144,71 +56,6 @@ export declare class TestOpsReporter extends AbstractReporter {
144
56
  * @returns {Promise<void>}
145
57
  */
146
58
  complete(): Promise<void>;
147
- /**
148
- * @param {TestResultType} result
149
- * @returns Promise<ResultCreateV2>
150
- * @private
151
- */
152
- private transformTestResult;
153
- /**
154
- * @param {TestResultType} result
155
- * @returns Promise<ResultCreate>
156
- * @private
157
- */
158
- private transformTestResultV1;
159
- /**
160
- * @returns {ResultExecution}
161
- * @private
162
- * @param {TestExecution} exec
163
- */
164
- private getExecution;
165
- /**
166
- * @param {Relation | null} relation
167
- * @returns {ResultRelations}
168
- * @private
169
- */
170
- private getRelation;
171
- /**
172
- * @param {TestStepType[]} steps
173
- * @param testTitle
174
- * @returns Promise<ResultStep[]>
175
- * @private
176
- */
177
- private transformSteps;
178
- /**
179
- * @param {TestStepType[]} steps
180
- * @param testTitle
181
- * @returns Promise<TestStepResultCreate[]>
182
- * @private
183
- */
184
- private transformStepsV1;
185
- private logEmptyStep;
186
- /**
187
- * @param {string} title
188
- * @param {string} description
189
- * @param {number | undefined} environment
190
- * @returns {Promise<IdResponse>}
191
- * @private
192
- */
193
- private createRun;
194
- /**
195
- * @returns {string}
196
- * @private
197
- */
198
- private getDate;
199
- /**
200
- * @returns {Promise<void>}
201
- * @private
202
- */
203
- private uploadAttachments;
204
- /**
205
- * Process error and throw QaseError
206
- * @param {Error | AxiosError} error
207
- * @param {string} message
208
- * @param {object} model
209
- * @private
210
- */
211
- private processError;
212
59
  /**
213
60
  * @param {string | undefined} url
214
61
  * @return string