@reportportal/client-javascript 5.0.12 → 5.0.14
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 +13 -11
- package/VERSION +1 -1
- package/lib/commons/config.js +20 -0
- package/lib/constants/outputs.js +8 -0
- package/lib/polyfills.js +19 -0
- package/lib/report-portal-client.js +30 -20
- package/package.json +1 -1
- package/statistics/statistics.js +23 -23
package/README.md
CHANGED
|
@@ -52,17 +52,19 @@ rpClient.checkConnect().then((response) => {
|
|
|
52
52
|
|
|
53
53
|
When creating a client instance, you need to specify the following options:
|
|
54
54
|
|
|
55
|
-
| Option | Necessity | Default
|
|
56
|
-
|
|
57
|
-
| apiKey | Required |
|
|
58
|
-
| endpoint | Required |
|
|
59
|
-
| launch | Required |
|
|
60
|
-
| project | Required |
|
|
61
|
-
| headers | Optional | {}
|
|
62
|
-
| debug | Optional | false
|
|
63
|
-
| isLaunchMergeRequired | Optional | false
|
|
64
|
-
| restClientConfig | Optional | Not set
|
|
65
|
-
|
|
|
55
|
+
| Option | Necessity | Default | Description |
|
|
56
|
+
|-----------------------|------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
57
|
+
| apiKey | Required | | User's reportportal token from which you want to send requests. It can be found on the profile page of this user. |
|
|
58
|
+
| endpoint | Required | | URL of your server. For example, if you visit the page at 'https://server:8080/ui', then endpoint will be equal to 'https://server:8080/api/v1'. |
|
|
59
|
+
| launch | Required | | Name of launch at creation. |
|
|
60
|
+
| project | Required | | The name of the project in which the launches will be created. |
|
|
61
|
+
| headers | Optional | {} | The object with custom headers for internal http client. |
|
|
62
|
+
| debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
|
|
63
|
+
| isLaunchMergeRequired | Optional | false | Allows client to merge launches into one at the end of the run via saving their UUIDs to the file system. At the end of the run launches can be merged using `mergeLaunches` method. |
|
|
64
|
+
| restClientConfig | Optional | Not set | The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. `timeout`. |
|
|
65
|
+
| launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
|
|
66
|
+
| launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if `launchUuidPrint` set to `true`. |
|
|
67
|
+
| token | Deprecated | Not set | Use `apiKey` instead. |
|
|
66
68
|
|
|
67
69
|
## Asynchronous reporting
|
|
68
70
|
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.0.
|
|
1
|
+
5.0.15-SNAPSHOT
|
package/lib/commons/config.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
const { ReportPortalRequiredOptionError, ReportPortalValidationError } = require('./errors');
|
|
2
|
+
const { OUTPUT_TYPES } = require('../constants/outputs');
|
|
3
|
+
|
|
4
|
+
const getOption = (options, optionName, defaultValue) => {
|
|
5
|
+
if (!Object.prototype.hasOwnProperty.call(options, optionName) || !options[optionName]) {
|
|
6
|
+
return defaultValue;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return options[optionName];
|
|
10
|
+
};
|
|
2
11
|
|
|
3
12
|
const getRequiredOption = (options, optionName) => {
|
|
4
13
|
if (!Object.prototype.hasOwnProperty.call(options, optionName) || !options[optionName]) {
|
|
@@ -32,6 +41,15 @@ const getClientConfig = (options) => {
|
|
|
32
41
|
const project = getRequiredOption(options, 'project');
|
|
33
42
|
const endpoint = getRequiredOption(options, 'endpoint');
|
|
34
43
|
|
|
44
|
+
const launchUuidPrintOutputType = getOption(options, 'launchUuidPrintOutput', 'STDOUT')
|
|
45
|
+
.toString()
|
|
46
|
+
.toUpperCase();
|
|
47
|
+
const launchUuidPrintOutput = getOption(
|
|
48
|
+
OUTPUT_TYPES,
|
|
49
|
+
launchUuidPrintOutputType,
|
|
50
|
+
OUTPUT_TYPES.STDOUT,
|
|
51
|
+
);
|
|
52
|
+
|
|
35
53
|
calculatedOptions = {
|
|
36
54
|
apiKey,
|
|
37
55
|
project,
|
|
@@ -45,6 +63,8 @@ const getClientConfig = (options) => {
|
|
|
45
63
|
attributes: options.attributes,
|
|
46
64
|
mode: options.mode,
|
|
47
65
|
description: options.description,
|
|
66
|
+
launchUuidPrint: options.launchUuidPrint,
|
|
67
|
+
launchUuidPrintOutput,
|
|
48
68
|
};
|
|
49
69
|
} catch (error) {
|
|
50
70
|
// don't throw the error up to not break the entire process
|
package/lib/polyfills.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//! Was added to support NodeJS 10.
|
|
2
|
+
if (!Promise.allSettled) {
|
|
3
|
+
Promise.allSettled = function (promises) {
|
|
4
|
+
return Promise.all(
|
|
5
|
+
promises.map((p) =>
|
|
6
|
+
Promise.resolve(p).then(
|
|
7
|
+
(value) => ({
|
|
8
|
+
status: 'fulfilled',
|
|
9
|
+
value,
|
|
10
|
+
}),
|
|
11
|
+
(error) => ({
|
|
12
|
+
status: 'rejected',
|
|
13
|
+
reason: error,
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
),
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -7,6 +7,7 @@ const { getClientConfig } = require('./commons/config');
|
|
|
7
7
|
const Statistics = require('../statistics/statistics');
|
|
8
8
|
const { EVENT_NAME } = require('../statistics/constants');
|
|
9
9
|
const { RP_STATUSES } = require('./constants/statuses');
|
|
10
|
+
require('./polyfills');
|
|
10
11
|
|
|
11
12
|
const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString();
|
|
12
13
|
|
|
@@ -115,11 +116,11 @@ class RPClient {
|
|
|
115
116
|
return RestClient.request('GET', url, {}, { headers: this.headers });
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
triggerStatisticsEvent() {
|
|
119
|
+
async triggerStatisticsEvent() {
|
|
119
120
|
if (process.env.REPORTPORTAL_CLIENT_JS_NO_ANALYTICS) {
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
|
-
this.statistics.trackEvent();
|
|
123
|
+
await this.statistics.trackEvent();
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
/**
|
|
@@ -187,6 +188,9 @@ class RPClient {
|
|
|
187
188
|
(response) => {
|
|
188
189
|
this.map[tempId].realId = response.id;
|
|
189
190
|
this.launchUuid = response.id;
|
|
191
|
+
if (this.config.launchUuidPrint) {
|
|
192
|
+
this.config.launchUuidPrintOutput(`Report Portal Launch UUID: ${this.launchUuid}`);
|
|
193
|
+
}
|
|
190
194
|
|
|
191
195
|
if (this.isLaunchMergeRequired) {
|
|
192
196
|
helpers.saveLaunchIdToFile(response.id);
|
|
@@ -203,7 +207,7 @@ class RPClient {
|
|
|
203
207
|
);
|
|
204
208
|
});
|
|
205
209
|
}
|
|
206
|
-
this.triggerStatisticsEvent();
|
|
210
|
+
this.triggerStatisticsEvent().catch(console.error);
|
|
207
211
|
return {
|
|
208
212
|
tempId,
|
|
209
213
|
promise: this.map[tempId].promiseStart,
|
|
@@ -578,32 +582,38 @@ class RPClient {
|
|
|
578
582
|
|
|
579
583
|
itemObj.finishSend = true;
|
|
580
584
|
this.logDebug(`Finish all children for test item with tempId ${itemTempId}`);
|
|
581
|
-
Promise.
|
|
585
|
+
Promise.allSettled(
|
|
582
586
|
itemObj.children.map((itemId) => this.map[itemId] && this.map[itemId].promiseFinish),
|
|
583
|
-
)
|
|
584
|
-
() => {
|
|
587
|
+
)
|
|
588
|
+
.then((results) => {
|
|
589
|
+
if (this.debug) {
|
|
590
|
+
results.forEach((result, index) => {
|
|
591
|
+
if (result.status === 'fulfilled') {
|
|
592
|
+
this.logDebug(
|
|
593
|
+
`Successfully finish child with tempId ${itemObj.children[index]}
|
|
594
|
+
of test item with tempId ${itemTempId}`,
|
|
595
|
+
);
|
|
596
|
+
} else {
|
|
597
|
+
this.logDebug(
|
|
598
|
+
`Failed to finish child with tempId ${itemObj.children[index]}
|
|
599
|
+
of test item with tempId ${itemTempId}`,
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
|
|
585
605
|
this.cleanMap(itemObj.children);
|
|
586
|
-
|
|
587
|
-
`All children for test item with tempId ${itemTempId} successfully finished.`,
|
|
588
|
-
);
|
|
606
|
+
|
|
589
607
|
this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
|
|
590
608
|
this.finishTestItemPromiseStart(
|
|
591
609
|
itemObj,
|
|
592
610
|
itemTempId,
|
|
593
611
|
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
|
|
594
612
|
);
|
|
595
|
-
}
|
|
596
|
-
() => {
|
|
597
|
-
this.cleanMap(itemObj.children);
|
|
613
|
+
})
|
|
614
|
+
.catch(() => {
|
|
598
615
|
this.logDebug(`Error finish children of test item with tempId ${itemTempId}`);
|
|
599
|
-
|
|
600
|
-
this.finishTestItemPromiseStart(
|
|
601
|
-
itemObj,
|
|
602
|
-
itemTempId,
|
|
603
|
-
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
|
|
604
|
-
);
|
|
605
|
-
},
|
|
606
|
-
);
|
|
616
|
+
});
|
|
607
617
|
|
|
608
618
|
return {
|
|
609
619
|
tempId: itemTempId,
|
package/package.json
CHANGED
package/statistics/statistics.js
CHANGED
|
@@ -2,6 +2,10 @@ const axios = require('axios');
|
|
|
2
2
|
const { MEASUREMENT_ID, API_KEY, PJSON_NAME, PJSON_VERSION, INTERPRETER } = require('./constants');
|
|
3
3
|
const { getClientId } = require('./client-id');
|
|
4
4
|
|
|
5
|
+
const hasOption = (options, optionName) => {
|
|
6
|
+
return Object.prototype.hasOwnProperty.call(options, optionName);
|
|
7
|
+
};
|
|
8
|
+
|
|
5
9
|
class Statistics {
|
|
6
10
|
constructor(eventName, agentParams) {
|
|
7
11
|
this.eventName = eventName;
|
|
@@ -14,38 +18,34 @@ class Statistics {
|
|
|
14
18
|
client_name: PJSON_NAME,
|
|
15
19
|
client_version: PJSON_VERSION,
|
|
16
20
|
};
|
|
17
|
-
if (
|
|
18
|
-
agentParams &&
|
|
19
|
-
Object.prototype.hasOwnProperty.call(agentParams, 'name') &&
|
|
20
|
-
agentParams.name
|
|
21
|
-
) {
|
|
21
|
+
if (agentParams && hasOption(agentParams, 'name') && agentParams.name) {
|
|
22
22
|
params.agent_name = agentParams.name;
|
|
23
23
|
}
|
|
24
|
-
if (
|
|
25
|
-
agentParams &&
|
|
26
|
-
Object.prototype.hasOwnProperty.call(agentParams, 'version') &&
|
|
27
|
-
agentParams.version
|
|
28
|
-
) {
|
|
24
|
+
if (agentParams && hasOption(agentParams, 'version') && agentParams.version) {
|
|
29
25
|
params.agent_version = agentParams.version;
|
|
30
26
|
}
|
|
31
27
|
return params;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
async trackEvent() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
try {
|
|
32
|
+
const requestBody = {
|
|
33
|
+
client_id: await getClientId(),
|
|
34
|
+
events: [
|
|
35
|
+
{
|
|
36
|
+
name: this.eventName,
|
|
37
|
+
params: this.eventParams,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
await axios.post(
|
|
43
|
+
`https://www.google-analytics.com/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_KEY}`,
|
|
44
|
+
requestBody,
|
|
45
|
+
);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(error.message);
|
|
48
|
+
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|