@reportportal/client-javascript
Advanced tools
Comparing version 5.0.11 to 5.0.12
@@ -6,2 +6,3 @@ /* eslint-disable quotes,no-console,class-methods-use-this */ | ||
const RestClient = require('./rest'); | ||
const { getClientConfig } = require('./commons/config'); | ||
const Statistics = require('../statistics/statistics'); | ||
@@ -16,6 +17,6 @@ const { EVENT_NAME } = require('../statistics/constants'); | ||
* Create a client for RP. | ||
* @param {Object} params - config object. | ||
* params should look like this | ||
* @param {Object} options - config object. | ||
* options should look like this | ||
* { | ||
* token: "00000000-0000-0000-0000-000000000000", | ||
* apiKey: "reportportalApiKey", | ||
* endpoint: "http://localhost:8080/api/v1", | ||
@@ -33,15 +34,17 @@ * launch: "YOUR LAUNCH NAME", | ||
*/ | ||
constructor(params, agentParams) { | ||
this.debug = params.debug; | ||
this.isLaunchMergeRequired = | ||
params.isLaunchMergeRequired === undefined ? false : params.isLaunchMergeRequired; | ||
constructor(options, agentParams) { | ||
this.config = getClientConfig(options); | ||
this.debug = this.config.debug; | ||
this.isLaunchMergeRequired = this.config.isLaunchMergeRequired; | ||
this.apiKey = this.config.apiKey; | ||
// deprecated | ||
this.token = this.apiKey; | ||
this.map = {}; | ||
this.baseURL = [params.endpoint, params.project].join('/'); | ||
this.baseURL = [this.config.endpoint, this.config.project].join('/'); | ||
this.headers = { | ||
'User-Agent': 'NodeJS', | ||
Authorization: `bearer ${params.token}`, | ||
...(params.headers || {}), | ||
Authorization: `bearer ${this.apiKey}`, | ||
...(this.config.headers || {}), | ||
}; | ||
this.token = params.token; | ||
this.config = params; | ||
this.helpers = helpers; | ||
@@ -51,3 +54,3 @@ this.restClient = new RestClient({ | ||
headers: this.headers, | ||
restClientConfig: params.restClientConfig, | ||
restClientConfig: this.config.restClientConfig, | ||
}); | ||
@@ -54,0 +57,0 @@ this.statistics = new Statistics(EVENT_NAME, agentParams); |
{ | ||
"name": "@reportportal/client-javascript", | ||
"version": "5.0.11", | ||
"version": "5.0.12", | ||
"description": "ReportPortal client for Node.js", | ||
@@ -5,0 +5,0 @@ "author": "ReportPortal.io", |
231
README.md
# ReportPortal js client | ||
This Client is to communicate with the Report Portal on Node.js. | ||
@@ -7,2 +8,3 @@ | ||
## Already implemented listeners: | ||
* [Jest integration](https://github.com/reportportal/agent-js-jest) | ||
@@ -23,2 +25,3 @@ * [Cypress integration](https://github.com/reportportal/agent-js-cypress) | ||
## Installation | ||
The latest version is available on npm: | ||
@@ -29,3 +32,3 @@ ```cmd | ||
## Example | ||
## Usage example | ||
@@ -36,6 +39,6 @@ ```javascript | ||
const rpClient = new RPClient({ | ||
token: "00000000-0000-0000-0000-000000000000", | ||
endpoint: "http://your-instance.com:8080/api/v1", | ||
launch: "LAUNCH_NAME", | ||
project: "PROJECT_NAME" | ||
apiKey: 'reportportalApiKey', | ||
endpoint: 'http://your-instance.com:8080/api/v1', | ||
launch: 'LAUNCH_NAME', | ||
project: 'PROJECT_NAME' | ||
}); | ||
@@ -52,21 +55,25 @@ | ||
## Settings | ||
When creating a client instance, you need to specify the following parameters: | ||
## Configuration | ||
| Parameter | Description | | ||
|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| token | User's token Report Portal from which you want to send requests. It can be found on the profile page of this user. | | ||
| endpoint | 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'. | | ||
| launch | Name of launch at creation. | | ||
| project | The name of the project in which the launches will be created. | | ||
| headers | (optional) The object with custom headers for internal http client. | | ||
| debug | (optional) *Default: false.* This flag allows seeing the logs of the client. Useful for debugging. | | ||
| isLaunchMergeRequired | (optional) *Default: 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. | | ||
| restClientConfig | (optional) 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`. | | ||
When creating a client instance, you need to specify the following options: | ||
| Option | Necessity | Default | Description | | ||
|-----------------------|------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| apiKey | Required | | User's reportportal token from which you want to send requests. It can be found on the profile page of this user. | | ||
| 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'. | | ||
| launch | Required | | Name of launch at creation. | | ||
| project | Required | | The name of the project in which the launches will be created. | | ||
| headers | Optional | {} | The object with custom headers for internal http client. | | ||
| debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. | | ||
| 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. | | ||
| 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`. | | ||
| token | Deprecated | Not set | Use `apiKey` instead. | | ||
## Asynchronous reporting | ||
The client supports an asynchronous reporting. | ||
If you want the client to work asynchronously change v1 to v2 in addresses in endpoint. | ||
If you want the client to work asynchronously change `v1` to `v2` in addresses in endpoint. | ||
## Api | ||
## API | ||
Each method (except checkConnect) returns an object in a specific format: | ||
@@ -82,8 +89,11 @@ ```javascript | ||
### Timeout (30000ms) on axios requests | ||
There is a timeout on axios requests. If for instance the server your making a request to is taking too long to load, then axios timeout will work and you will see the error "Error: timeout of 30000ms exceeded". | ||
There is a timeout on axios requests. If for instance the server your making a request to is taking too long to load, then axios timeout will work and you will see the error 'Error: timeout of 30000ms exceeded'. | ||
You can simply change this timeout by adding a `timeout` property to `restClientConfig` with your desired numeric value (in _ms_) or *0* to disable it. | ||
### checkConnect | ||
checkConnect - asynchronous method for verifying the correctness of the client connection | ||
`checkConnect` - asynchronous method for verifying the correctness of the client connection | ||
```javascript | ||
@@ -100,15 +110,17 @@ rpClient.checkConnect().then((response) => { | ||
### startLaunch | ||
startLaunch - starts a new launch, return temp id that you want to use for all of the items within this launch. | ||
`startLaunch` - starts a new launch, return temp id that you want to use for the all items within this launch. | ||
```javascript | ||
const launchObj = rpClient.startLaunch({ | ||
name: "Client test", | ||
name: 'Client test', | ||
startTime: rpClient.helpers.now(), | ||
description: "description of the launch", | ||
description: 'description of the launch', | ||
attributes: [ | ||
{ | ||
"key": "yourKey", | ||
"value": "yourValue" | ||
'key': 'yourKey', | ||
'value': 'yourValue' | ||
}, | ||
{ | ||
"value": "yourValue" | ||
'value': 'yourValue' | ||
} | ||
@@ -124,12 +136,13 @@ ], | ||
Parameter | Description | ||
--------- | ----------- | ||
startTime | (optional) start time launch(unix time). Default: rpClient.helpers.now() | ||
name | (optional) launch name. Default: parameter 'launch' specified when creating the client instance | ||
mode | (optional) "DEFAULT" or "DEBUG". Default: "DEFAULT" | ||
description | (optional) description of the launch (supports markdown syntax) | ||
attributes | (optional) array of launch tags | ||
id | id of the existing launch in which tests data would be sent, without this param new launch instance would be created | ||
| Option | Necessity | Default | Description | | ||
|-------------|-----------|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------| | ||
| startTime | Optional | rpClient.helpers.now() | (optional) start time launch(unix time). | | ||
| name | Optional | parameter 'launch' specified when creating the client instance | Name of the launch. | | ||
| mode | Optional | 'DEFAULT' | 'DEFAULT' - results will be submitted to Launches page, 'DEBUG' - results will be submitted to Debug page. | | ||
| description | Optional | '' | Description of the launch (supports markdown syntax). | | ||
| attributes | Optional | [] | Array of launch attributes (tags). | | ||
| 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. | | ||
To know the real launch id wait for the method to finish. The real id is used by the client in asynchronous reporting. | ||
To get the real launch `ID` (also known as launch `UUID` from database) wait for the returned promise to finish. | ||
```javascript | ||
@@ -160,4 +173,6 @@ const launchObj = rpClient.startLaunch(); | ||
### finishLaunch | ||
finishLaunch - finish of the launch. After calling this method, you can not add items to the launch. | ||
`finishLaunch` - finish of the launch. After calling this method, you can not add items to the launch. | ||
The request to finish the launch will be sent only after all items within it have finished. | ||
```javascript | ||
@@ -169,37 +184,43 @@ // launchObj - object returned by method 'startLaunch' | ||
``` | ||
The method takes two arguments: | ||
* id launch (returned by method 'startLaunch') | ||
* launch `tempId` (returned by the method `startLaunch`) | ||
* data object: | ||
Parameter | Description | ||
--------- | ----------- | ||
endTime | (optional) end time of launch. Default: rpClient.helpers.now() | ||
status | (optional) status of launch, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "INTERRUPTED", "CANCELLED". | ||
|Option | Necessity | Default | Description | | ||
|--------- |-----------|---------|---------------------------------------------------------------------------------------------------| | ||
|endTime | Optional | rpClient.helpers.now() | End time of the launch. | | ||
|status | Optional | '' | Status of launch, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. | | ||
### getPromiseFinishAllItems | ||
getPromiseFinishAllItems - returns promise that contains status about all data has been sent to the Report Protal. | ||
This method needed when test frameworks don't wait for async methods and stop processed. | ||
`getPromiseFinishAllItems` - returns promise that contains status about all data has been sent to the reportportal. | ||
This method needed when test frameworks don't wait for async methods until finished. | ||
```javascript | ||
// jasmine example. tempLaunchId - id of the client's process | ||
agent.getPromiseFinishAllItems(agent.tempLaunchId).then(()=> done()); | ||
// jasmine example. tempLaunchId - tempId of the launch started by the current client process | ||
agent.getPromiseFinishAllItems(agent.tempLaunchId).then(() => done()); | ||
``` | ||
Parameter | Description | ||
--------- | ----------- | ||
tempLaunchId | id of the client's process | ||
| Option | Necessity | Default | Description | | ||
|--------------|-----------|---------|----------------------------| | ||
| tempLaunchId | Required | | `tempId` of the launch started by the current client process | | ||
### updateLaunch | ||
updateLaunch - updates launch data. Will send a request to the server only after finishing the launch. | ||
`updateLaunch` - updates the launch data. Will send a request to the server only after finishing the launch. | ||
```javascript | ||
// launchObj - object returned by method 'startLaunch' | ||
rpClient.updateLaunch( | ||
launchObj.tempId, { | ||
launchObj.tempId, | ||
{ | ||
description: 'new launch description', | ||
attributes: [ | ||
{ | ||
"key": "yourKey", | ||
"value": "yourValue" | ||
key: 'yourKey', | ||
value: 'yourValue' | ||
}, | ||
{ | ||
"value": "yourValue" | ||
value: 'yourValue' | ||
} | ||
@@ -212,7 +233,9 @@ ], | ||
The method takes two arguments: | ||
* id launch (returned by method 'startLaunch') | ||
* data object - may contain the following fields: description, tags, mode. These fields can be looked up in the method "startLaunch". | ||
* launch `tempId` (returned by the method 'startLaunch') | ||
* data object - may contain the following fields: `description`, `attributes`, `mode`. These fields can be looked up in the method `startLaunch`. | ||
### startTestItem | ||
startTestItem - starts a new test item. | ||
`startTestItem` - starts a new test item. | ||
```javascript | ||
@@ -224,3 +247,3 @@ // launchObj - object returned by method 'startLaunch' | ||
startTime: rpClient.helpers.now(), | ||
type: "SUITE" | ||
type: 'SUITE' | ||
}, launchObj.tempId); | ||
@@ -234,10 +257,10 @@ const stepObj = rpClient.startTestItem({ | ||
{ | ||
"key": "yourKey", | ||
"value": "yourValue" | ||
key: 'yourKey', | ||
value: 'yourValue' | ||
}, | ||
{ | ||
"value": "yourValue" | ||
value: 'yourValue' | ||
} | ||
], | ||
type: "STEP" | ||
type: 'STEP' | ||
}, launchObj.tempId, suiteObj.tempId); | ||
@@ -249,33 +272,34 @@ | ||
Parameter | Description | ||
--------- | ----------- | ||
name | item name | ||
type | 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' | ||
hasStats | (optional) Changes behavior for 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. Default: true | ||
description | (optional) description of the launch (supports markdown syntax) | ||
startTime | (optional) start time item(unix time). Default: rpClient.helpers.now() | ||
attributes | (optional) array of item attributes | ||
|Option | Necessity | Default | Description | | ||
|--------- |-----------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
|name | Required | | Test item name | | ||
|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' | | ||
|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. | | ||
|description | Optional | '' | Description of the test item (supports markdown syntax). | | ||
|startTime | Optional | rpClient.helpers.now() | Start time of the test item (unix time). | | ||
|attributes | Optional | [] | Array of the test item attributes. | | ||
* id launch (returned by method 'startLaunch') | ||
* id parent item (optional) (returned by method 'startTestItem') | ||
* launch `tempId` (returned by the method `startLaunch`) | ||
* parent test item `tempId` (*optional*) (returned by method `startTestItem`) | ||
### finishTestItem | ||
### finishTestItem | ||
finishTestItem - finish of the item. After calling this method, you can not add items to the item. | ||
The request to finish the item will be sent only after all items within it have finished. | ||
`finishTestItem` - finish of the test item. After calling this method, you can not add items to the test item. | ||
The request to finish the test item will be sent only after all test items within it have finished. | ||
```javascript | ||
// itemObj - object returned by method 'startTestItem' | ||
rpClient.finishTestItem(itemObj.tempId, { | ||
status: "failed" | ||
status: 'failed' | ||
}) | ||
``` | ||
The method takes two arguments: | ||
* id item (returned by method 'startTestItem') | ||
* test item `tempId` (returned by the method `startTestItem`) | ||
* data object: | ||
Parameter | Description | ||
--------- | ----------- | ||
endTime | (optional) end time of launch. Default: rpClient.helpers.now() | ||
status | (optional) item status, one of "", "PASSED", "FAILED", "STOPPED", "SKIPPED", "INTERRUPTED", "CANCELLED". Default: "PASSED". | ||
issue | (optional) object issue. IssueType is required, allowable values: "pb***", "ab***", "si***", "ti***", "nd001". Where *** is locator id | ||
| Option | Necessity | Default | Description | | ||
|---------|-----------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------| | ||
| issue | Optional | true | Test item issue object. `issueType` is required, allowable values: 'pb***', 'ab***', 'si***', 'ti***', 'nd001'. Where `***` is locator id | | ||
| status | Optional | 'PASSED' | Test item status, one of '', 'PASSED', 'FAILED', 'STOPPED', 'SKIPPED', 'INTERRUPTED', 'CANCELLED'. | | ||
| endTime | Optional | rpClient.helpers.now() | End time of the launch (unix time). | | ||
@@ -285,11 +309,11 @@ Example issue object: | ||
{ | ||
issueType: "string", | ||
comment: "string", | ||
issueType: 'string', | ||
comment: 'string', | ||
externalSystemIssues: [ | ||
{ | ||
submitDate: 0, | ||
submitter: "string", | ||
systemId: "string", | ||
ticketId: "string", | ||
url: "string" | ||
submitter: 'string', | ||
systemId: 'string', | ||
ticketId: 'string', | ||
url: 'string' | ||
} | ||
@@ -301,8 +325,10 @@ ] | ||
### sendLog | ||
sendLog - adds a log to the item | ||
`sendLog` - adds a log to the test item. | ||
```javascript | ||
// stepObj - object returned by method 'startTestItem' | ||
rpClient.sendLog(stepObj.tempId, { | ||
level: "INFO", | ||
message: makeid(), | ||
level: 'INFO', | ||
message: 'User clicks login button', | ||
time: rpClient.helpers.now() | ||
@@ -312,21 +338,22 @@ }) | ||
The method takes three arguments: | ||
* id item (returned by method 'startTestItem') | ||
* test item `tempId` (returned by method `startTestItem`) | ||
* data object: | ||
Parameter | Description | ||
--------- | ----------- | ||
time | (optional) time of log. Default: rpClient.helpers.now() | ||
message | (optional) log message. Default: ''. | ||
status | (optional) log status, one of 'trace', 'debug', 'info', 'warn', 'error', ''. Default "". | ||
| Option | Necessity | Default | Description | | ||
|---------|-----------|------------------------|----------------------------------------------------------------------| | ||
| message | Optional | '' | The log message. | | ||
| level | Optional | '' | The log level, one of 'trace', 'debug', 'info', 'warn', 'error', ''. | | ||
| time | Optional | rpClient.helpers.now() | The time of the log. | | ||
* file object (optional): | ||
Parameter | Description | ||
--------- | ----------- | ||
name | file name | ||
type | file mimeType, example "image/png" (support types: 'image/*', application/ ['xml', 'javascript', 'json', 'css', 'php'] , another format will be opened in a new browser tab ), | ||
content | file | ||
| Option | Necessity | Default | Description | | ||
|---------|-----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| name | Required | | The name of the file. | | ||
| type | Required | | The file mimeType, example 'image/png' (support types: 'image/*', application/['xml', 'javascript', 'json', 'css', 'php'], other formats will be opened in reportportal in a new browser tab only). | | ||
| content | Required | | base64 encoded file content. | | ||
# Copyright Notice | ||
Licensed under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0.html) | ||
license (see the LICENSE.txt file). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73989
15
1276
343