@reportportal/client-javascript 5.1.0 → 5.1.2

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
@@ -6,17 +6,18 @@ Library is used only for implementors of custom listeners for ReportPortal.
6
6
 
7
7
  ## Already implemented listeners:
8
8
 
9
- * [Jest integration](https://github.com/reportportal/agent-js-jest)
9
+ * [Playwright integration](https://github.com/reportportal/agent-js-playwright)
10
10
  * [Cypress integration](https://github.com/reportportal/agent-js-cypress)
11
+ * [Jest integration](https://github.com/reportportal/agent-js-jest)
11
12
  * [Mocha integration](https://github.com/reportportal/agent-js-mocha)
12
- * [Jasmine integration](https://github.com/reportportal/agent-js-jasmine)
13
- * [Nightwatch integration](https://github.com/reportportal/agent-js-nightwatch)
14
- * [Cucumber integration](https://github.com/reportportal/agent-js-cucumber)
15
- * [Codecept integration](https://github.com/reportportal/agent-js-codecept)
13
+ * [Webdriverio integration](https://github.com/reportportal/agent-js-webdriverio)
16
14
  * [Postman integration](https://github.com/reportportal/agent-js-postman)
15
+ * [Cucumber integration](https://github.com/reportportal/agent-js-cucumber)
16
+ * [Vitest integration](https://github.com/reportportal/agent-js-vitest)
17
+ * [Jasmine integration](https://github.com/reportportal/agent-js-jasmine)
17
18
  * [TestCafe integration](https://github.com/reportportal/agent-js-testcafe)
18
- * [Webdriverio integration](https://github.com/reportportal/agent-js-webdriverio)
19
- * [Playwright integration](https://github.com/reportportal/agent-js-playwright)
19
+ * [Codecept integration](https://github.com/reportportal/agent-js-codecept)
20
+ * [Nightwatch integration](https://github.com/reportportal/agent-js-nightwatch)
20
21
 
21
22
  Examples for test framework integrations from the list above described in [examples](https://github.com/reportportal/examples-js) repository.
22
23
 
@@ -61,7 +62,7 @@ When creating a client instance, you need to specify the following options:
61
62
  | headers | Optional | {} | The object with custom headers for internal http client. |
62
63
  | debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
63
64
  | isLaunchMergeRequired | Optional | false | Allows client to merge launches into one at the end of the run via saving their UUIDs to the temp files at filesystem . At the end of the run launches can be merged using `mergeLaunches` method. Temp file format: `rplaunch-${launch_uuid}.tmp`. |
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
+ | restClientConfig | Optional | Not set | `axios` like http client [config](https://github.com/axios/axios#request-config). May contain `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, and other client options eg. `timeout`. For debugging and displaying logs you can set `debug: true`. |
65
66
  | launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
66
67
  | launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if `launchUuidPrint` set to `true`. |
67
68
  | token | Deprecated | Not set | Use `apiKey` instead. |
package/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.1-SNAPSHOT
1
+ 5.1.3-SNAPSHOT
@@ -53,7 +53,8 @@ class RPClient {
53
53
  });
54
54
  this.statistics = new Statistics(EVENT_NAME, agentParams);
55
55
  this.launchUuid = '';
56
- this.nonRetriedItemMap = new Map();
56
+ this.itemRetriesChainMap = new Map();
57
+ this.itemRetriesChainKeyMapByTempId = new Map();
57
58
  }
58
59
 
59
60
  // eslint-disable-next-line valid-jsdoc
@@ -67,10 +68,27 @@ class RPClient {
67
68
  }
68
69
  }
69
70
 
70
- calculateNonRetriedItemMapKey(launchId, parentId, name, itemId = '') {
71
+ calculateItemRetriesChainMapKey(launchId, parentId, name, itemId = '') {
71
72
  return `${launchId}__${parentId}__${name}__${itemId}`;
72
73
  }
73
74
 
75
+ // eslint-disable-next-line valid-jsdoc
76
+ /**
77
+ *
78
+ * @Private
79
+ */
80
+ cleanItemRetriesChain(tempIds) {
81
+ tempIds.forEach((id) => {
82
+ const key = this.itemRetriesChainKeyMapByTempId.get(id);
83
+
84
+ if (key) {
85
+ this.itemRetriesChainMap.delete(key);
86
+ }
87
+
88
+ this.itemRetriesChainKeyMapByTempId.delete(id);
89
+ });
90
+ }
91
+
74
92
  getUniqId() {
75
93
  return UniqId();
76
94
  }
@@ -488,20 +506,17 @@ class RPClient {
488
506
  parentPromise = parentObj.promiseStart;
489
507
  }
490
508
 
491
- const itemKey = this.calculateNonRetriedItemMapKey(
509
+ const itemKey = this.calculateItemRetriesChainMapKey(
492
510
  launchTempId,
493
511
  parentTempId,
494
512
  testItemDataRQ.name,
495
513
  testItemDataRQ.uniqueId,
496
514
  );
497
- const firstNonRetriedItemPromise = testItemDataRQ.retry && this.nonRetriedItemMap.get(itemKey);
498
- if (firstNonRetriedItemPromise) {
499
- parentPromise = Promise.all([parentPromise, firstNonRetriedItemPromise]);
500
- }
515
+ const executionItemPromise = testItemDataRQ.retry && this.itemRetriesChainMap.get(itemKey);
501
516
 
502
517
  const tempId = this.getUniqId();
503
518
  this.map[tempId] = this.getNewItemObj((resolve, reject) => {
504
- parentPromise.then(
519
+ (executionItemPromise || parentPromise).then(
505
520
  () => {
506
521
  const realLaunchId = this.map[launchTempId].realId;
507
522
  let url = 'item/';
@@ -515,7 +530,6 @@ class RPClient {
515
530
  (response) => {
516
531
  this.logDebug(`Success start item with tempId ${tempId}`, response);
517
532
  this.map[tempId].realId = response.id;
518
- this.nonRetriedItemMap.delete(itemKey);
519
533
  resolve(response);
520
534
  },
521
535
  (error) => {
@@ -531,10 +545,8 @@ class RPClient {
531
545
  );
532
546
  });
533
547
  this.map[parentMapId].children.push(tempId);
534
-
535
- if (!testItemDataRQ.retry) {
536
- this.nonRetriedItemMap.set(itemKey, this.map[tempId].promiseStart);
537
- }
548
+ this.itemRetriesChainKeyMapByTempId.set(tempId, itemKey);
549
+ this.itemRetriesChainMap.set(itemKey, this.map[tempId].promiseStart);
538
550
 
539
551
  return {
540
552
  tempId,
@@ -602,7 +614,7 @@ class RPClient {
602
614
  }
603
615
  });
604
616
  }
605
-
617
+ this.cleanItemRetriesChain(itemObj.children);
606
618
  this.cleanMap(itemObj.children);
607
619
 
608
620
  this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
package/lib/rest.js CHANGED
@@ -16,6 +16,8 @@ class RestClient {
16
16
  this.baseURL = options.baseURL;
17
17
  this.headers = options.headers;
18
18
  this.restClientConfig = options.restClientConfig;
19
+
20
+ addLogger(this.restClientConfig ? this.restClientConfig.debug : false);
19
21
  }
20
22
 
21
23
  buildPath(path) {
@@ -112,4 +114,45 @@ method: ${method}`,
112
114
  }
113
115
  }
114
116
 
117
+ const addLogger = (debug) => {
118
+ if (debug) {
119
+ axios.interceptors.request.use((config) => {
120
+ const startDate = new Date();
121
+ config.startTime = startDate.valueOf();
122
+
123
+ console.log(`Request method=${config.method} url=${config.url} [${startDate.toISOString()}]`);
124
+
125
+ return config;
126
+ });
127
+
128
+ axios.interceptors.response.use(
129
+ (response) => {
130
+ const date = new Date();
131
+ const { status, config } = response;
132
+
133
+ console.log(
134
+ `Response status=${status} url=${config.url} time=${
135
+ date.valueOf() - config.startTime
136
+ }ms [${date.toISOString()}]`,
137
+ );
138
+
139
+ return response;
140
+ },
141
+ (error) => {
142
+ const date = new Date();
143
+ const { response, config } = error;
144
+ const status = response ? response.status : null;
145
+
146
+ console.log(
147
+ `Response ${status ? 'status=' + status : "message='" + error.message + "'"} url=${
148
+ config.url
149
+ } time=${date.valueOf() - config.startTime}ms [${date.toISOString()}]`,
150
+ );
151
+
152
+ return Promise.reject(error);
153
+ },
154
+ );
155
+ }
156
+ };
157
+
115
158
  module.exports = RestClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/client-javascript",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "ReportPortal client for Node.js",
5
5
  "author": "ReportPortal.io",
6
6
  "scripts": {