@reportportal/client-javascript 5.1.3 → 5.2.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.
- package/README.md +15 -15
- package/VERSION +1 -1
- package/lib/helpers.js +2 -1
- package/lib/logger.js +41 -0
- package/lib/report-portal-client.js +18 -15
- package/lib/rest.js +38 -65
- package/package.json +9 -10
package/README.md
CHANGED
|
@@ -53,24 +53,24 @@ rpClient.checkConnect().then((response) => {
|
|
|
53
53
|
|
|
54
54
|
When creating a client instance, you need to specify the following options:
|
|
55
55
|
|
|
56
|
-
| Option | Necessity | Default | Description
|
|
57
|
-
|
|
58
|
-
| apiKey | Required | | User's reportportal token from which you want to send requests. It can be found on the profile page of this user.
|
|
59
|
-
| 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'.
|
|
60
|
-
| launch | Required | | Name of the launch at creation.
|
|
61
|
-
| project | Required | | The name of the project in which the launches will be created.
|
|
62
|
-
| headers | Optional | {} | The object with custom headers for internal http client.
|
|
63
|
-
| debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging.
|
|
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
|
|
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`.
|
|
66
|
-
| launchUuidPrint | Optional | false | Whether to print the current launch UUID.
|
|
67
|
-
| launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR', 'FILE', 'ENVIRONMENT'. Works only if `launchUuidPrint` set to `true`. File format: `rp-launch-uuid-${launch_uuid}.tmp`. Env variable: `RP_LAUNCH_UUID`.
|
|
68
|
-
| token | Deprecated | Not set | Use `apiKey` instead.
|
|
56
|
+
| Option | Necessity | Default | Description |
|
|
57
|
+
|-----------------------|------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
58
|
+
| apiKey | Required | | User's reportportal token from which you want to send requests. It can be found on the profile page of this user. |
|
|
59
|
+
| 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'. |
|
|
60
|
+
| launch | Required | | Name of the launch at creation. |
|
|
61
|
+
| project | Required | | The name of the project in which the launches will be created. |
|
|
62
|
+
| headers | Optional | {} | The object with custom headers for internal http client. |
|
|
63
|
+
| debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
|
|
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`. |
|
|
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`. |
|
|
66
|
+
| launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
|
|
67
|
+
| launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR', 'FILE', 'ENVIRONMENT'. Works only if `launchUuidPrint` set to `true`. File format: `rp-launch-uuid-${launch_uuid}.tmp`. Env variable: `RP_LAUNCH_UUID`. |
|
|
68
|
+
| token | Deprecated | Not set | Use `apiKey` instead. |
|
|
69
69
|
|
|
70
70
|
## Asynchronous reporting
|
|
71
71
|
|
|
72
|
-
The client supports an asynchronous reporting.
|
|
73
|
-
If you want the client to
|
|
72
|
+
The client supports an asynchronous reporting (via the ReportPortal asynchronous API).
|
|
73
|
+
If you want the client to report through the asynchronous API, change `v1` to `v2` in the `endpoint` address.
|
|
74
74
|
|
|
75
75
|
## API
|
|
76
76
|
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.1
|
|
1
|
+
5.2.1-SNAPSHOT
|
package/lib/helpers.js
CHANGED
|
@@ -22,8 +22,9 @@ module.exports = {
|
|
|
22
22
|
return new Date().valueOf();
|
|
23
23
|
},
|
|
24
24
|
|
|
25
|
+
// TODO: deprecate and remove
|
|
25
26
|
getServerResult(url, request, options, method) {
|
|
26
|
-
return RestClient.request(method, url, request, options);
|
|
27
|
+
return new RestClient(options).request(method, url, request, options);
|
|
27
28
|
},
|
|
28
29
|
|
|
29
30
|
readLaunchesFromFile() {
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const addLogger = (axiosInstance) => {
|
|
2
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
3
|
+
const startDate = new Date();
|
|
4
|
+
// eslint-disable-next-line no-param-reassign
|
|
5
|
+
config.startTime = startDate.valueOf();
|
|
6
|
+
|
|
7
|
+
console.log(`Request method=${config.method} url=${config.url} [${startDate.toISOString()}]`);
|
|
8
|
+
|
|
9
|
+
return config;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
axiosInstance.interceptors.response.use(
|
|
13
|
+
(response) => {
|
|
14
|
+
const date = new Date();
|
|
15
|
+
const { status, config } = response;
|
|
16
|
+
|
|
17
|
+
console.log(
|
|
18
|
+
`Response status=${status} url=${config.url} time=${
|
|
19
|
+
date.valueOf() - config.startTime
|
|
20
|
+
}ms [${date.toISOString()}]`,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return response;
|
|
24
|
+
},
|
|
25
|
+
(error) => {
|
|
26
|
+
const date = new Date();
|
|
27
|
+
const { response, config } = error;
|
|
28
|
+
const status = response ? response.status : null;
|
|
29
|
+
|
|
30
|
+
console.log(
|
|
31
|
+
`Response ${status ? `status=${status}` : `message='${error.message}'`} url=${
|
|
32
|
+
config.url
|
|
33
|
+
} time=${date.valueOf() - config.startTime}ms [${date.toISOString()}]`,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return Promise.reject(error);
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = { addLogger };
|
|
@@ -41,7 +41,8 @@ class RPClient {
|
|
|
41
41
|
this.baseURL = [this.config.endpoint, this.config.project].join('/');
|
|
42
42
|
this.headers = {
|
|
43
43
|
'User-Agent': 'NodeJS',
|
|
44
|
-
|
|
44
|
+
'Content-Type': 'application/json; charset=UTF-8',
|
|
45
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
45
46
|
...(this.config.headers || {}),
|
|
46
47
|
};
|
|
47
48
|
this.helpers = helpers;
|
|
@@ -130,7 +131,7 @@ class RPClient {
|
|
|
130
131
|
|
|
131
132
|
checkConnect() {
|
|
132
133
|
const url = [this.config.endpoint.replace('/v2', '/v1'), 'user'].join('/');
|
|
133
|
-
return
|
|
134
|
+
return this.restClient.request('GET', url, {});
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
async triggerStatisticsEvent() {
|
|
@@ -201,7 +202,7 @@ class RPClient {
|
|
|
201
202
|
this.map[tempId] = this.getNewItemObj((resolve, reject) => {
|
|
202
203
|
const url = 'launch';
|
|
203
204
|
this.logDebug(`Start launch with tempId ${tempId}`, launchDataRQ);
|
|
204
|
-
this.restClient.create(url, launchData
|
|
205
|
+
this.restClient.create(url, launchData).then(
|
|
205
206
|
(response) => {
|
|
206
207
|
this.map[tempId].realId = response.id;
|
|
207
208
|
this.launchUuid = response.id;
|
|
@@ -260,7 +261,7 @@ class RPClient {
|
|
|
260
261
|
() => {
|
|
261
262
|
this.logDebug(`Finish launch with tempId ${launchTempId}`, finishExecutionData);
|
|
262
263
|
const url = ['launch', launchObj.realId, 'finish'].join('/');
|
|
263
|
-
this.restClient.update(url, finishExecutionData
|
|
264
|
+
this.restClient.update(url, finishExecutionData).then(
|
|
264
265
|
(response) => {
|
|
265
266
|
this.logDebug(`Success finish launch with tempId ${launchTempId}`, response);
|
|
266
267
|
console.log(`\nReportPortal Launch Link: ${response.link}`);
|
|
@@ -332,10 +333,13 @@ class RPClient {
|
|
|
332
333
|
'filter.in.uuid': launchUUIds,
|
|
333
334
|
'page.size': launchUUIds.length,
|
|
334
335
|
});
|
|
335
|
-
const launchSearchUrl =
|
|
336
|
+
const launchSearchUrl =
|
|
337
|
+
this.config.mode === 'DEBUG'
|
|
338
|
+
? `launch/mode?${params.toString()}`
|
|
339
|
+
: `launch?${params.toString()}`;
|
|
336
340
|
this.logDebug(`Find launches with UUIDs to merge: ${launchUUIds}`);
|
|
337
341
|
return this.restClient
|
|
338
|
-
.retrieveSyncAPI(launchSearchUrl
|
|
342
|
+
.retrieveSyncAPI(launchSearchUrl)
|
|
339
343
|
.then(
|
|
340
344
|
(response) => {
|
|
341
345
|
const launchIds = response.content.map((launch) => launch.id);
|
|
@@ -351,10 +355,13 @@ class RPClient {
|
|
|
351
355
|
const request = this.getMergeLaunchesRequest(launchIds, mergeOptions);
|
|
352
356
|
this.logDebug(`Merge launches with ids: ${launchIds}`, request);
|
|
353
357
|
const mergeURL = 'launch/merge';
|
|
354
|
-
return this.restClient.create(mergeURL, request
|
|
358
|
+
return this.restClient.create(mergeURL, request);
|
|
355
359
|
})
|
|
356
|
-
.then(() => {
|
|
360
|
+
.then((response) => {
|
|
357
361
|
this.logDebug(`Launches with UUIDs: ${launchUUIds} were successfully merged!`);
|
|
362
|
+
if (this.config.launchUuidPrint) {
|
|
363
|
+
this.config.launchUuidPrintOutput(response.uuid);
|
|
364
|
+
}
|
|
358
365
|
})
|
|
359
366
|
.catch((error) => {
|
|
360
367
|
this.logDebug(`Error merging launches with UUIDs: ${launchUUIds}`, error);
|
|
@@ -417,7 +424,7 @@ class RPClient {
|
|
|
417
424
|
() => {
|
|
418
425
|
const url = ['launch', launchObj.realId, 'update'].join('/');
|
|
419
426
|
this.logDebug(`Update launch with tempId ${launchTempId}`, launchData);
|
|
420
|
-
this.restClient.update(url, launchData
|
|
427
|
+
this.restClient.update(url, launchData).then(
|
|
421
428
|
(response) => {
|
|
422
429
|
this.logDebug(`Launch with tempId ${launchTempId} were successfully updated`, response);
|
|
423
430
|
resolvePromise(response);
|
|
@@ -525,7 +532,7 @@ class RPClient {
|
|
|
525
532
|
}
|
|
526
533
|
testItemData.launchUuid = realLaunchId;
|
|
527
534
|
this.logDebug(`Start test item with tempId ${tempId}`, testItemData);
|
|
528
|
-
this.restClient.create(url, testItemData
|
|
535
|
+
this.restClient.create(url, testItemData).then(
|
|
529
536
|
(response) => {
|
|
530
537
|
this.logDebug(`Success start item with tempId ${tempId}`, response);
|
|
531
538
|
this.map[tempId].realId = response.id;
|
|
@@ -712,7 +719,6 @@ class RPClient {
|
|
|
712
719
|
return this.restClient.create(
|
|
713
720
|
url,
|
|
714
721
|
Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }),
|
|
715
|
-
{ headers: this.headers },
|
|
716
722
|
);
|
|
717
723
|
};
|
|
718
724
|
return this.saveLog(itemObj, requestPromise);
|
|
@@ -768,7 +774,6 @@ class RPClient {
|
|
|
768
774
|
return this.restClient
|
|
769
775
|
.create(url, this.buildMultiPartStream([saveLogRQ], fileObj, MULTIPART_BOUNDARY), {
|
|
770
776
|
headers: {
|
|
771
|
-
...this.headers,
|
|
772
777
|
'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}`,
|
|
773
778
|
},
|
|
774
779
|
})
|
|
@@ -831,9 +836,7 @@ class RPClient {
|
|
|
831
836
|
const url = ['item', itemObj.realId].join('/');
|
|
832
837
|
this.logDebug(`Finish test item with tempId ${itemTempId}`, itemObj);
|
|
833
838
|
this.restClient
|
|
834
|
-
.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid })
|
|
835
|
-
headers: this.headers,
|
|
836
|
-
})
|
|
839
|
+
.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid }))
|
|
837
840
|
.then(
|
|
838
841
|
(response) => {
|
|
839
842
|
this.logDebug(`Success finish item with tempId ${itemTempId}`, response);
|
package/lib/rest.js
CHANGED
|
@@ -2,6 +2,7 @@ const axios = require('axios');
|
|
|
2
2
|
const axiosRetry = require('axios-retry').default;
|
|
3
3
|
const http = require('http');
|
|
4
4
|
const https = require('https');
|
|
5
|
+
const logger = require('./logger');
|
|
5
6
|
|
|
6
7
|
const DEFAULT_MAX_CONNECTION_TIME_MS = 30000;
|
|
7
8
|
|
|
@@ -17,7 +18,15 @@ class RestClient {
|
|
|
17
18
|
this.headers = options.headers;
|
|
18
19
|
this.restClientConfig = options.restClientConfig;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
this.axiosInstance = axios.create({
|
|
22
|
+
timeout: DEFAULT_MAX_CONNECTION_TIME_MS,
|
|
23
|
+
headers: this.headers,
|
|
24
|
+
...this.getRestConfig(this.restClientConfig),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (this.restClientConfig?.debug) {
|
|
28
|
+
logger.addLogger(this.axiosInstance);
|
|
29
|
+
}
|
|
21
30
|
}
|
|
22
31
|
|
|
23
32
|
buildPath(path) {
|
|
@@ -28,14 +37,18 @@ class RestClient {
|
|
|
28
37
|
return [this.baseURL.replace('/v2', '/v1'), path].join('/');
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
request(method, url, data, options = {}) {
|
|
41
|
+
return this.axiosInstance
|
|
42
|
+
.request({
|
|
43
|
+
method,
|
|
44
|
+
url,
|
|
45
|
+
data,
|
|
46
|
+
...options,
|
|
47
|
+
headers: {
|
|
48
|
+
HOST: new URL(url).host,
|
|
49
|
+
...options.headers,
|
|
50
|
+
},
|
|
51
|
+
})
|
|
39
52
|
.then((response) => response.data)
|
|
40
53
|
.catch((error) => {
|
|
41
54
|
const errorMessage = error.message;
|
|
@@ -74,85 +87,45 @@ method: ${method}`,
|
|
|
74
87
|
return config;
|
|
75
88
|
}
|
|
76
89
|
|
|
77
|
-
create(path, data, options = {
|
|
78
|
-
return
|
|
90
|
+
create(path, data, options = {}) {
|
|
91
|
+
return this.request('POST', this.buildPath(path), data, {
|
|
79
92
|
...options,
|
|
80
|
-
...this.getRestConfig(),
|
|
81
93
|
});
|
|
82
94
|
}
|
|
83
95
|
|
|
84
|
-
retrieve(path, options = {
|
|
85
|
-
return
|
|
96
|
+
retrieve(path, options = {}) {
|
|
97
|
+
return this.request(
|
|
86
98
|
'GET',
|
|
87
99
|
this.buildPath(path),
|
|
88
100
|
{},
|
|
89
|
-
{
|
|
101
|
+
{
|
|
102
|
+
...options,
|
|
103
|
+
},
|
|
90
104
|
);
|
|
91
105
|
}
|
|
92
106
|
|
|
93
|
-
update(path, data, options = {
|
|
94
|
-
return
|
|
107
|
+
update(path, data, options = {}) {
|
|
108
|
+
return this.request('PUT', this.buildPath(path), data, {
|
|
95
109
|
...options,
|
|
96
|
-
...this.getRestConfig(),
|
|
97
110
|
});
|
|
98
111
|
}
|
|
99
112
|
|
|
100
|
-
delete(path, data, options = {
|
|
101
|
-
return
|
|
113
|
+
delete(path, data, options = {}) {
|
|
114
|
+
return this.request('DELETE', this.buildPath(path), data, {
|
|
102
115
|
...options,
|
|
103
|
-
...this.getRestConfig(),
|
|
104
116
|
});
|
|
105
117
|
}
|
|
106
118
|
|
|
107
|
-
retrieveSyncAPI(path, options = {
|
|
108
|
-
return
|
|
119
|
+
retrieveSyncAPI(path, options = {}) {
|
|
120
|
+
return this.request(
|
|
109
121
|
'GET',
|
|
110
122
|
this.buildPathToSyncAPI(path),
|
|
111
123
|
{},
|
|
112
|
-
{
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
}
|
|
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);
|
|
124
|
+
{
|
|
125
|
+
...options,
|
|
153
126
|
},
|
|
154
127
|
);
|
|
155
128
|
}
|
|
156
|
-
}
|
|
129
|
+
}
|
|
157
130
|
|
|
158
131
|
module.exports = RestClient;
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reportportal/client-javascript",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "ReportPortal client for Node.js",
|
|
5
5
|
"author": "ReportPortal.io",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "npm run clean && tsc",
|
|
8
8
|
"clean": "rimraf ./build",
|
|
9
|
-
"lint": "eslint ./statistics/**/* ./lib/**/* ./
|
|
9
|
+
"lint": "eslint ./statistics/**/* ./lib/**/* ./__tests__/**/*",
|
|
10
10
|
"format": "npm run lint -- --fix",
|
|
11
|
-
"test": "
|
|
12
|
-
"test:coverage": "
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"test:coverage": "jest --coverage"
|
|
13
13
|
},
|
|
14
14
|
"directories": {
|
|
15
15
|
"lib": "./lib"
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
],
|
|
22
22
|
"main": "./lib/report-portal-client",
|
|
23
23
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
24
|
+
"node": ">=14.x"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "^1.
|
|
27
|
+
"axios": "^1.7.7",
|
|
28
28
|
"axios-retry": "^4.1.0",
|
|
29
29
|
"glob": "^8.1.0",
|
|
30
30
|
"ini": "^2.0.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/
|
|
36
|
+
"@types/jest": "^29.5.12",
|
|
37
37
|
"@types/node": "^18.19.8",
|
|
38
38
|
"@typescript-eslint/eslint-plugin": "5.62.0",
|
|
39
39
|
"@typescript-eslint/parser": "^5.62.0",
|
|
@@ -44,13 +44,12 @@
|
|
|
44
44
|
"eslint-plugin-import": "^2.29.1",
|
|
45
45
|
"eslint-plugin-node": "^11.1.0",
|
|
46
46
|
"eslint-plugin-prettier": "^4.2.1",
|
|
47
|
-
"
|
|
48
|
-
"jasmine-ts": "^0.4.0",
|
|
47
|
+
"jest": "^29.7.0",
|
|
49
48
|
"lodash": "^4.17.21",
|
|
50
49
|
"nock": "^13.5.0",
|
|
51
|
-
"nyc": "^15.1.0",
|
|
52
50
|
"prettier": "^2.8.8",
|
|
53
51
|
"rimraf": "^3.0.2",
|
|
52
|
+
"ts-jest": "^29.1.5",
|
|
54
53
|
"ts-node": "^10.9.2",
|
|
55
54
|
"typescript": "^4.9.5"
|
|
56
55
|
},
|