@reportportal/client-javascript 5.0.6 → 5.0.7

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/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ ## [5.0.7] - 2022-12-26
3
+ ### Added
4
+ - The ability to see verbose logs in debug mode. To enable the debug mode, the `debug: true` flag should be specified in `params`.
5
+ ### Security
6
+ - Updated versions of vulnerable packages (ajv, qs, follow-redirects, minimatch).
7
+
2
8
  ## [5.0.6] - 2022-01-13
3
9
  ### Fixed
4
10
  - Security vulnerabilities (axios, path-parse, minimist)
@@ -39,6 +45,5 @@
39
45
  ## [5.0.0] - 2020-06-09
40
46
  ### Added
41
47
  - Full compatibility with ReportPortal version 5.* (see [reportportal releases](https://github.com/reportportal/reportportal/releases))
42
-
43
48
  ### Deprecated
44
49
  - Previous package version (`reportportal-client`) will no longer supported by reportportal.io
package/README.md CHANGED
@@ -48,14 +48,16 @@ rpClient.checkConnect().then((response) => {
48
48
  ## Settings
49
49
  When creating a client instance, you need to specify the following parameters:
50
50
 
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
- 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`.
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`. |
59
61
 
60
62
  ## Asynchronous reporting
61
63
  The client supports an asynchronous reporting.
@@ -74,7 +76,7 @@ The client works synchronously, so it is not necessary to wait for the end of th
74
76
  ### Timeout (30000ms) on axios requests
75
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".
76
78
 
77
- You can simply change this timeout by adding a `timeout` property to `restClientConfig` with your desired numeric value.
79
+ 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.
78
80
 
79
81
  ### checkConnect
80
82
  checkConnect - asynchronous method for verifying the correctness of the client connection
package/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.6
1
+ 5.0.7
@@ -8,7 +8,8 @@ const CLIENT_JAVASCRIPT_EVENTS = {
8
8
  },
9
9
  };
10
10
 
11
- const getAgentEventLabel = (agentParams) => `Agent name "${agentParams.name}", version "${agentParams.version}"`;
11
+ const getAgentEventLabel = (agentParams) =>
12
+ `Agent name "${agentParams.name}", version "${agentParams.version}"`;
12
13
 
13
14
  module.exports = {
14
15
  CLIENT_JAVASCRIPT_EVENTS,
package/lib/helpers.js CHANGED
@@ -15,7 +15,7 @@ module.exports = {
15
15
  formatName(name) {
16
16
  const len = name.length;
17
17
  // eslint-disable-next-line no-mixed-operators
18
- return ((len < MIN) ? (name + new Array(MIN - len + 1).join('.')) : name).slice(-MAX);
18
+ return (len < MIN ? name + new Array(MIN - len + 1).join('.') : name).slice(-MAX);
19
19
  },
20
20
 
21
21
  now() {
@@ -23,8 +23,7 @@ module.exports = {
23
23
  },
24
24
 
25
25
  getServerResult(url, request, options, method) {
26
- return RestClient
27
- .request(method, url, request, options);
26
+ return RestClient.request(method, url, request, options);
28
27
  },
29
28
 
30
29
  readLaunchesFromFile() {
@@ -48,23 +47,28 @@ module.exports = {
48
47
  const osArchitecture = os.arch();
49
48
  const RAMSize = os.totalmem();
50
49
  const nodeVersion = process.version;
51
- const systemAttr = [{
52
- key: 'client',
53
- value: `${PJSON_NAME}|${PJSON_VERSION}`,
54
- system: true,
55
- }, {
56
- key: 'os',
57
- value: `${osType}|${osArchitecture}`,
58
- system: true,
59
- }, {
60
- key: 'RAMSize',
61
- value: RAMSize,
62
- system: true,
63
- }, {
64
- key: 'nodeJS',
65
- value: nodeVersion,
66
- system: true,
67
- }];
50
+ const systemAttr = [
51
+ {
52
+ key: 'client',
53
+ value: `${PJSON_NAME}|${PJSON_VERSION}`,
54
+ system: true,
55
+ },
56
+ {
57
+ key: 'os',
58
+ value: `${osType}|${osArchitecture}`,
59
+ system: true,
60
+ },
61
+ {
62
+ key: 'RAMSize',
63
+ value: RAMSize,
64
+ system: true,
65
+ },
66
+ {
67
+ key: 'nodeJS',
68
+ value: nodeVersion,
69
+ system: true,
70
+ },
71
+ ];
68
72
 
69
73
  return systemAttr;
70
74
  },
@@ -78,7 +82,10 @@ module.exports = {
78
82
  return codeRef;
79
83
  }
80
84
 
81
- const parameters = params.reduce((result, item) => (item.value ? result.concat(item.value) : result), []);
85
+ const parameters = params.reduce(
86
+ (result, item) => (item.value ? result.concat(item.value) : result),
87
+ [],
88
+ );
82
89
 
83
90
  return `${codeRef}[${parameters}]`;
84
91
  },
@@ -5,85 +5,85 @@ const { EVENTS } = require('./constants/events');
5
5
  */
6
6
  class PublicReportingAPI {
7
7
  /**
8
- * Emit set description event.
9
- * @param {String} text - description of current test/suite.
10
- * @param {String} suite - suite description, optional.
11
- */
8
+ * Emit set description event.
9
+ * @param {String} text - description of current test/suite.
10
+ * @param {String} suite - suite description, optional.
11
+ */
12
12
  static setDescription(text, suite) {
13
13
  process.emit(EVENTS.SET_DESCRIPTION, { text, suite });
14
14
  }
15
15
 
16
16
  /**
17
- * Emit add attributes event.
18
- * @param {Array} attributes - array of attributes, should looks like this:
19
- * [{
20
- * key: "attrKey",
21
- * value: "attrValue",
22
- * }]
23
- *
24
- * @param {String} suite - suite description, optional.
25
- */
17
+ * Emit add attributes event.
18
+ * @param {Array} attributes - array of attributes, should looks like this:
19
+ * [{
20
+ * key: "attrKey",
21
+ * value: "attrValue",
22
+ * }]
23
+ *
24
+ * @param {String} suite - suite description, optional.
25
+ */
26
26
  static addAttributes(attributes, suite) {
27
27
  process.emit(EVENTS.ADD_ATTRIBUTES, { attributes, suite });
28
28
  }
29
29
 
30
30
  /**
31
- * Emit send log to test item event.
32
- * @param {Object} log - log object should looks like this:
33
- * {
34
- * level: "INFO",
35
- * message: "log message",
36
- * file: {
37
- * name: "filename",
38
- * type: "image/png", // media type
39
- * content: data, // file content represented as 64base string
40
- * },
41
- * }
42
- * @param {String} suite - suite description, optional.
43
- */
31
+ * Emit send log to test item event.
32
+ * @param {Object} log - log object should looks like this:
33
+ * {
34
+ * level: "INFO",
35
+ * message: "log message",
36
+ * file: {
37
+ * name: "filename",
38
+ * type: "image/png", // media type
39
+ * content: data, // file content represented as 64base string
40
+ * },
41
+ * }
42
+ * @param {String} suite - suite description, optional.
43
+ */
44
44
  static addLog(log, suite) {
45
45
  process.emit(EVENTS.ADD_LOG, { log, suite });
46
46
  }
47
47
 
48
48
  /**
49
- * Emit send log to current launch event.
50
- * @param {Object} log - log object should looks like this:
51
- * {
52
- * level: "INFO",
53
- * message: "log message",
54
- * file: {
55
- * name: "filename",
56
- * type: "image/png", // media type
57
- * content: data, // file content represented as 64base string
58
- * },
59
- * }
60
- */
49
+ * Emit send log to current launch event.
50
+ * @param {Object} log - log object should looks like this:
51
+ * {
52
+ * level: "INFO",
53
+ * message: "log message",
54
+ * file: {
55
+ * name: "filename",
56
+ * type: "image/png", // media type
57
+ * content: data, // file content represented as 64base string
58
+ * },
59
+ * }
60
+ */
61
61
  static addLaunchLog(log) {
62
62
  process.emit(EVENTS.ADD_LAUNCH_LOG, log);
63
63
  }
64
64
 
65
65
  /**
66
- * Emit set testCaseId event.
67
- * @param {String} testCaseId - testCaseId of current test/suite.
68
- * @param {String} suite - suite description, optional.
69
- */
66
+ * Emit set testCaseId event.
67
+ * @param {String} testCaseId - testCaseId of current test/suite.
68
+ * @param {String} suite - suite description, optional.
69
+ */
70
70
  static setTestCaseId(testCaseId, suite) {
71
71
  process.emit(EVENTS.SET_TEST_CASE_ID, { testCaseId, suite });
72
72
  }
73
73
 
74
74
  /**
75
- * Emit set status to current launch event.
76
- * @param {String} status - status of current launch.
77
- */
75
+ * Emit set status to current launch event.
76
+ * @param {String} status - status of current launch.
77
+ */
78
78
  static setLaunchStatus(status) {
79
79
  process.emit(EVENTS.SET_LAUNCH_STATUS, status);
80
80
  }
81
81
 
82
82
  /**
83
- * Emit set status event.
84
- * @param {String} status - status of current test/suite.
85
- * @param {String} suite - suite description, optional.
86
- */
83
+ * Emit set status event.
84
+ * @param {String} status - status of current test/suite.
85
+ * @param {String} suite - suite description, optional.
86
+ */
87
87
  static setStatus(status, suite) {
88
88
  process.emit(EVENTS.SET_STATUS, { status, suite });
89
89
  }
@@ -11,26 +11,27 @@ const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString();
11
11
 
12
12
  class RPClient {
13
13
  /**
14
- * Create a client for RP.
15
- * @param {Object} params - config object.
16
- * params should look like this
17
- * {
18
- * token: "00000000-0000-0000-0000-000000000000",
19
- * endpoint: "http://localhost:8080/api/v1",
20
- * launch: "YOUR LAUNCH NAME",
21
- * project: "PROJECT NAME",
22
- * }
23
- *
24
- * @param {Object} agentParams - agent's info object.
25
- * agentParams should look like this
26
- * {
27
- * name: "AGENT NAME",
28
- * version: "AGENT VERSION",
29
- * }
30
- */
14
+ * Create a client for RP.
15
+ * @param {Object} params - config object.
16
+ * params should look like this
17
+ * {
18
+ * token: "00000000-0000-0000-0000-000000000000",
19
+ * endpoint: "http://localhost:8080/api/v1",
20
+ * launch: "YOUR LAUNCH NAME",
21
+ * project: "PROJECT NAME",
22
+ * }
23
+ *
24
+ * @param {Object} agentParams - agent's info object.
25
+ * agentParams should look like this
26
+ * {
27
+ * name: "AGENT NAME",
28
+ * version: "AGENT VERSION",
29
+ * }
30
+ */
31
31
  constructor(params, agentParams) {
32
32
  this.debug = params.debug;
33
- this.isLaunchMergeRequired = params.isLaunchMergeRequired === undefined ? false : params.isLaunchMergeRequired;
33
+ this.isLaunchMergeRequired =
34
+ params.isLaunchMergeRequired === undefined ? false : params.isLaunchMergeRequired;
34
35
  this.map = {};
35
36
  this.baseURL = [params.endpoint, params.project].join('/');
36
37
  const headers = {
@@ -57,9 +58,9 @@ class RPClient {
57
58
  *
58
59
  * @Private
59
60
  */
60
- logDebug(msg) {
61
+ logDebug(msg, dataMsg = '') {
61
62
  if (this.debug) {
62
- console.log(msg);
63
+ console.log(msg, dataMsg);
63
64
  }
64
65
  }
65
66
 
@@ -82,14 +83,14 @@ class RPClient {
82
83
  let resolveFinish;
83
84
  let rejectFinish;
84
85
  const obj = {
85
- promiseStart: (new Promise(startPromiseFunc)),
86
+ promiseStart: new Promise(startPromiseFunc),
86
87
  realId: '',
87
88
  children: [],
88
89
  finishSend: false,
89
- promiseFinish: (new Promise((resolve, reject) => {
90
+ promiseFinish: new Promise((resolve, reject) => {
90
91
  resolveFinish = resolve;
91
92
  rejectFinish = reject;
92
- })),
93
+ }),
93
94
  };
94
95
  obj.resolveFinish = resolveFinish;
95
96
  obj.rejectFinish = rejectFinish;
@@ -185,9 +186,9 @@ class RPClient {
185
186
 
186
187
  this.map[tempId] = this.getNewItemObj((resolve, reject) => {
187
188
  const url = 'launch';
188
- this.logDebug(`Start launch ${tempId}`);
189
- this.restClient.create(url, launchData, { headers: this.headers })
190
- .then((response) => {
189
+ this.logDebug(`Start launch with tempId ${tempId}`, launchDataRQ);
190
+ this.restClient.create(url, launchData, { headers: this.headers }).then(
191
+ (response) => {
191
192
  this.map[tempId].realId = response.id;
192
193
  this.launchUuid = response.id;
193
194
 
@@ -195,11 +196,15 @@ class RPClient {
195
196
  helpers.saveLaunchIdToFile(response.id);
196
197
  }
197
198
 
199
+ this.logDebug(`Success start launch with tempId ${tempId}`, response);
198
200
  resolve(response);
199
- }, (error) => {
201
+ },
202
+ (error) => {
203
+ this.logDebug(`Error start launch with tempId ${tempId}`, error);
200
204
  console.dir(error);
201
205
  reject(error);
202
- });
206
+ },
207
+ );
203
208
  });
204
209
  }
205
210
  this.triggerAnalyticsEvent();
@@ -210,46 +215,57 @@ class RPClient {
210
215
  }
211
216
 
212
217
  /**
213
- * Finish launch.
214
- * @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
215
- * @param {Object} finishExecutionRQ - finish launch info should include time and status.
216
- * finishExecutionRQ should look like this
217
- * {
218
- * "endTime": this.helper.now(),
219
- * "status": "passed" or one of ‘passed’, ‘failed’, ‘stopped’, ‘skipped’, ‘interrupted’, ‘cancelled’
220
- * }
221
- * @Returns {Object} - an object which contains a tempID and a promise
222
- */
218
+ * Finish launch.
219
+ * @param {string} launchTempId - temp launch id (returned in the query "startLaunch").
220
+ * @param {Object} finishExecutionRQ - finish launch info should include time and status.
221
+ * finishExecutionRQ should look like this
222
+ * {
223
+ * "endTime": this.helper.now(),
224
+ * "status": "passed" or one of ‘passed’, ‘failed’, ‘stopped’, ‘skipped’, ‘interrupted’, ‘cancelled’
225
+ * }
226
+ * @Returns {Object} - an object which contains a tempID and a promise
227
+ */
223
228
  finishLaunch(launchTempId, finishExecutionRQ) {
224
229
  const launchObj = this.map[launchTempId];
225
230
  if (!launchObj) {
226
- return this.getRejectAnswer(launchTempId, new Error(`Launch "${launchTempId}" not found`));
231
+ return this.getRejectAnswer(
232
+ launchTempId,
233
+ new Error(`Launch with tempId "${launchTempId}" not found`),
234
+ );
227
235
  }
228
236
 
229
237
  const finishExecutionData = { endTime: this.helpers.now(), ...finishExecutionRQ };
230
238
 
231
239
  launchObj.finishSend = true;
232
- Promise.all(launchObj.children.map((itemId) => this.map[itemId].promiseFinish))
233
- .then(() => {
234
- launchObj.promiseStart
235
- .then(() => {
236
- this.logDebug(`Finish launch ${launchTempId}`);
240
+ Promise.all(launchObj.children.map((itemId) => this.map[itemId].promiseFinish)).then(
241
+ () => {
242
+ launchObj.promiseStart.then(
243
+ () => {
244
+ this.logDebug(`Finish launch with tempId ${launchTempId}`, finishExecutionData);
237
245
  const url = ['launch', launchObj.realId, 'finish'].join('/');
238
- this.restClient.update(url, finishExecutionData, { headers: this.headers })
239
- .then((response) => {
240
- this.logDebug(`Success finish launch ${launchTempId}`);
246
+ this.restClient.update(url, finishExecutionData, { headers: this.headers }).then(
247
+ (response) => {
248
+ this.logDebug(`Success finish launch with tempId ${launchTempId}`, response);
241
249
  launchObj.resolveFinish(response);
242
- }, (error) => {
243
- this.logDebug(`Error finish launch ${launchTempId}`);
250
+ },
251
+ (error) => {
252
+ this.logDebug(`Error finish launch with tempId ${launchTempId}`, error);
244
253
  console.dir(error);
245
254
  launchObj.rejectFinish(error);
246
- });
247
- }, (error) => {
255
+ },
256
+ );
257
+ },
258
+ (error) => {
259
+ console.dir(error);
248
260
  launchObj.rejectFinish(error);
249
- });
250
- }, (error) => {
261
+ },
262
+ );
263
+ },
264
+ (error) => {
265
+ console.dir(error);
251
266
  launchObj.rejectFinish(error);
252
- });
267
+ },
268
+ );
253
269
 
254
270
  return {
255
271
  tempId: launchTempId,
@@ -258,29 +274,29 @@ class RPClient {
258
274
  }
259
275
 
260
276
  /*
261
- * This method is used to create data object for merge request to ReportPortal.
262
- *
263
- * @Returns {Object} - an object which contains a data for merge launches in ReportPortal.
264
- */
277
+ * This method is used to create data object for merge request to ReportPortal.
278
+ *
279
+ * @Returns {Object} - an object which contains a data for merge launches in ReportPortal.
280
+ */
265
281
  getMergeLaunchesRequest(launchIds) {
266
282
  return {
267
- description: "Merged launch",
283
+ description: 'Merged launch',
268
284
  endTime: this.helpers.now(),
269
285
  extendSuitesDescription: true,
270
286
  launches: launchIds,
271
- mergeType: "BASIC",
272
- mode: "DEFAULT",
287
+ mergeType: 'BASIC',
288
+ mode: 'DEFAULT',
273
289
  name: this.config.launch || 'Test launch name',
274
290
  attributes: this.config.attributes,
275
291
  };
276
292
  }
277
293
 
278
294
  /*
279
- * This method is used for merge launches in ReportPortal.
280
- *
281
- * Please, keep in mind that this method is work only in case
282
- * the option isLaunchMergeRequired is true.
283
- */
295
+ * This method is used for merge launches in ReportPortal.
296
+ *
297
+ * Please, keep in mind that this method is work only in case
298
+ * the option isLaunchMergeRequired is true.
299
+ */
284
300
  mergeLaunches() {
285
301
  if (this.isLaunchMergeRequired) {
286
302
  const launchUUIds = helpers.readLaunchesFromFile();
@@ -288,37 +304,46 @@ class RPClient {
288
304
  'filter.in.uuid': launchUUIds,
289
305
  });
290
306
  const launchSearchUrl = `launch?${params.toString()}`;
291
- return this.restClient.retrieveSyncAPI(launchSearchUrl, { headers: this.headers })
292
- .then((response) => {
293
- const launchIds = response.content.map((launch) => launch.id);
294
- this.logDebug(`Found launches: ${launchIds}`);
295
- return launchIds;
296
- }, (error) => {
297
- console.dir(error);
298
- })
307
+ this.logDebug(`Find launches with UUIDs to merge: ${launchUUIds}`);
308
+ return this.restClient
309
+ .retrieveSyncAPI(launchSearchUrl, { headers: this.headers })
310
+ .then(
311
+ (response) => {
312
+ const launchIds = response.content.map((launch) => launch.id);
313
+ this.logDebug(`Found launches: ${launchIds}`, response.content);
314
+ return launchIds;
315
+ },
316
+ (error) => {
317
+ this.logDebug(`Error during launches search with UUIDs: ${launchUUIds}`, error);
318
+ console.dir(error);
319
+ },
320
+ )
299
321
  .then((launchIds) => {
300
322
  const request = this.getMergeLaunchesRequest(launchIds);
323
+ this.logDebug(`Merge launches with ids: ${launchIds}`, request);
301
324
  const mergeURL = 'launch/merge';
302
325
  return this.restClient.create(mergeURL, request, { headers: this.headers });
303
326
  })
304
327
  .then(() => {
305
- this.logDebug(`Launches successfully merged!`);
328
+ this.logDebug(`Launches with UUIDs: ${launchUUIds} were successfully merged!`);
306
329
  })
307
330
  .catch((error) => {
308
- this.logDebug('ERROR');
309
- this.logDebug(error);
331
+ this.logDebug(`Error merging launches with UUIDs: ${launchUUIds}`, error);
332
+ console.dir(error);
310
333
  });
311
334
  }
312
- this.logDebug('Option isLaunchMergeRequired is false');
335
+ this.logDebug(
336
+ 'Option isLaunchMergeRequired is false, merge process cannot be done as no launch UUIDs where saved.',
337
+ );
313
338
  }
314
339
 
315
340
  /*
316
- * This method is used for frameworks as Jasmine. There is problem when
317
- * it doesn't wait for promise resolve and stop the process. So it better to call
318
- * this method at the spec's function as @afterAll() and manually resolve this promise.
319
- *
320
- * @return Promise
321
- */
341
+ * This method is used for frameworks as Jasmine. There is problem when
342
+ * it doesn't wait for promise resolve and stop the process. So it better to call
343
+ * this method at the spec's function as @afterAll() and manually resolve this promise.
344
+ *
345
+ * @return Promise
346
+ */
322
347
  getPromiseFinishAllItems(launchTempId) {
323
348
  const launchObj = this.map[launchTempId];
324
349
  return Promise.all(launchObj.children.map((itemId) => this.map[itemId].promiseFinish));
@@ -347,7 +372,10 @@ class RPClient {
347
372
  updateLaunch(launchTempId, launchData) {
348
373
  const launchObj = this.map[launchTempId];
349
374
  if (!launchObj) {
350
- return this.getRejectAnswer(launchTempId, new Error(`Launch "${launchTempId}" not found`));
375
+ return this.getRejectAnswer(
376
+ launchTempId,
377
+ new Error(`Launch with tempId "${launchTempId}" not found`),
378
+ );
351
379
  }
352
380
  let resolvePromise;
353
381
  let rejectPromise;
@@ -356,17 +384,26 @@ class RPClient {
356
384
  rejectPromise = reject;
357
385
  });
358
386
 
359
- launchObj.promiseFinish.then(() => {
360
- const url = ['launch', launchObj.realId, 'update'].join('/');
361
- this.restClient.update(url, launchData, { headers: this.headers })
362
- .then((response) => {
363
- resolvePromise(response);
364
- }, (error) => {
365
- rejectPromise(error);
366
- });
367
- }, (error) => {
368
- rejectPromise(error);
369
- });
387
+ launchObj.promiseFinish.then(
388
+ () => {
389
+ const url = ['launch', launchObj.realId, 'update'].join('/');
390
+ this.logDebug(`Update launch with tempId ${launchTempId}`, launchData);
391
+ this.restClient.update(url, launchData, { headers: this.headers }).then(
392
+ (response) => {
393
+ this.logDebug(`Launch with tempId ${launchTempId} were successfully updated`, response);
394
+ resolvePromise(response);
395
+ },
396
+ (error) => {
397
+ this.logDebug(`Error when updating launch with tempId ${launchTempId}`, error);
398
+ console.dir(error);
399
+ rejectPromise(error);
400
+ },
401
+ );
402
+ },
403
+ (error) => {
404
+ rejectPromise(error);
405
+ },
406
+ );
370
407
  return {
371
408
  tempId: launchTempId,
372
409
  promise,
@@ -404,23 +441,37 @@ class RPClient {
404
441
  let parentMapId = launchTempId;
405
442
  const launchObj = this.map[launchTempId];
406
443
  if (!launchObj) {
407
- return this.getRejectAnswer(launchTempId, new Error(`Launch "${launchTempId}" not found`));
444
+ return this.getRejectAnswer(
445
+ launchTempId,
446
+ new Error(`Launch with tempId "${launchTempId}" not found`),
447
+ );
408
448
  }
449
+ // TODO: Allow items reporting to finished launch
409
450
  if (launchObj.finishSend) {
410
- const err = new Error(`Launch "${launchTempId}" is already finished, you can not add an item to it`);
451
+ const err = new Error(
452
+ `Launch with tempId "${launchTempId}" is already finished, you can not add an item to it`,
453
+ );
411
454
  return this.getRejectAnswer(launchTempId, err);
412
455
  }
413
456
 
414
- const testCaseId = testItemDataRQ.testCaseId
415
- || helpers.generateTestCaseId(testItemDataRQ.codeRef, testItemDataRQ.parameters);
416
- const testItemData = { startTime: this.helpers.now(), ...testItemDataRQ, ...(testCaseId && { testCaseId }) };
457
+ const testCaseId =
458
+ testItemDataRQ.testCaseId ||
459
+ helpers.generateTestCaseId(testItemDataRQ.codeRef, testItemDataRQ.parameters);
460
+ const testItemData = {
461
+ startTime: this.helpers.now(),
462
+ ...testItemDataRQ,
463
+ ...(testCaseId && { testCaseId }),
464
+ };
417
465
 
418
466
  let parentPromise = launchObj.promiseStart;
419
467
  if (parentTempId) {
420
468
  parentMapId = parentTempId;
421
469
  const parentObj = this.map[parentTempId];
422
470
  if (!parentObj) {
423
- return this.getRejectAnswer(launchTempId, new Error(`Item "${parentTempId}" not found`));
471
+ return this.getRejectAnswer(
472
+ launchTempId,
473
+ new Error(`Item with tempId "${parentTempId}" not found`),
474
+ );
424
475
  }
425
476
  parentPromise = parentObj.promiseStart;
426
477
  }
@@ -438,29 +489,34 @@ class RPClient {
438
489
 
439
490
  const tempId = this.getUniqId();
440
491
  this.map[tempId] = this.getNewItemObj((resolve, reject) => {
441
- parentPromise.then(() => {
442
- const realLaunchId = this.map[launchTempId].realId;
443
- let url = 'item/';
444
- if (parentTempId) {
445
- const realParentId = this.map[parentTempId].realId;
446
- url += `${realParentId}`;
447
- }
448
- testItemData.launchUuid = realLaunchId;
449
- this.logDebug(`Start test item ${tempId}`);
450
- this.restClient.create(url, testItemData, { headers: this.headers })
451
- .then((response) => {
452
- this.logDebug(`Success start item ${tempId}`);
453
- this.map[tempId].realId = response.id;
454
- this.nonRetriedItemMap.delete(itemKey);
455
- resolve(response);
456
- }, (error) => {
457
- this.logDebug(`Error start item ${tempId}:`);
458
- console.dir(error);
459
- reject(error);
460
- });
461
- }, (error) => {
462
- reject(error);
463
- });
492
+ parentPromise.then(
493
+ () => {
494
+ const realLaunchId = this.map[launchTempId].realId;
495
+ let url = 'item/';
496
+ if (parentTempId) {
497
+ const realParentId = this.map[parentTempId].realId;
498
+ url += `${realParentId}`;
499
+ }
500
+ testItemData.launchUuid = realLaunchId;
501
+ this.logDebug(`Start test item with tempId ${tempId}`, testItemData);
502
+ this.restClient.create(url, testItemData, { headers: this.headers }).then(
503
+ (response) => {
504
+ this.logDebug(`Success start item with tempId ${tempId}`, response);
505
+ this.map[tempId].realId = response.id;
506
+ this.nonRetriedItemMap.delete(itemKey);
507
+ resolve(response);
508
+ },
509
+ (error) => {
510
+ this.logDebug(`Error start item with tempId ${tempId}`, error);
511
+ console.dir(error);
512
+ reject(error);
513
+ },
514
+ );
515
+ },
516
+ (error) => {
517
+ reject(error);
518
+ },
519
+ );
464
520
  });
465
521
  this.map[parentMapId].children.push(tempId);
466
522
 
@@ -501,7 +557,10 @@ class RPClient {
501
557
  finishTestItem(itemTempId, finishTestItemRQ) {
502
558
  const itemObj = this.map[itemTempId];
503
559
  if (!itemObj) {
504
- return this.getRejectAnswer(itemTempId, new Error(`Item "${itemTempId}" not found`));
560
+ return this.getRejectAnswer(
561
+ itemTempId,
562
+ new Error(`Item with tempId "${itemTempId}" not found`),
563
+ );
505
564
  }
506
565
 
507
566
  const finishTestItemData = {
@@ -511,24 +570,33 @@ class RPClient {
511
570
  };
512
571
 
513
572
  itemObj.finishSend = true;
514
- Promise.all(itemObj.children.map((itemId) => this.map[itemId] && this.map[itemId].promiseFinish))
515
- .then(() => {
573
+ this.logDebug(`Finish all children for test item with tempId ${itemTempId}`);
574
+ Promise.all(
575
+ itemObj.children.map((itemId) => this.map[itemId] && this.map[itemId].promiseFinish),
576
+ ).then(
577
+ () => {
516
578
  this.cleanMap(itemObj.children);
579
+ this.logDebug(
580
+ `All children for test item with tempId ${itemTempId} successfully finished.`,
581
+ );
582
+ this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
517
583
  this.finishTestItemPromiseStart(
518
584
  itemObj,
519
585
  itemTempId,
520
586
  Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
521
587
  );
522
- }, () => {
588
+ },
589
+ () => {
523
590
  this.cleanMap(itemObj.children);
524
- this.logDebug(`Error finish children of test item ${itemTempId}`);
525
- this.logDebug(`Finish test item ${itemTempId}`);
591
+ this.logDebug(`Error finish children of test item with tempId ${itemTempId}`);
592
+ this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
526
593
  this.finishTestItemPromiseStart(
527
594
  itemObj,
528
595
  itemTempId,
529
596
  Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
530
597
  );
531
- });
598
+ },
599
+ );
532
600
 
533
601
  return {
534
602
  tempId: itemTempId,
@@ -539,24 +607,34 @@ class RPClient {
539
607
  saveLog(itemObj, requestPromiseFunc) {
540
608
  const tempId = this.getUniqId();
541
609
  this.map[tempId] = this.getNewItemObj((resolve, reject) => {
542
- itemObj.promiseStart.then(() => {
543
- this.logDebug(`Save log ${tempId}`);
544
- requestPromiseFunc(itemObj.realId, this.launchUuid).then((response) => {
545
- this.logDebug(`Successfully save log ${tempId}`);
546
- resolve(response);
547
- }, (error) => {
548
- this.logDebug(`Error finish log: ${error}`);
610
+ itemObj.promiseStart.then(
611
+ () => {
612
+ this.logDebug(`Save log with tempId ${tempId}`, itemObj);
613
+ requestPromiseFunc(itemObj.realId, this.launchUuid).then(
614
+ (response) => {
615
+ this.logDebug(`Successfully save log with tempId ${tempId}`, response);
616
+ resolve(response);
617
+ },
618
+ (error) => {
619
+ this.logDebug(`Error save log with tempId ${tempId}`, error);
620
+ console.dir(error);
621
+ reject(error);
622
+ },
623
+ );
624
+ },
625
+ (error) => {
549
626
  reject(error);
550
- });
551
- }, (error) => {
552
- reject(error);
553
- });
627
+ },
628
+ );
554
629
  });
555
630
  itemObj.children.push(tempId);
556
631
 
557
632
  const logObj = this.map[tempId];
558
633
  logObj.finishSend = true;
559
- logObj.promiseStart.then((response) => logObj.resolveFinish(response), (error) => logObj.rejectFinish(error));
634
+ logObj.promiseStart.then(
635
+ (response) => logObj.resolveFinish(response),
636
+ (error) => logObj.rejectFinish(error),
637
+ );
560
638
 
561
639
  return {
562
640
  tempId,
@@ -579,21 +657,24 @@ class RPClient {
579
657
  }
580
658
 
581
659
  /**
582
- * Send log of test results.
583
- * @param {string} itemTempId - temp item id (returned in the query "startTestItem").
584
- * @param {Object} saveLogRQ - object with data of test result.
585
- * saveLogRQ should look like this
586
- * {
587
- * level: 'error' or one of 'trace', 'debug', 'info', 'warn', 'error', '',
588
- * message: 'string' (support markdown),
589
- * time: this.helpers.now()
590
- * }
591
- * @Returns {Object} - an object which contains a tempId and a promise
592
- */
660
+ * Send log of test results.
661
+ * @param {string} itemTempId - temp item id (returned in the query "startTestItem").
662
+ * @param {Object} saveLogRQ - object with data of test result.
663
+ * saveLogRQ should look like this
664
+ * {
665
+ * level: 'error' or one of 'trace', 'debug', 'info', 'warn', 'error', '',
666
+ * message: 'string' (support markdown),
667
+ * time: this.helpers.now()
668
+ * }
669
+ * @Returns {Object} - an object which contains a tempId and a promise
670
+ */
593
671
  sendLogWithoutFile(itemTempId, saveLogRQ) {
594
672
  const itemObj = this.map[itemTempId];
595
673
  if (!itemObj) {
596
- return this.getRejectAnswer(itemTempId, new Error(`Item "${itemTempId}" not found`));
674
+ return this.getRejectAnswer(
675
+ itemTempId,
676
+ new Error(`Item with tempId "${itemTempId}" not found`),
677
+ );
597
678
  }
598
679
 
599
680
  const requestPromise = (itemUuid, launchUuid) => {
@@ -601,11 +682,7 @@ class RPClient {
601
682
  const isItemUuid = itemUuid !== launchUuid;
602
683
  return this.restClient.create(
603
684
  url,
604
- Object.assign(
605
- saveLogRQ,
606
- { launchUuid },
607
- isItemUuid && { itemUuid },
608
- ),
685
+ Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }),
609
686
  { headers: this.headers },
610
687
  );
611
688
  };
@@ -636,14 +713,19 @@ class RPClient {
636
713
  sendLogWithFile(itemTempId, saveLogRQ, fileObj) {
637
714
  const itemObj = this.map[itemTempId];
638
715
  if (!itemObj) {
639
- return this.getRejectAnswer(itemTempId, new Error(`Item "${itemTempId}" not found`));
716
+ return this.getRejectAnswer(
717
+ itemTempId,
718
+ new Error(`Item with tempId "${itemTempId}" not found`),
719
+ );
640
720
  }
641
- // eslint-disable-next-line max-len
721
+
642
722
  const requestPromise = (itemUuid, launchUuid) => {
643
723
  const isItemUuid = itemUuid !== launchUuid;
644
724
 
645
- // eslint-disable-next-line max-len
646
- return this.getRequestLogWithFile(Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }), fileObj);
725
+ return this.getRequestLogWithFile(
726
+ Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }),
727
+ fileObj,
728
+ );
647
729
  };
648
730
 
649
731
  return this.saveLog(itemObj, requestPromise);
@@ -653,17 +735,21 @@ class RPClient {
653
735
  const url = 'log';
654
736
  // eslint-disable-next-line no-param-reassign
655
737
  saveLogRQ.file = { name: fileObj.name };
656
- return this.restClient.create(
657
- url,
658
- this.buildMultiPartStream([saveLogRQ], fileObj, MULTIPART_BOUNDARY),
659
- {
660
- headers: { ...this.headers, 'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}` },
661
- },
662
- )
663
- .then((response) => response)
738
+ this.logDebug(`Save log with file: ${fileObj.name}`, saveLogRQ);
739
+ return this.restClient
740
+ .create(url, this.buildMultiPartStream([saveLogRQ], fileObj, MULTIPART_BOUNDARY), {
741
+ headers: {
742
+ ...this.headers,
743
+ 'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}`,
744
+ },
745
+ })
746
+ .then((response) => {
747
+ this.logDebug(`Success save log with file: ${fileObj.name}`, response);
748
+ return response;
749
+ })
664
750
  .catch((error) => {
665
- this.logDebug('ERROR');
666
- this.logDebug(error);
751
+ this.logDebug(`Error save log with file: ${fileObj.name}`, error);
752
+ console.dir(error);
667
753
  });
668
754
  }
669
755
 
@@ -673,21 +759,36 @@ class RPClient {
673
759
  * @Private
674
760
  */
675
761
  buildMultiPartStream(jsonPart, filePart, boundary) {
676
- const eol = "\r\n";
762
+ const eol = '\r\n';
677
763
  const bx = `--${boundary}`;
678
764
  const buffers = [
679
765
  // eslint-disable-next-line function-paren-newline
680
766
  Buffer.from(
681
767
  // eslint-disable-next-line prefer-template
682
- bx + eol + "Content-Disposition: form-data; name=\"json_request_part\""
683
- + eol + "Content-Type: application/json" + eol
684
- + eol + eol + JSON.stringify(jsonPart) + eol,
768
+ bx +
769
+ eol +
770
+ 'Content-Disposition: form-data; name="json_request_part"' +
771
+ eol +
772
+ 'Content-Type: application/json' +
773
+ eol +
774
+ eol +
775
+ eol +
776
+ JSON.stringify(jsonPart) +
777
+ eol,
685
778
  ),
686
779
  // eslint-disable-next-line function-paren-newline
687
780
  Buffer.from(
688
781
  // eslint-disable-next-line prefer-template
689
- bx + eol + "Content-Disposition: form-data; name=\"file\"; filename=\"" + filePart.name + "\"" + eol
690
- + "Content-Type: " + filePart.type + eol + eol,
782
+ bx +
783
+ eol +
784
+ 'Content-Disposition: form-data; name="file"; filename="' +
785
+ filePart.name +
786
+ '"' +
787
+ eol +
788
+ 'Content-Type: ' +
789
+ filePart.type +
790
+ eol +
791
+ eol,
691
792
  ),
692
793
  Buffer.from(filePart.content, 'base64'),
693
794
  Buffer.from(`${eol + bx}--${eol}`),
@@ -696,23 +797,30 @@ class RPClient {
696
797
  }
697
798
 
698
799
  finishTestItemPromiseStart(itemObj, itemTempId, finishTestItemData) {
699
- itemObj.promiseStart
700
- .then(() => {
800
+ itemObj.promiseStart.then(
801
+ () => {
701
802
  const url = ['item', itemObj.realId].join('/');
702
- this.logDebug(`Finish test item ${itemTempId}`);
703
- // eslint-disable-next-line max-len
704
- this.restClient.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid }), { headers: this.headers })
705
- .then((response) => {
706
- this.logDebug(`Success finish item ${itemTempId}`);
707
- itemObj.resolveFinish(response);
708
- }, (error) => {
709
- this.logDebug(`Error finish test item ${itemTempId}`);
710
- console.dir(error);
711
- itemObj.rejectFinish(error);
712
- });
713
- }, (error) => {
803
+ this.logDebug(`Finish test item with tempId ${itemTempId}`, itemObj);
804
+ this.restClient
805
+ .update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid }), {
806
+ headers: this.headers,
807
+ })
808
+ .then(
809
+ (response) => {
810
+ this.logDebug(`Success finish item with tempId ${itemTempId}`, response);
811
+ itemObj.resolveFinish(response);
812
+ },
813
+ (error) => {
814
+ this.logDebug(`Error finish test item with tempId ${itemTempId}`, error);
815
+ console.dir(error);
816
+ itemObj.rejectFinish(error);
817
+ },
818
+ );
819
+ },
820
+ (error) => {
714
821
  itemObj.rejectFinish(error);
715
- });
822
+ },
823
+ );
716
824
  }
717
825
  }
718
826
 
package/lib/rest.js CHANGED
@@ -5,7 +5,11 @@ const https = require('https');
5
5
 
6
6
  const DEFAULT_MAX_CONNECTION_TIME_MS = 30000;
7
7
 
8
- axiosRetry(axios, { retryDelay: () => 100, retries: 10, retryCondition: axiosRetry.isRetryableError });
8
+ axiosRetry(axios, {
9
+ retryDelay: () => 100,
10
+ retries: 10,
11
+ retryCondition: axiosRetry.isRetryableError,
12
+ });
9
13
 
10
14
  class RestClient {
11
15
  constructor(options) {
@@ -34,11 +38,16 @@ class RestClient {
34
38
  .catch((error) => {
35
39
  const errorMessage = error.message;
36
40
  const responseData = error.response && error.response.data;
37
- throw new Error(`${errorMessage}${
38
- responseData
39
- && typeof responseData === 'object'
40
- ? `: ${JSON.stringify(responseData)}`
41
- : ''}`);
41
+ throw new Error(
42
+ `${errorMessage}${
43
+ responseData && typeof responseData === 'object'
44
+ ? `: ${JSON.stringify(responseData)}`
45
+ : ''
46
+ }
47
+ URL: ${url}
48
+ method: ${method}
49
+ Request data: ${JSON.stringify(data)}`,
50
+ );
42
51
  });
43
52
  }
44
53
 
@@ -65,24 +74,33 @@ class RestClient {
65
74
  }
66
75
 
67
76
  create(path, data, options = { headers: this.headers }) {
68
- return RestClient.request('POST', this.buildPath(path), data, { ...options, ...this.getRestConfig() });
77
+ return RestClient.request('POST', this.buildPath(path), data, {
78
+ ...options,
79
+ ...this.getRestConfig(),
80
+ });
69
81
  }
70
82
 
71
83
  retrieve(path, options = { headers: this.headers }) {
72
- return RestClient.request('GET', this.buildPath(path), {}, { ...options, ...this.getRestConfig() });
84
+ return RestClient.request(
85
+ 'GET',
86
+ this.buildPath(path),
87
+ {},
88
+ { ...options, ...this.getRestConfig() },
89
+ );
73
90
  }
74
91
 
75
92
  update(path, data, options = { headers: this.headers }) {
76
- return RestClient.request('PUT', this.buildPath(path), data, { ...options, ...this.getRestConfig() });
93
+ return RestClient.request('PUT', this.buildPath(path), data, {
94
+ ...options,
95
+ ...this.getRestConfig(),
96
+ });
77
97
  }
78
98
 
79
99
  delete(path, data, options = { headers: this.headers }) {
80
- return RestClient.request(
81
- 'DELETE',
82
- this.buildPath(path),
83
- data,
84
- { ...options, ...this.getRestConfig() },
85
- );
100
+ return RestClient.request('DELETE', this.buildPath(path), data, {
101
+ ...options,
102
+ ...this.getRestConfig(),
103
+ });
86
104
  }
87
105
 
88
106
  retrieveSyncAPI(path, options = { headers: this.headers }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/client-javascript",
3
- "version": "5.0.6",
3
+ "version": "5.0.7",
4
4
  "description": "ReportPortal client for node.js",
5
5
  "author": "ReportPortal.io",
6
6
  "contributors": [
@@ -31,15 +31,17 @@
31
31
  "node": ">= 10.0.0"
32
32
  },
33
33
  "dependencies": {
34
- "axios": "^0.24.0",
34
+ "axios": "^0.27.2",
35
35
  "axios-retry": "^3.2.4",
36
36
  "glob": "^7.2.0",
37
37
  "uniqid": "^5.4.0",
38
- "universal-analytics": "^0.4.20"
38
+ "universal-analytics": "^0.5.3"
39
39
  },
40
40
  "license": "Apache-2.0",
41
41
  "scripts": {
42
- "lint": "eslint . --quiet",
42
+ "build": "npm run clean && tsc",
43
+ "clean": "rimraf ./build",
44
+ "lint": "eslint ./analytics/**/* ./lib/**/* ./spec/**/*",
43
45
  "format": "npm run lint -- --fix",
44
46
  "test": "nyc ./node_modules/jasmine/bin/jasmine.js",
45
47
  "test:coverage": "nyc report --reporter=lcov --reporter=text-summary"
@@ -47,12 +49,24 @@
47
49
  "devDependencies": {
48
50
  "eslint": "^7.32.0",
49
51
  "eslint-config-airbnb-base": "^15.0.0",
50
- "eslint-plugin-import": "^2.25.4",
52
+ "eslint-plugin-import": "^2.26.0",
51
53
  "eslint-plugin-node": "^11.1.0",
54
+ "typescript": "^4.7.4",
52
55
  "jasmine": "^3.5.0",
53
56
  "lodash": "^4.17.11",
54
- "nock": "^10.0.6",
55
- "nyc": "^15.1.0"
57
+ "nock": "^13.2.9",
58
+ "nyc": "^15.1.0",
59
+ "prettier": "^2.7.1",
60
+ "rimraf": "^3.0.2",
61
+ "@types/jasmine": "^4.0.3",
62
+ "@types/node": "^18.7.6",
63
+ "@typescript-eslint/eslint-plugin": "^5.33.1",
64
+ "@typescript-eslint/parser": "^5.33.1",
65
+ "eslint-config-airbnb-typescript": "^17.0.0",
66
+ "eslint-config-prettier": "^8.5.0",
67
+ "eslint-plugin-prettier": "^4.2.1",
68
+ "jasmine-ts": "^0.4.0",
69
+ "ts-node": "^10.9.1"
56
70
  },
57
71
  "bugs": {
58
72
  "url": "https://github.com/reportportal/client-javascript/issues"