qase-javascript-commons 2.3.6 → 2.4.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.
@@ -17,6 +17,7 @@ export declare class ClientV1 implements IClient {
17
17
  uploadResults(_runId: number, _results: TestResultType[]): Promise<void>;
18
18
  createRun(): Promise<number>;
19
19
  completeRun(runId: number): Promise<void>;
20
+ uploadAttachment(attachment: Attachment): Promise<string>;
20
21
  protected uploadAttachments(attachments: Attachment[]): Promise<string[]>;
21
22
  private prepareAttachmentData;
22
23
  private getEnvironmentId;
@@ -95,6 +95,16 @@ class ClientV1 {
95
95
  this.logger.log((0, chalk_1.default) `{blue Test run link: ${runUrl}}`);
96
96
  }
97
97
  }
98
+ async uploadAttachment(attachment) {
99
+ try {
100
+ const data = this.prepareAttachmentData(attachment);
101
+ const response = await this.attachmentClient.uploadAttachment(this.config.project, [data]);
102
+ return response.data.result?.[0]?.hash ?? '';
103
+ }
104
+ catch (error) {
105
+ throw this.processError(error, 'Error on uploading attachment');
106
+ }
107
+ }
98
108
  async uploadAttachments(attachments) {
99
109
  if (!this.config.uploadAttachments) {
100
110
  return [];
@@ -57,6 +57,9 @@ class ClientV2 extends clientV1_1.ClientV1 {
57
57
  }
58
58
  async transformTestResult(result) {
59
59
  const attachments = await this.uploadAttachments(result.attachments);
60
+ if (result.preparedAttachments) {
61
+ attachments.push(...result.preparedAttachments);
62
+ }
60
63
  const steps = await this.transformSteps(result.steps, result.title);
61
64
  const params = this.transformParams(result.params);
62
65
  const groupParams = this.transformGroupParams(result.group_params, params);
@@ -1,6 +1,7 @@
1
- import { TestResultType } from "../models";
1
+ import { Attachment, TestResultType } from "../models";
2
2
  export interface IClient {
3
3
  createRun(): Promise<number>;
4
4
  completeRun(runId: number): Promise<void>;
5
5
  uploadResults(runId: number, results: TestResultType[]): Promise<void>;
6
+ uploadAttachment(attachment: Attachment): Promise<string>;
6
7
  }
@@ -17,6 +17,7 @@ export declare class TestResultType {
17
17
  relations: Relation | null;
18
18
  muted: boolean;
19
19
  message: string | null;
20
+ preparedAttachments?: string[];
20
21
  constructor(title: string);
21
22
  }
22
23
  export interface Relation {
@@ -18,6 +18,7 @@ class TestResultType {
18
18
  relations;
19
19
  muted;
20
20
  message;
21
+ preparedAttachments;
21
22
  constructor(title) {
22
23
  this.id = '';
23
24
  this.title = title;
@@ -34,6 +35,7 @@ class TestResultType {
34
35
  this.relations = null;
35
36
  this.muted = false;
36
37
  this.message = null;
38
+ this.preparedAttachments = [];
37
39
  }
38
40
  }
39
41
  exports.TestResultType = TestResultType;
package/dist/qase.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { OptionsType } from './options';
2
- import { TestResultType } from './models';
2
+ import { TestResultType, Attachment } from './models';
3
3
  export interface ReporterInterface {
4
4
  addTestResult(result: TestResultType): Promise<void>;
5
5
  publish(): Promise<void>;
@@ -9,6 +9,7 @@ export interface ReporterInterface {
9
9
  getResults(): TestResultType[];
10
10
  sendResults(): Promise<void>;
11
11
  complete(): Promise<void>;
12
+ uploadAttachment(attachment: Attachment): Promise<string>;
12
13
  }
13
14
  /**
14
15
  * @class QaseReporter
@@ -49,6 +50,7 @@ export declare class QaseReporter implements ReporterInterface {
49
50
  * @param {OptionsType} options
50
51
  */
51
52
  private constructor();
53
+ uploadAttachment(attachment: Attachment): Promise<string>;
52
54
  getResults(): TestResultType[];
53
55
  setTestResults(results: TestResultType[]): void;
54
56
  sendResults(): Promise<void>;
package/dist/qase.js CHANGED
@@ -136,6 +136,15 @@ class QaseReporter {
136
136
  }
137
137
  }
138
138
  }
139
+ async uploadAttachment(attachment) {
140
+ if (this.disabled) {
141
+ return '';
142
+ }
143
+ if (this.useFallback) {
144
+ return await this.fallbackReporter?.uploadAttachment(attachment) ?? '';
145
+ }
146
+ return await this.upstreamReporter?.uploadAttachment(attachment) ?? '';
147
+ }
139
148
  getResults() {
140
149
  if (this.disabled) {
141
150
  return [];
@@ -1,4 +1,4 @@
1
- import { TestResultType } from '../models';
1
+ import { Attachment, TestResultType } from '../models';
2
2
  import { LoggerInterface } from '../utils/logger';
3
3
  export interface InternalReporterInterface {
4
4
  addTestResult(result: TestResultType): Promise<void>;
@@ -8,6 +8,7 @@ export interface InternalReporterInterface {
8
8
  setTestResults(results: TestResultType[]): void;
9
9
  sendResults(): Promise<void>;
10
10
  complete(): Promise<void>;
11
+ uploadAttachment(attachments: Attachment): Promise<string>;
11
12
  }
12
13
  /**
13
14
  * @abstract
@@ -41,6 +42,11 @@ export declare abstract class AbstractReporter implements InternalReporterInterf
41
42
  * @returns {Promise<void>}
42
43
  */
43
44
  abstract sendResults(): Promise<void>;
45
+ /**
46
+ * @param {Attachment} attachment
47
+ * @returns {Promise<string>}
48
+ */
49
+ abstract uploadAttachment(attachment: Attachment): Promise<string>;
44
50
  /**
45
51
  * @protected
46
52
  * @param {LoggerInterface} logger
@@ -1,4 +1,5 @@
1
1
  import { AbstractReporter } from './abstract-reporter';
2
+ import { Attachment } from '../models';
2
3
  import { WriterInterface } from '../writer';
3
4
  import { LoggerInterface } from '../utils/logger';
4
5
  /**
@@ -34,6 +35,7 @@ export declare class ReportReporter extends AbstractReporter {
34
35
  publish(): Promise<void>;
35
36
  sendResults(): Promise<void>;
36
37
  complete(): Promise<void>;
38
+ uploadAttachment(attachment: Attachment): Promise<string>;
37
39
  /**
38
40
  * @param {TestStepType[]} steps
39
41
  * @returns {TestStepType[]}
@@ -134,6 +134,10 @@ class ReportReporter extends abstract_reporter_1.AbstractReporter {
134
134
  const path = await this.writer.writeReport(report);
135
135
  this.logger.log(`Report saved to ${path}`);
136
136
  }
137
+ uploadAttachment(attachment) {
138
+ this.writer.writeAttachment([attachment]);
139
+ return Promise.resolve('');
140
+ }
137
141
  /**
138
142
  * @param {TestStepType[]} steps
139
143
  * @returns {TestStepType[]}
@@ -1,5 +1,5 @@
1
1
  import { AbstractReporter } from './abstract-reporter';
2
- import { TestResultType } from '../models';
2
+ import { Attachment, TestResultType } from '../models';
3
3
  import { LoggerInterface } from '../utils/logger';
4
4
  import { IClient } from '../client/interface';
5
5
  /**
@@ -52,6 +52,11 @@ export declare class TestOpsReporter extends AbstractReporter {
52
52
  * @returns {Promise<void>}
53
53
  */
54
54
  sendResults(): Promise<void>;
55
+ /**
56
+ * @param {Attachment} attachment
57
+ * @returns {Promise<string>}
58
+ */
59
+ uploadAttachment(attachment: Attachment): Promise<string>;
55
60
  /**
56
61
  * @returns {Promise<void>}
57
62
  */
@@ -133,6 +133,13 @@ class TestOpsReporter extends abstract_reporter_1.AbstractReporter {
133
133
  // Clear results because we don't need to send them again then we use Cypress reporter
134
134
  this.results.length = 0;
135
135
  }
136
+ /**
137
+ * @param {Attachment} attachment
138
+ * @returns {Promise<string>}
139
+ */
140
+ async uploadAttachment(attachment) {
141
+ return await this.api.uploadAttachment(attachment);
142
+ }
136
143
  /**
137
144
  * @returns {Promise<void>}
138
145
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qase-javascript-commons",
3
- "version": "2.3.6",
3
+ "version": "2.4.0",
4
4
  "description": "Qase JS Reporters",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "async-mutex": "~0.5.0",
29
29
  "chalk": "^4.1.2",
30
30
  "env-schema": "^5.2.0",
31
- "form-data": "^4.0.0",
31
+ "form-data": "^4.0.4",
32
32
  "lodash.get": "^4.4.2",
33
33
  "lodash.merge": "^4.6.2",
34
34
  "lodash.mergewith": "^4.6.2",