@reportportal/client-javascript 5.1.4 → 5.3.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 +43 -33
- package/VERSION +1 -1
- package/lib/helpers.js +103 -83
- package/lib/logger.js +41 -0
- package/lib/report-portal-client.js +14 -15
- package/lib/rest.js +38 -65
- package/package.json +11 -11
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
|
|
|
@@ -129,13 +129,13 @@ console.log(launchObj.tempId);
|
|
|
129
129
|
The method takes one argument:
|
|
130
130
|
* launch data object:
|
|
131
131
|
|
|
132
|
-
| Option | Necessity | Default | Description
|
|
133
|
-
|
|
134
|
-
| startTime | Optional | rpClient.helpers.now() | Start time of the launch (
|
|
135
|
-
| name | Optional | parameter 'launch' specified when creating the client instance | Name of the launch.
|
|
136
|
-
| mode | Optional | 'DEFAULT' | 'DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page.
|
|
137
|
-
| description | Optional | '' | Description of the launch (supports markdown syntax).
|
|
138
|
-
| attributes | Optional | [] | Array of launch attributes (tags).
|
|
132
|
+
| Option | Necessity | Default | Description |
|
|
133
|
+
|-------------|-----------|----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
|
|
134
|
+
| startTime | Optional | rpClient.helpers.now() | Start time of the launch (Unix Epoch time, see [time format](#time-format)). |
|
|
135
|
+
| name | Optional | parameter 'launch' specified when creating the client instance | Name of the launch. |
|
|
136
|
+
| mode | Optional | 'DEFAULT' | 'DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page. |
|
|
137
|
+
| description | Optional | '' | Description of the launch (supports markdown syntax). |
|
|
138
|
+
| attributes | Optional | [] | Array of launch attributes (tags). |
|
|
139
139
|
| 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. |
|
|
140
140
|
|
|
141
141
|
To get the real launch `ID` (also known as launch `UUID` from database) wait for the returned promise to finish.
|
|
@@ -180,9 +180,9 @@ The method takes two arguments:
|
|
|
180
180
|
* launch `tempId` (returned by the method `startLaunch`)
|
|
181
181
|
* data object:
|
|
182
182
|
|
|
183
|
-
|Option | Necessity | Default | Description
|
|
184
|
-
|---------
|
|
185
|
-
|endTime | Optional | rpClient.helpers.now() | End time of the launch.
|
|
183
|
+
|Option | Necessity | Default | Description |
|
|
184
|
+
|--------- |-----------|---------|----------------------------------------------------------------------------------------------------|
|
|
185
|
+
|endTime | Optional | rpClient.helpers.now() | End time of the launch (Unix Epoch time, see [time format](#time-format)). |
|
|
186
186
|
|status | Optional | '' | Status of launch, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. |
|
|
187
187
|
|
|
188
188
|
### getPromiseFinishAllItems
|
|
@@ -265,7 +265,7 @@ The method takes three arguments:
|
|
|
265
265
|
|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' |
|
|
266
266
|
|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. |
|
|
267
267
|
|description | Optional | '' | Description of the test item (supports markdown syntax). |
|
|
268
|
-
|startTime | Optional | rpClient.helpers.now() | Start time of the test item (
|
|
268
|
+
|startTime | Optional | rpClient.helpers.now() | Start time of the test item (Unix Epoch time, see [time format](#time-format)). |
|
|
269
269
|
|attributes | Optional | [] | Array of the test item attributes. |
|
|
270
270
|
|
|
271
271
|
* launch `tempId` (returned by the method `startLaunch`)
|
|
@@ -289,8 +289,8 @@ The method takes two arguments:
|
|
|
289
289
|
| Option | Necessity | Default | Description |
|
|
290
290
|
|---------|-----------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
|
|
291
291
|
| issue | Optional | true | Test item issue object. `issueType` is required, allowable values: 'pb***', 'ab***', 'si***', 'ti***', 'nd001'. Where `***` is locator id |
|
|
292
|
-
| status | Optional | 'PASSED' | Test item status, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'.
|
|
293
|
-
| endTime | Optional | rpClient.helpers.now() | End time of the launch (
|
|
292
|
+
| status | Optional | 'PASSED' | Test item status, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. |
|
|
293
|
+
| endTime | Optional | rpClient.helpers.now() | End time of the launch (Unix Epoch time, see [time format](#time-format)). |
|
|
294
294
|
|
|
295
295
|
Example issue object:
|
|
296
296
|
```
|
|
@@ -325,11 +325,11 @@ The method takes three arguments:
|
|
|
325
325
|
* test item `tempId` (returned by method `startTestItem`)
|
|
326
326
|
* data object:
|
|
327
327
|
|
|
328
|
-
| Option | Necessity | Default | Description
|
|
329
|
-
|
|
330
|
-
| message | Optional | '' | The log message.
|
|
328
|
+
| Option | Necessity | Default | Description |
|
|
329
|
+
|---------|-----------|------------------------|---------------------------------------------------------------------|
|
|
330
|
+
| message | Optional | '' | The log message. |
|
|
331
331
|
| level | Optional | '' | The log level, one of 'trace', 'debug', 'info', 'warn', 'error', ''. |
|
|
332
|
-
| time | Optional | rpClient.helpers.now() | The time of the log.
|
|
332
|
+
| time | Optional | rpClient.helpers.now() | The time of the log (Unix Epoch time, see [time format](#time-format)). |
|
|
333
333
|
|
|
334
334
|
* file object (optional):
|
|
335
335
|
|
|
@@ -370,13 +370,23 @@ The method takes one argument:
|
|
|
370
370
|
|-------------------------|-----------|-----------------------------------------|------------------------------------------------------------------------------------------------------------|
|
|
371
371
|
| description | Optional | config.description or 'Merged launch' | Description of the launch (supports markdown syntax). |
|
|
372
372
|
| attributes | Optional | config.attributes or [] | Array of launch attributes (tags). |
|
|
373
|
-
| endTime | Optional | rpClient.helpers.now() | End time of the launch (
|
|
373
|
+
| endTime | Optional | rpClient.helpers.now() | End time of the launch (Unix Epoch time, see [time format](#time-format)). |
|
|
374
374
|
| extendSuitesDescription | Optional | true | Whether to extend suites description or not. |
|
|
375
375
|
| launches | Optional | ids of the launches saved to filesystem | The array of the real launch ids, not UUIDs |
|
|
376
376
|
| mergeType | Optional | 'BASIC' | The type of the merge operation. Possible values are 'BASIC' or 'DEEP'. |
|
|
377
377
|
| mode | Optional | config.mode or 'DEFAULT' | 'DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page. |
|
|
378
378
|
| name | Optional | config.launch or 'Test launch name' | Name of the launch after merge. |
|
|
379
379
|
|
|
380
|
+
## Time format
|
|
381
|
+
|
|
382
|
+
The unix Epoch time ISO string.
|
|
383
|
+
|
|
384
|
+
The [ReportPortal since product version 24.2]() (Service API version 5.12.0) supports the time with microsecond precision in the ISO string format (`2024-09-23T11:10:46.793546Z`).
|
|
385
|
+
Thus, it is recommended to report time in this format to have more accurate logs and test items order on the ReportPortal UI.
|
|
386
|
+
**Note:** Reporting the time in ISO string format with millisecond precision (`2024-09-23T11:10:46.793Z`) or as a number of milliseconds (`1727089846793`) is also acceptable with microseconds automatically added as zeros for backward compatibility.
|
|
387
|
+
|
|
388
|
+
The client use time with microsecond precision in the ISO string format by default since [version 5.3.0]().
|
|
389
|
+
|
|
380
390
|
# Copyright Notice
|
|
381
391
|
|
|
382
392
|
Licensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.1
|
|
1
|
+
5.3.1-SNAPSHOT
|
package/lib/helpers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const glob = require('glob');
|
|
3
3
|
const os = require('os');
|
|
4
|
+
const microtime = require('microtime');
|
|
4
5
|
const RestClient = require('./rest');
|
|
5
6
|
const pjson = require('../package.json');
|
|
6
7
|
|
|
@@ -11,91 +12,110 @@ const PJSON_NAME = pjson.name;
|
|
|
11
12
|
|
|
12
13
|
const getUUIDFromFileName = (filename) => filename.match(/rplaunch-(.*)\.tmp/)[1];
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const nodeVersion = process.version;
|
|
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
|
-
];
|
|
72
|
-
|
|
73
|
-
return systemAttr;
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
generateTestCaseId(codeRef, params) {
|
|
77
|
-
if (!codeRef) {
|
|
78
|
-
return;
|
|
15
|
+
const formatName = (name) => {
|
|
16
|
+
const len = name.length;
|
|
17
|
+
// eslint-disable-next-line no-mixed-operators
|
|
18
|
+
return (len < MIN ? name + new Array(MIN - len + 1).join('.') : name).slice(-MAX);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const formatMicrosecondsToISOString = (timestampInMicroseconds) => {
|
|
22
|
+
const milliseconds = Math.floor(timestampInMicroseconds / 1000);
|
|
23
|
+
const microseconds = String(timestampInMicroseconds).slice(-3);
|
|
24
|
+
const isoDate = new Date(milliseconds).toISOString();
|
|
25
|
+
|
|
26
|
+
return isoDate.replace('Z', `${microseconds}Z`);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const now = () => {
|
|
30
|
+
return formatMicrosecondsToISOString(microtime.now());
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// TODO: deprecate and remove
|
|
34
|
+
const getServerResult = (url, request, options, method) => {
|
|
35
|
+
return new RestClient(options).request(method, url, request, options);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const readLaunchesFromFile = () => {
|
|
39
|
+
const files = glob.sync('rplaunch-*.tmp');
|
|
40
|
+
const ids = files.map(getUUIDFromFileName);
|
|
41
|
+
|
|
42
|
+
return ids;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const saveLaunchIdToFile = (launchId) => {
|
|
46
|
+
const filename = `rplaunch-${launchId}.tmp`;
|
|
47
|
+
fs.open(filename, 'w', (err) => {
|
|
48
|
+
if (err) {
|
|
49
|
+
throw err;
|
|
79
50
|
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const getSystemAttribute = () => {
|
|
55
|
+
const osType = os.type();
|
|
56
|
+
const osArchitecture = os.arch();
|
|
57
|
+
const RAMSize = os.totalmem();
|
|
58
|
+
const nodeVersion = process.version;
|
|
59
|
+
const systemAttr = [
|
|
60
|
+
{
|
|
61
|
+
key: 'client',
|
|
62
|
+
value: `${PJSON_NAME}|${PJSON_VERSION}`,
|
|
63
|
+
system: true,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: 'os',
|
|
67
|
+
value: `${osType}|${osArchitecture}`,
|
|
68
|
+
system: true,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: 'RAMSize',
|
|
72
|
+
value: RAMSize,
|
|
73
|
+
system: true,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
key: 'nodeJS',
|
|
77
|
+
value: nodeVersion,
|
|
78
|
+
system: true,
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
return systemAttr;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const generateTestCaseId = (codeRef, params) => {
|
|
86
|
+
if (!codeRef) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
80
89
|
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
if (!params) {
|
|
91
|
+
return codeRef;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const parameters = params.reduce(
|
|
95
|
+
(result, item) => (item.value ? result.concat(item.value) : result),
|
|
96
|
+
[],
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return `${codeRef}[${parameters}]`;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const saveLaunchUuidToFile = (launchUuid) => {
|
|
103
|
+
const filename = `rp-launch-uuid-${launchUuid}.tmp`;
|
|
104
|
+
fs.open(filename, 'w', (err) => {
|
|
105
|
+
if (err) {
|
|
106
|
+
throw err;
|
|
83
107
|
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
84
110
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
fs.open(filename, 'w', (err) => {
|
|
96
|
-
if (err) {
|
|
97
|
-
throw err;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
},
|
|
111
|
+
module.exports = {
|
|
112
|
+
formatName,
|
|
113
|
+
formatMicrosecondsToISOString,
|
|
114
|
+
now,
|
|
115
|
+
getServerResult,
|
|
116
|
+
readLaunchesFromFile,
|
|
117
|
+
saveLaunchIdToFile,
|
|
118
|
+
getSystemAttribute,
|
|
119
|
+
generateTestCaseId,
|
|
120
|
+
saveLaunchUuidToFile,
|
|
101
121
|
};
|
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,11 +333,13 @@ class RPClient {
|
|
|
332
333
|
'filter.in.uuid': launchUUIds,
|
|
333
334
|
'page.size': launchUUIds.length,
|
|
334
335
|
});
|
|
335
|
-
const launchSearchUrl =
|
|
336
|
-
|
|
336
|
+
const launchSearchUrl =
|
|
337
|
+
this.config.mode === 'DEBUG'
|
|
338
|
+
? `launch/mode?${params.toString()}`
|
|
339
|
+
: `launch?${params.toString()}`;
|
|
337
340
|
this.logDebug(`Find launches with UUIDs to merge: ${launchUUIds}`);
|
|
338
341
|
return this.restClient
|
|
339
|
-
.retrieveSyncAPI(launchSearchUrl
|
|
342
|
+
.retrieveSyncAPI(launchSearchUrl)
|
|
340
343
|
.then(
|
|
341
344
|
(response) => {
|
|
342
345
|
const launchIds = response.content.map((launch) => launch.id);
|
|
@@ -352,7 +355,7 @@ class RPClient {
|
|
|
352
355
|
const request = this.getMergeLaunchesRequest(launchIds, mergeOptions);
|
|
353
356
|
this.logDebug(`Merge launches with ids: ${launchIds}`, request);
|
|
354
357
|
const mergeURL = 'launch/merge';
|
|
355
|
-
return this.restClient.create(mergeURL, request
|
|
358
|
+
return this.restClient.create(mergeURL, request);
|
|
356
359
|
})
|
|
357
360
|
.then((response) => {
|
|
358
361
|
this.logDebug(`Launches with UUIDs: ${launchUUIds} were successfully merged!`);
|
|
@@ -421,7 +424,7 @@ class RPClient {
|
|
|
421
424
|
() => {
|
|
422
425
|
const url = ['launch', launchObj.realId, 'update'].join('/');
|
|
423
426
|
this.logDebug(`Update launch with tempId ${launchTempId}`, launchData);
|
|
424
|
-
this.restClient.update(url, launchData
|
|
427
|
+
this.restClient.update(url, launchData).then(
|
|
425
428
|
(response) => {
|
|
426
429
|
this.logDebug(`Launch with tempId ${launchTempId} were successfully updated`, response);
|
|
427
430
|
resolvePromise(response);
|
|
@@ -529,7 +532,7 @@ class RPClient {
|
|
|
529
532
|
}
|
|
530
533
|
testItemData.launchUuid = realLaunchId;
|
|
531
534
|
this.logDebug(`Start test item with tempId ${tempId}`, testItemData);
|
|
532
|
-
this.restClient.create(url, testItemData
|
|
535
|
+
this.restClient.create(url, testItemData).then(
|
|
533
536
|
(response) => {
|
|
534
537
|
this.logDebug(`Success start item with tempId ${tempId}`, response);
|
|
535
538
|
this.map[tempId].realId = response.id;
|
|
@@ -716,7 +719,6 @@ class RPClient {
|
|
|
716
719
|
return this.restClient.create(
|
|
717
720
|
url,
|
|
718
721
|
Object.assign(saveLogRQ, { launchUuid }, isItemUuid && { itemUuid }),
|
|
719
|
-
{ headers: this.headers },
|
|
720
722
|
);
|
|
721
723
|
};
|
|
722
724
|
return this.saveLog(itemObj, requestPromise);
|
|
@@ -772,7 +774,6 @@ class RPClient {
|
|
|
772
774
|
return this.restClient
|
|
773
775
|
.create(url, this.buildMultiPartStream([saveLogRQ], fileObj, MULTIPART_BOUNDARY), {
|
|
774
776
|
headers: {
|
|
775
|
-
...this.headers,
|
|
776
777
|
'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}`,
|
|
777
778
|
},
|
|
778
779
|
})
|
|
@@ -835,9 +836,7 @@ class RPClient {
|
|
|
835
836
|
const url = ['item', itemObj.realId].join('/');
|
|
836
837
|
this.logDebug(`Finish test item with tempId ${itemTempId}`, itemObj);
|
|
837
838
|
this.restClient
|
|
838
|
-
.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid })
|
|
839
|
-
headers: this.headers,
|
|
840
|
-
})
|
|
839
|
+
.update(url, Object.assign(finishTestItemData, { launchUuid: this.launchUuid }))
|
|
841
840
|
.then(
|
|
842
841
|
(response) => {
|
|
843
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.3.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,19 +21,20 @@
|
|
|
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",
|
|
31
31
|
"uniqid": "^5.4.0",
|
|
32
|
-
"uuid": "^9.0.1"
|
|
32
|
+
"uuid": "^9.0.1",
|
|
33
|
+
"microtime": "^3.1.1"
|
|
33
34
|
},
|
|
34
35
|
"license": "Apache-2.0",
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@types/
|
|
37
|
+
"@types/jest": "^29.5.12",
|
|
37
38
|
"@types/node": "^18.19.8",
|
|
38
39
|
"@typescript-eslint/eslint-plugin": "5.62.0",
|
|
39
40
|
"@typescript-eslint/parser": "^5.62.0",
|
|
@@ -44,13 +45,12 @@
|
|
|
44
45
|
"eslint-plugin-import": "^2.29.1",
|
|
45
46
|
"eslint-plugin-node": "^11.1.0",
|
|
46
47
|
"eslint-plugin-prettier": "^4.2.1",
|
|
47
|
-
"
|
|
48
|
-
"jasmine-ts": "^0.4.0",
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
49
|
"lodash": "^4.17.21",
|
|
50
50
|
"nock": "^13.5.0",
|
|
51
|
-
"nyc": "^15.1.0",
|
|
52
51
|
"prettier": "^2.8.8",
|
|
53
52
|
"rimraf": "^3.0.2",
|
|
53
|
+
"ts-jest": "^29.1.5",
|
|
54
54
|
"ts-node": "^10.9.2",
|
|
55
55
|
"typescript": "^4.9.5"
|
|
56
56
|
},
|