@reportportal/client-javascript 5.2.0 → 5.3.1

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
@@ -1,6 +1,6 @@
1
1
  # ReportPortal js client
2
2
 
3
- This Client is to communicate with the Report Portal on Node.js.
3
+ This Client is to communicate with the ReportPortal on Node.js.
4
4
 
5
5
  Library is used only for implementors of custom listeners for ReportPortal.
6
6
 
@@ -40,9 +40,8 @@ const rpClient = new RPClient({
40
40
  project: 'PROJECT_NAME'
41
41
  });
42
42
 
43
- rpClient.checkConnect().then((response) => {
43
+ rpClient.checkConnect().then(() => {
44
44
  console.log('You have successfully connected to the server.');
45
- console.log(`You are using an account: ${response.fullName}`);
46
45
  }, (error) => {
47
46
  console.log('Error connection to server');
48
47
  console.dir(error);
@@ -129,13 +128,13 @@ console.log(launchObj.tempId);
129
128
  The method takes one argument:
130
129
  * launch data object:
131
130
 
132
- | Option | Necessity | Default | Description |
133
- |-------------|-----------|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
134
- | startTime | Optional | rpClient.helpers.now() | Start time of the launch (unix time). |
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). |
131
+ | Option | Necessity | Default | Description |
132
+ |-------------|-----------|----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
133
+ | startTime | Optional | rpClient.helpers.now() | Start time of the launch (Unix Epoch time, see [time format](#time-format)). |
134
+ | name | Optional | parameter 'launch' specified when creating the client instance | Name of the launch. |
135
+ | mode | Optional | 'DEFAULT' | 'DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page. |
136
+ | description | Optional | '' | Description of the launch (supports markdown syntax). |
137
+ | attributes | Optional | [] | Array of launch attributes (tags). |
139
138
  | 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
139
 
141
140
  To get the real launch `ID` (also known as launch `UUID` from database) wait for the returned promise to finish.
@@ -180,9 +179,9 @@ The method takes two arguments:
180
179
  * launch `tempId` (returned by the method `startLaunch`)
181
180
  * data object:
182
181
 
183
- |Option | Necessity | Default | Description |
184
- |--------- |-----------|---------|---------------------------------------------------------------------------------------------------|
185
- |endTime | Optional | rpClient.helpers.now() | End time of the launch. |
182
+ |Option | Necessity | Default | Description |
183
+ |--------- |-----------|---------|----------------------------------------------------------------------------------------------------|
184
+ |endTime | Optional | rpClient.helpers.now() | End time of the launch (Unix Epoch time, see [time format](#time-format)). |
186
185
  |status | Optional | '' | Status of launch, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. |
187
186
 
188
187
  ### getPromiseFinishAllItems
@@ -265,7 +264,7 @@ The method takes three arguments:
265
264
  |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
265
  |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
266
  |description | Optional | '' | Description of the test item (supports markdown syntax). |
268
- |startTime | Optional | rpClient.helpers.now() | Start time of the test item (unix time). |
267
+ |startTime | Optional | rpClient.helpers.now() | Start time of the test item (Unix Epoch time, see [time format](#time-format)). |
269
268
  |attributes | Optional | [] | Array of the test item attributes. |
270
269
 
271
270
  * launch `tempId` (returned by the method `startLaunch`)
@@ -289,8 +288,8 @@ The method takes two arguments:
289
288
  | Option | Necessity | Default | Description |
290
289
  |---------|-----------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
291
290
  | 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 (unix time). |
291
+ | status | Optional | 'PASSED' | Test item status, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. |
292
+ | endTime | Optional | rpClient.helpers.now() | End time of the launch (Unix Epoch time, see [time format](#time-format)). |
294
293
 
295
294
  Example issue object:
296
295
  ```
@@ -325,11 +324,11 @@ The method takes three arguments:
325
324
  * test item `tempId` (returned by method `startTestItem`)
326
325
  * data object:
327
326
 
328
- | Option | Necessity | Default | Description |
329
- |---------|-----------|------------------------|----------------------------------------------------------------------|
330
- | message | Optional | '' | The log message. |
327
+ | Option | Necessity | Default | Description |
328
+ |---------|-----------|------------------------|---------------------------------------------------------------------|
329
+ | message | Optional | '' | The log message. |
331
330
  | level | Optional | '' | The log level, one of 'trace', 'debug', 'info', 'warn', 'error', ''. |
332
- | time | Optional | rpClient.helpers.now() | The time of the log. |
331
+ | time | Optional | rpClient.helpers.now() | The time of the log (Unix Epoch time, see [time format](#time-format)). |
333
332
 
334
333
  * file object (optional):
335
334
 
@@ -370,13 +369,24 @@ The method takes one argument:
370
369
  |-------------------------|-----------|-----------------------------------------|------------------------------------------------------------------------------------------------------------|
371
370
  | description | Optional | config.description or 'Merged launch' | Description of the launch (supports markdown syntax). |
372
371
  | attributes | Optional | config.attributes or [] | Array of launch attributes (tags). |
373
- | endTime | Optional | rpClient.helpers.now() | End time of the launch (unix time) |
372
+ | endTime | Optional | rpClient.helpers.now() | End time of the launch (Unix Epoch time, see [time format](#time-format)). |
374
373
  | extendSuitesDescription | Optional | true | Whether to extend suites description or not. |
375
374
  | launches | Optional | ids of the launches saved to filesystem | The array of the real launch ids, not UUIDs |
376
375
  | mergeType | Optional | 'BASIC' | The type of the merge operation. Possible values are 'BASIC' or 'DEEP'. |
377
376
  | mode | Optional | config.mode or 'DEFAULT' | 'DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page. |
378
377
  | name | Optional | config.launch or 'Test launch name' | Name of the launch after merge. |
379
378
 
379
+ ## Time format
380
+
381
+ The unix Epoch time ISO string.
382
+
383
+ 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`).
384
+ Thus, it is recommended to report time in this format to have more accurate logs and test items order on the ReportPortal UI.
385
+
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 on ReportPortal's API service 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.2.1-SNAPSHOT
1
+ 5.3.2-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,92 +12,110 @@ const PJSON_NAME = pjson.name;
11
12
 
12
13
  const getUUIDFromFileName = (filename) => filename.match(/rplaunch-(.*)\.tmp/)[1];
13
14
 
14
- module.exports = {
15
- 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
- now() {
22
- return new Date().valueOf();
23
- },
24
-
25
- // TODO: deprecate and remove
26
- getServerResult(url, request, options, method) {
27
- return new RestClient(options).request(method, url, request, options);
28
- },
29
-
30
- readLaunchesFromFile() {
31
- const files = glob.sync('rplaunch-*.tmp');
32
- const ids = files.map(getUUIDFromFileName);
33
-
34
- return ids;
35
- },
36
-
37
- saveLaunchIdToFile(launchId) {
38
- const filename = `rplaunch-${launchId}.tmp`;
39
- fs.open(filename, 'w', (err) => {
40
- if (err) {
41
- throw err;
42
- }
43
- });
44
- },
45
-
46
- getSystemAttribute() {
47
- const osType = os.type();
48
- const osArchitecture = os.arch();
49
- const RAMSize = os.totalmem();
50
- const nodeVersion = process.version;
51
- const systemAttr = [
52
- {
53
- key: 'client',
54
- value: `${PJSON_NAME}|${PJSON_VERSION}`,
55
- system: true,
56
- },
57
- {
58
- key: 'os',
59
- value: `${osType}|${osArchitecture}`,
60
- system: true,
61
- },
62
- {
63
- key: 'RAMSize',
64
- value: RAMSize,
65
- system: true,
66
- },
67
- {
68
- key: 'nodeJS',
69
- value: nodeVersion,
70
- system: true,
71
- },
72
- ];
73
-
74
- return systemAttr;
75
- },
76
-
77
- generateTestCaseId(codeRef, params) {
78
- if (!codeRef) {
79
- 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;
80
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
+ }
81
89
 
82
- if (!params) {
83
- return codeRef;
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;
84
107
  }
108
+ });
109
+ };
85
110
 
86
- const parameters = params.reduce(
87
- (result, item) => (item.value ? result.concat(item.value) : result),
88
- [],
89
- );
90
-
91
- return `${codeRef}[${parameters}]`;
92
- },
93
-
94
- saveLaunchUuidToFile(launchUuid) {
95
- const filename = `rp-launch-uuid-${launchUuid}.tmp`;
96
- fs.open(filename, 'w', (err) => {
97
- if (err) {
98
- throw err;
99
- }
100
- });
101
- },
111
+ module.exports = {
112
+ formatName,
113
+ formatMicrosecondsToISOString,
114
+ now,
115
+ getServerResult,
116
+ readLaunchesFromFile,
117
+ saveLaunchIdToFile,
118
+ getSystemAttribute,
119
+ generateTestCaseId,
120
+ saveLaunchUuidToFile,
102
121
  };
@@ -130,7 +130,9 @@ class RPClient {
130
130
  }
131
131
 
132
132
  checkConnect() {
133
- const url = [this.config.endpoint.replace('/v2', '/v1'), 'user'].join('/');
133
+ const url = [this.config.endpoint.replace('/v2', '/v1'), this.config.project, 'launch']
134
+ .join('/')
135
+ .concat('?page.page=1&page.size=1');
134
136
  return this.restClient.request('GET', url, {});
135
137
  }
136
138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/client-javascript",
3
- "version": "5.2.0",
3
+ "version": "5.3.1",
4
4
  "description": "ReportPortal client for Node.js",
5
5
  "author": "ReportPortal.io",
6
6
  "scripts": {
@@ -29,7 +29,8 @@
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": {