@reportportal/client-javascript 5.0.11 → 5.0.13

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.
package/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # ReportPortal js client
2
+
2
3
  This Client is to communicate with the Report Portal on Node.js.
3
4
 
4
5
  Library is used only for implementors of custom listeners for ReportPortal.
5
6
 
6
7
  ## Already implemented listeners:
8
+
7
9
  * [Jest integration](https://github.com/reportportal/agent-js-jest)
8
10
  * [Cypress integration](https://github.com/reportportal/agent-js-cypress)
9
11
  * [Mocha integration](https://github.com/reportportal/agent-js-mocha)
@@ -19,21 +21,22 @@ Library is used only for implementors of custom listeners for ReportPortal.
19
21
  Examples for test framework integrations from the list above described in [examples](https://github.com/reportportal/examples-js) repository.
20
22
 
21
23
  ## Installation
24
+
22
25
  The latest version is available on npm:
23
26
  ```cmd
24
27
  npm install @reportportal/client-javascript
25
28
  ```
26
29
 
27
- ## Example
30
+ ## Usage example
28
31
 
29
32
  ```javascript
30
33
  const RPClient = require('@reportportal/client-javascript');
31
34
 
32
35
  const rpClient = new RPClient({
33
- token: "00000000-0000-0000-0000-000000000000",
34
- endpoint: "http://your-instance.com:8080/api/v1",
35
- launch: "LAUNCH_NAME",
36
- project: "PROJECT_NAME"
36
+ apiKey: 'reportportalApiKey',
37
+ endpoint: 'http://your-instance.com:8080/api/v1',
38
+ launch: 'LAUNCH_NAME',
39
+ project: 'PROJECT_NAME'
37
40
  });
38
41
 
39
42
  rpClient.checkConnect().then((response) => {
@@ -45,25 +48,31 @@ rpClient.checkConnect().then((response) => {
45
48
  });
46
49
  ```
47
50
 
48
- ## Settings
49
- When creating a client instance, you need to specify the following parameters:
51
+ ## Configuration
52
+
53
+ When creating a client instance, you need to specify the following options:
50
54
 
51
- | Parameter | Description |
52
- |-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
53
- | token | User's token Report Portal from which you want to send requests. It can be found on the profile page of this user. |
54
- | endpoint | URL of your server. For example, if you visit the page at 'https://server:8080/ui', then endpoint will be equal to 'https://server:8080/api/v1'. |
55
- | launch | Name of launch at creation. |
56
- | project | The name of the project in which the launches will be created. |
57
- | headers | (optional) The object with custom headers for internal http client. |
58
- | debug | (optional) *Default: false.* This flag allows seeing the logs of the client. Useful for debugging. |
59
- | isLaunchMergeRequired | (optional) *Default: false.* Allows client to merge launches into one at the end of the run via saving their UUIDs to the file system. At the end of the run launches can be merged using `mergeLaunches` method. |
60
- | restClientConfig | (optional) The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. `timeout`. |
55
+ | Option | Necessity | Default | Description |
56
+ |-----------------------|------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
57
+ | apiKey | Required | | User's reportportal token from which you want to send requests. It can be found on the profile page of this user. |
58
+ | endpoint | Required | | URL of your server. For example, if you visit the page at 'https://server:8080/ui', then endpoint will be equal to 'https://server:8080/api/v1'. |
59
+ | launch | Required | | Name of launch at creation. |
60
+ | project | Required | | The name of the project in which the launches will be created. |
61
+ | headers | Optional | {} | The object with custom headers for internal http client. |
62
+ | debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
63
+ | isLaunchMergeRequired | Optional | false | Allows client to merge launches into one at the end of the run via saving their UUIDs to the file system. At the end of the run launches can be merged using `mergeLaunches` method. |
64
+ | restClientConfig | Optional | Not set | The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. `timeout`. |
65
+ | launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
66
+ | launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if `launchUuidPrint` set to `true`. |
67
+ | token | Deprecated | Not set | Use `apiKey` instead. |
61
68
 
62
69
  ## Asynchronous reporting
70
+
63
71
  The client supports an asynchronous reporting.
64
- If you want the client to work asynchronously change v1 to v2 in addresses in endpoint.
72
+ If you want the client to work asynchronously change `v1` to `v2` in addresses in endpoint.
73
+
74
+ ## API
65
75
 
66
- ## Api
67
76
  Each method (except checkConnect) returns an object in a specific format:
68
77
  ```javascript
69
78
  {
@@ -74,12 +83,15 @@ Each method (except checkConnect) returns an object in a specific format:
74
83
  The client works synchronously, so it is not necessary to wait for the end of the previous requests to send following ones.
75
84
 
76
85
  ### Timeout (30000ms) on axios requests
77
- There is a timeout on axios requests. If for instance the server your making a request to is taking too long to load, then axios timeout will work and you will see the error "Error: timeout of 30000ms exceeded".
86
+
87
+ There is a timeout on axios requests. If for instance the server your making a request to is taking too long to load, then axios timeout will work and you will see the error 'Error: timeout of 30000ms exceeded'.
78
88
 
79
89
  You can simply change this timeout by adding a `timeout` property to `restClientConfig` with your desired numeric value (in _ms_) or *0* to disable it.
80
90
 
81
91
  ### checkConnect
82
- checkConnect - asynchronous method for verifying the correctness of the client connection
92
+
93
+ `checkConnect` - asynchronous method for verifying the correctness of the client connection
94
+
83
95
  ```javascript
84
96
  rpClient.checkConnect().then((response) => {
85
97
  console.log('You have successfully connected to the server.');
@@ -91,19 +103,21 @@ rpClient.checkConnect().then((response) => {
91
103
  ```
92
104
 
93
105
  ### startLaunch
94
- startLaunch - starts a new launch, return temp id that you want to use for all of the items within this launch.
106
+
107
+ `startLaunch` - starts a new launch, return temp id that you want to use for the all items within this launch.
108
+
95
109
  ```javascript
96
110
  const launchObj = rpClient.startLaunch({
97
- name: "Client test",
111
+ name: 'Client test',
98
112
  startTime: rpClient.helpers.now(),
99
- description: "description of the launch",
113
+ description: 'description of the launch',
100
114
  attributes: [
101
115
  {
102
- "key": "yourKey",
103
- "value": "yourValue"
116
+ 'key': 'yourKey',
117
+ 'value': 'yourValue'
104
118
  },
105
119
  {
106
- "value": "yourValue"
120
+ 'value': 'yourValue'
107
121
  }
108
122
  ],
109
123
  //this param used only when you need client to send data into the existing launch
@@ -114,16 +128,17 @@ console.log(launchObj.tempId);
114
128
  The method takes one argument:
115
129
  * launch data object:
116
130
 
117
- Parameter | Description
118
- --------- | -----------
119
- startTime | (optional) start time launch(unix time). Default: rpClient.helpers.now()
120
- name | (optional) launch name. Default: parameter 'launch' specified when creating the client instance
121
- mode | (optional) "DEFAULT" or "DEBUG". Default: "DEFAULT"
122
- description | (optional) description of the launch (supports markdown syntax)
123
- attributes | (optional) array of launch tags
124
- id | id of the existing launch in which tests data would be sent, without this param new launch instance would be created
131
+ | Option | Necessity | Default | Description |
132
+ |-------------|-----------|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
133
+ | startTime | Optional | rpClient.helpers.now() | (optional) start time launch(unix time). |
134
+ | name | Optional | parameter 'launch' specified when creating the client instance | Name of the launch. |
135
+ | mode | Optional | 'DEFAULT' | 'DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page. |
136
+ | description | Optional | '' | Description of the launch (supports markdown syntax). |
137
+ | attributes | Optional | [] | Array of launch attributes (tags). |
138
+ | id | Optional | Not set | `ID` of the existing launch in which tests data would be sent, without this param new launch instance will be created. |
139
+
140
+ To get the real launch `ID` (also known as launch `UUID` from database) wait for the returned promise to finish.
125
141
 
126
- To know the real launch id wait for the method to finish. The real id is used by the client in asynchronous reporting.
127
142
  ```javascript
128
143
  const launchObj = rpClient.startLaunch();
129
144
  launchObj.promise.then((response) => {
@@ -149,49 +164,57 @@ If you still want to switch Off Google Analytics, please change env variable.
149
164
  'REPORTPORTAL_CLIENT_JS_NO_ANALYTICS=true'
150
165
 
151
166
  ### finishLaunch
152
- finishLaunch - finish of the launch. After calling this method, you can not add items to the launch.
167
+
168
+ `finishLaunch` - finish of the launch. After calling this method, you can not add items to the launch.
153
169
  The request to finish the launch will be sent only after all items within it have finished.
170
+
154
171
  ```javascript
155
172
  // launchObj - object returned by method 'startLaunch'
156
173
  const launchFinishObj = rpClient.finishLaunch(launchObj.tempId, {
157
174
  endTime: rpClient.helpers.now()
158
175
  });
159
176
  ```
177
+
160
178
  The method takes two arguments:
161
- * id launch (returned by method 'startLaunch')
179
+ * launch `tempId` (returned by the method `startLaunch`)
162
180
  * data object:
163
181
 
164
- Parameter | Description
165
- --------- | -----------
166
- endTime | (optional) end time of launch. Default: rpClient.helpers.now()
167
- status | (optional) status of launch, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "INTERRUPTED", "CANCELLED".
182
+ |Option | Necessity | Default | Description |
183
+ |--------- |-----------|---------|---------------------------------------------------------------------------------------------------|
184
+ |endTime | Optional | rpClient.helpers.now() | End time of the launch. |
185
+ |status | Optional | '' | Status of launch, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. |
168
186
 
169
187
  ### getPromiseFinishAllItems
170
- getPromiseFinishAllItems - returns promise that contains status about all data has been sent to the Report Protal.
171
- This method needed when test frameworks don't wait for async methods and stop processed.
188
+
189
+ `getPromiseFinishAllItems` - returns promise that contains status about all data has been sent to the reportportal.
190
+ This method needed when test frameworks don't wait for async methods until finished.
172
191
 
173
192
  ```javascript
174
- // jasmine example. tempLaunchId - id of the client's process
175
- agent.getPromiseFinishAllItems(agent.tempLaunchId).then(()=> done());
193
+ // jasmine example. tempLaunchId - tempId of the launch started by the current client process
194
+ agent.getPromiseFinishAllItems(agent.tempLaunchId).then(() => done());
176
195
  ```
177
- Parameter | Description
178
- --------- | -----------
179
- tempLaunchId | id of the client's process
196
+
197
+ | Option | Necessity | Default | Description |
198
+ |--------------|-----------|---------|----------------------------|
199
+ | tempLaunchId | Required | | `tempId` of the launch started by the current client process |
180
200
 
181
201
  ### updateLaunch
182
- updateLaunch - updates launch data. Will send a request to the server only after finishing the launch.
202
+
203
+ `updateLaunch` - updates the launch data. Will send a request to the server only after finishing the launch.
204
+
183
205
  ```javascript
184
206
  // launchObj - object returned by method 'startLaunch'
185
207
  rpClient.updateLaunch(
186
- launchObj.tempId, {
208
+ launchObj.tempId,
209
+ {
187
210
  description: 'new launch description',
188
211
  attributes: [
189
212
  {
190
- "key": "yourKey",
191
- "value": "yourValue"
213
+ key: 'yourKey',
214
+ value: 'yourValue'
192
215
  },
193
216
  {
194
- "value": "yourValue"
217
+ value: 'yourValue'
195
218
  }
196
219
  ],
197
220
  mode: 'DEBUG'
@@ -199,18 +222,20 @@ rpClient.updateLaunch(
199
222
  );
200
223
  ```
201
224
  The method takes two arguments:
202
- * id launch (returned by method 'startLaunch')
203
- * data object - may contain the following fields: description, tags, mode. These fields can be looked up in the method "startLaunch".
225
+ * launch `tempId` (returned by the method 'startLaunch')
226
+ * data object - may contain the following fields: `description`, `attributes`, `mode`. These fields can be looked up in the method `startLaunch`.
204
227
 
205
228
  ### startTestItem
206
- startTestItem - starts a new test item.
229
+
230
+ `startTestItem` - starts a new test item.
231
+
207
232
  ```javascript
208
233
  // launchObj - object returned by method 'startLaunch'
209
234
  const suiteObj = rpClient.startTestItem({
210
235
  description: makeid(),
211
236
  name: makeid(),
212
237
  startTime: rpClient.helpers.now(),
213
- type: "SUITE"
238
+ type: 'SUITE'
214
239
  }, launchObj.tempId);
215
240
  const stepObj = rpClient.startTestItem({
216
241
  description: makeid(),
@@ -219,97 +244,101 @@ const stepObj = rpClient.startTestItem({
219
244
  attributes: [
220
245
 
221
246
  {
222
- "key": "yourKey",
223
- "value": "yourValue"
247
+ key: 'yourKey',
248
+ value: 'yourValue'
224
249
  },
225
250
  {
226
- "value": "yourValue"
251
+ value: 'yourValue'
227
252
  }
228
253
  ],
229
- type: "STEP"
254
+ type: 'STEP'
230
255
  }, launchObj.tempId, suiteObj.tempId);
231
256
 
232
257
  ```
233
258
  The method takes three arguments:
234
259
  * test item data object:
235
260
 
236
- Parameter | Description
237
- --------- | -----------
238
- name | item name
239
- type | Item type, one of 'SUITE', 'STORY', 'TEST', 'SCENARIO', 'STEP', 'BEFORE_CLASS', 'BEFORE_GROUPS','BEFORE_METHOD', 'BEFORE_SUITE', 'BEFORE_TEST', 'AFTER_CLASS', 'AFTER_GROUPS', 'AFTER_METHOD', 'AFTER_SUITE', 'AFTER_TEST'
240
- hasStats | (optional) Changes behavior for item of type 'STEP'. When set to true, step is treaten as a test case (entity containig statistics). When false, step becomes a nested step. Default: true
241
- description | (optional) description of the launch (supports markdown syntax)
242
- startTime | (optional) start time item(unix time). Default: rpClient.helpers.now()
243
- attributes | (optional) array of item attributes
244
-
245
- * id launch (returned by method 'startLaunch')
246
- * id parent item (optional) (returned by method 'startTestItem')
261
+ |Option | Necessity | Default | Description |
262
+ |--------- |-----------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
263
+ |name | Required | | Test item name |
264
+ |type | Required | | Test item type, one of 'SUITE', 'STORY', 'TEST', 'SCENARIO', 'STEP', 'BEFORE_CLASS', 'BEFORE_GROUPS','BEFORE_METHOD', 'BEFORE_SUITE', 'BEFORE_TEST', 'AFTER_CLASS', 'AFTER_GROUPS', 'AFTER_METHOD', 'AFTER_SUITE', 'AFTER_TEST' |
265
+ |hasStats | Optional | true | Changes behavior for test item of type 'STEP'. When set to `true`, step is treaten as a test case (entity containig statistics). When false, step becomes a nested step. |
266
+ |description | Optional | '' | Description of the test item (supports markdown syntax). |
267
+ |startTime | Optional | rpClient.helpers.now() | Start time of the test item (unix time). |
268
+ |attributes | Optional | [] | Array of the test item attributes. |
247
269
 
270
+ * launch `tempId` (returned by the method `startLaunch`)
271
+ * parent test item `tempId` (*optional*) (returned by method `startTestItem`)
248
272
 
249
273
  ### finishTestItem
250
- finishTestItem - finish of the item. After calling this method, you can not add items to the item.
251
- The request to finish the item will be sent only after all items within it have finished.
274
+
275
+ `finishTestItem` - finish of the test item. After calling this method, you can not add items to the test item.
276
+ The request to finish the test item will be sent only after all test items within it have finished.
277
+
252
278
  ```javascript
253
279
  // itemObj - object returned by method 'startTestItem'
254
280
  rpClient.finishTestItem(itemObj.tempId, {
255
- status: "failed"
281
+ status: 'failed'
256
282
  })
257
283
  ```
258
284
  The method takes two arguments:
259
- * id item (returned by method 'startTestItem')
285
+ * test item `tempId` (returned by the method `startTestItem`)
260
286
  * data object:
261
287
 
262
- Parameter | Description
263
- --------- | -----------
264
- endTime | (optional) end time of launch. Default: rpClient.helpers.now()
265
- status | (optional) item status, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "INTERRUPTED", "CANCELLED". Default: "PASSED".
266
- issue | (optional) object issue. IssueType is required, allowable values: "pb***", "ab***", "si***", "ti***", "nd001". Where *** is locator id
288
+ | Option | Necessity | Default | Description |
289
+ |---------|-----------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
290
+ | issue | Optional | true | Test item issue object. `issueType` is required, allowable values: 'pb***', 'ab***', 'si***', 'ti***', 'nd001'. Where `***` is locator id |
291
+ | status | Optional | 'PASSED' | Test item status, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. |
292
+ | endTime | Optional | rpClient.helpers.now() | End time of the launch (unix time). |
267
293
 
268
294
  Example issue object:
269
295
  ```
270
296
  {
271
- issueType: "string",
272
- comment: "string",
297
+ issueType: 'string',
298
+ comment: 'string',
273
299
  externalSystemIssues: [
274
300
  {
275
301
  submitDate: 0,
276
- submitter: "string",
277
- systemId: "string",
278
- ticketId: "string",
279
- url: "string"
302
+ submitter: 'string',
303
+ systemId: 'string',
304
+ ticketId: 'string',
305
+ url: 'string'
280
306
  }
281
307
  ]
282
308
  }
283
309
  ```
284
310
 
285
311
  ### sendLog
286
- sendLog - adds a log to the item
312
+
313
+ `sendLog` - adds a log to the test item.
314
+
287
315
  ```javascript
288
316
  // stepObj - object returned by method 'startTestItem'
289
317
  rpClient.sendLog(stepObj.tempId, {
290
- level: "INFO",
291
- message: makeid(),
318
+ level: 'INFO',
319
+ message: 'User clicks login button',
292
320
  time: rpClient.helpers.now()
293
321
  })
294
322
  ```
295
323
  The method takes three arguments:
296
- * id item (returned by method 'startTestItem')
324
+ * test item `tempId` (returned by method `startTestItem`)
297
325
  * data object:
298
326
 
299
- Parameter | Description
300
- --------- | -----------
301
- time | (optional) time of log. Default: rpClient.helpers.now()
302
- message | (optional) log message. Default: ''.
303
- status | (optional) log status, one of 'trace', 'debug', 'info', 'warn', 'error', ''. Default "".
327
+ | Option | Necessity | Default | Description |
328
+ |---------|-----------|------------------------|----------------------------------------------------------------------|
329
+ | message | Optional | '' | The log message. |
330
+ | level | Optional | '' | The log level, one of 'trace', 'debug', 'info', 'warn', 'error', ''. |
331
+ | time | Optional | rpClient.helpers.now() | The time of the log. |
304
332
 
305
333
  * file object (optional):
306
334
 
307
- Parameter | Description
308
- --------- | -----------
309
- name | file name
310
- type | file mimeType, example "image/png" (support types: 'image/*', application/ ['xml', 'javascript', 'json', 'css', 'php'] , another format will be opened in a new browser tab ),
311
- content | file
335
+ | Option | Necessity | Default | Description |
336
+ |---------|-----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
337
+ | name | Required | | The name of the file. |
338
+ | type | Required | | The file mimeType, example 'image/png' (support types: 'image/*', application/['xml', 'javascript', 'json', 'css', 'php'], other formats will be opened in reportportal in a new browser tab only). |
339
+ | content | Required | | base64 encoded file content. |
312
340
 
313
341
  # Copyright Notice
342
+
314
343
  Licensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)
315
344
  license (see the LICENSE.txt file).
package/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.12-SNAPSHOT
1
+ 5.0.14-SNAPSHOT
@@ -0,0 +1,81 @@
1
+ const { ReportPortalRequiredOptionError, ReportPortalValidationError } = require('./errors');
2
+ const { OUTPUT_TYPES } = require('../constants/outputs');
3
+
4
+ const getOption = (options, optionName, defaultValue) => {
5
+ if (!Object.prototype.hasOwnProperty.call(options, optionName) || !options[optionName]) {
6
+ return defaultValue;
7
+ }
8
+
9
+ return options[optionName];
10
+ };
11
+
12
+ const getRequiredOption = (options, optionName) => {
13
+ if (!Object.prototype.hasOwnProperty.call(options, optionName) || !options[optionName]) {
14
+ throw new ReportPortalRequiredOptionError(optionName);
15
+ }
16
+
17
+ return options[optionName];
18
+ };
19
+
20
+ const getApiKey = ({ apiKey, token }) => {
21
+ let calculatedApiKey = apiKey;
22
+ if (!calculatedApiKey) {
23
+ calculatedApiKey = token;
24
+ if (!calculatedApiKey) {
25
+ throw new ReportPortalRequiredOptionError('apiKey');
26
+ } else {
27
+ console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`);
28
+ }
29
+ }
30
+
31
+ return calculatedApiKey;
32
+ };
33
+
34
+ const getClientConfig = (options) => {
35
+ let calculatedOptions = options;
36
+ try {
37
+ if (typeof options !== 'object') {
38
+ throw new ReportPortalValidationError('`options` must be an object.');
39
+ }
40
+ const apiKey = getApiKey(options);
41
+ const project = getRequiredOption(options, 'project');
42
+ const endpoint = getRequiredOption(options, 'endpoint');
43
+
44
+ const launchUuidPrintOutputType = getOption(options, 'launchUuidPrintOutput', 'STDOUT')
45
+ .toString()
46
+ .toUpperCase();
47
+ const launchUuidPrintOutput = getOption(
48
+ OUTPUT_TYPES,
49
+ launchUuidPrintOutputType,
50
+ OUTPUT_TYPES.STDOUT,
51
+ );
52
+
53
+ calculatedOptions = {
54
+ apiKey,
55
+ project,
56
+ endpoint,
57
+ launch: options.launch,
58
+ debug: options.debug,
59
+ isLaunchMergeRequired:
60
+ options.isLaunchMergeRequired === undefined ? false : options.isLaunchMergeRequired,
61
+ headers: options.headers,
62
+ restClientConfig: options.restClientConfig,
63
+ attributes: options.attributes,
64
+ mode: options.mode,
65
+ description: options.description,
66
+ launchUuidPrint: options.launchUuidPrint,
67
+ launchUuidPrintOutput,
68
+ };
69
+ } catch (error) {
70
+ // don't throw the error up to not break the entire process
71
+ console.dir(error);
72
+ }
73
+
74
+ return calculatedOptions;
75
+ };
76
+
77
+ module.exports = {
78
+ getClientConfig,
79
+ getRequiredOption,
80
+ getApiKey,
81
+ };
@@ -0,0 +1,29 @@
1
+ class ReportPortalError extends Error {
2
+ constructor(message) {
3
+ const basicMessage = `\nReportPortal client error: ${message}`;
4
+ super(basicMessage);
5
+ this.name = 'ReportPortalError';
6
+ }
7
+ }
8
+
9
+ class ReportPortalValidationError extends ReportPortalError {
10
+ constructor(message) {
11
+ const basicMessage = `\nValidation failed. Please, check the specified parameters: ${message}`;
12
+ super(basicMessage);
13
+ this.name = 'ReportPortalValidationError';
14
+ }
15
+ }
16
+
17
+ class ReportPortalRequiredOptionError extends ReportPortalValidationError {
18
+ constructor(propertyName) {
19
+ const basicMessage = `\nProperty '${propertyName}' must not be empty.`;
20
+ super(basicMessage);
21
+ this.name = 'ReportPortalRequiredOptionError';
22
+ }
23
+ }
24
+
25
+ module.exports = {
26
+ ReportPortalError,
27
+ ReportPortalValidationError,
28
+ ReportPortalRequiredOptionError,
29
+ };
@@ -0,0 +1,8 @@
1
+ const OUTPUT_TYPES = {
2
+ // eslint-disable-next-line no-console
3
+ STDOUT: console.log,
4
+ // eslint-disable-next-line no-console
5
+ STDERR: console.error,
6
+ };
7
+
8
+ module.exports = { OUTPUT_TYPES };
@@ -3,6 +3,7 @@ const UniqId = require('uniqid');
3
3
  const { URLSearchParams } = require('url');
4
4
  const helpers = require('./helpers');
5
5
  const RestClient = require('./rest');
6
+ const { getClientConfig } = require('./commons/config');
6
7
  const Statistics = require('../statistics/statistics');
7
8
  const { EVENT_NAME } = require('../statistics/constants');
8
9
  const { RP_STATUSES } = require('./constants/statuses');
@@ -12,10 +13,10 @@ const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString();
12
13
  class RPClient {
13
14
  /**
14
15
  * Create a client for RP.
15
- * @param {Object} params - config object.
16
- * params should look like this
16
+ * @param {Object} options - config object.
17
+ * options should look like this
17
18
  * {
18
- * token: "00000000-0000-0000-0000-000000000000",
19
+ * apiKey: "reportportalApiKey",
19
20
  * endpoint: "http://localhost:8080/api/v1",
20
21
  * launch: "YOUR LAUNCH NAME",
21
22
  * project: "PROJECT NAME",
@@ -28,24 +29,26 @@ class RPClient {
28
29
  * version: "AGENT VERSION",
29
30
  * }
30
31
  */
31
- constructor(params, agentParams) {
32
- this.debug = params.debug;
33
- this.isLaunchMergeRequired =
34
- params.isLaunchMergeRequired === undefined ? false : params.isLaunchMergeRequired;
32
+ constructor(options, agentParams) {
33
+ this.config = getClientConfig(options);
34
+ this.debug = this.config.debug;
35
+ this.isLaunchMergeRequired = this.config.isLaunchMergeRequired;
36
+ this.apiKey = this.config.apiKey;
37
+ // deprecated
38
+ this.token = this.apiKey;
39
+
35
40
  this.map = {};
36
- this.baseURL = [params.endpoint, params.project].join('/');
41
+ this.baseURL = [this.config.endpoint, this.config.project].join('/');
37
42
  this.headers = {
38
43
  'User-Agent': 'NodeJS',
39
- Authorization: `bearer ${params.token}`,
40
- ...(params.headers || {}),
44
+ Authorization: `bearer ${this.apiKey}`,
45
+ ...(this.config.headers || {}),
41
46
  };
42
- this.token = params.token;
43
- this.config = params;
44
47
  this.helpers = helpers;
45
48
  this.restClient = new RestClient({
46
49
  baseURL: this.baseURL,
47
50
  headers: this.headers,
48
- restClientConfig: params.restClientConfig,
51
+ restClientConfig: this.config.restClientConfig,
49
52
  });
50
53
  this.statistics = new Statistics(EVENT_NAME, agentParams);
51
54
  this.launchUuid = '';
@@ -184,6 +187,9 @@ class RPClient {
184
187
  (response) => {
185
188
  this.map[tempId].realId = response.id;
186
189
  this.launchUuid = response.id;
190
+ if (this.config.launchUuidPrint) {
191
+ this.config.launchUuidPrintOutput(`Report Portal Launch UUID: ${this.launchUuid}`);
192
+ }
187
193
 
188
194
  if (this.isLaunchMergeRequired) {
189
195
  helpers.saveLaunchIdToFile(response.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/client-javascript",
3
- "version": "5.0.11",
3
+ "version": "5.0.13",
4
4
  "description": "ReportPortal client for Node.js",
5
5
  "author": "ReportPortal.io",
6
6
  "scripts": {
@@ -2,6 +2,10 @@ const axios = require('axios');
2
2
  const { MEASUREMENT_ID, API_KEY, PJSON_NAME, PJSON_VERSION, INTERPRETER } = require('./constants');
3
3
  const { getClientId } = require('./client-id');
4
4
 
5
+ const hasOption = (options, optionName) => {
6
+ return Object.prototype.hasOwnProperty.call(options, optionName);
7
+ };
8
+
5
9
  class Statistics {
6
10
  constructor(eventName, agentParams) {
7
11
  this.eventName = eventName;
@@ -14,18 +18,10 @@ class Statistics {
14
18
  client_name: PJSON_NAME,
15
19
  client_version: PJSON_VERSION,
16
20
  };
17
- if (
18
- agentParams &&
19
- Object.prototype.hasOwnProperty.call(agentParams, 'name') &&
20
- agentParams.name
21
- ) {
21
+ if (agentParams && hasOption(agentParams, 'name') && agentParams.name) {
22
22
  params.agent_name = agentParams.name;
23
23
  }
24
- if (
25
- agentParams &&
26
- Object.prototype.hasOwnProperty.call(agentParams, 'version') &&
27
- agentParams.version
28
- ) {
24
+ if (agentParams && hasOption(agentParams, 'version') && agentParams.version) {
29
25
  params.agent_version = agentParams.version;
30
26
  }
31
27
  return params;