Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 5.0.13 #166

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Added
- `launchUuidPrint` and `launchUuidPrintOutput` configuration options to ease integration with CI tools, by @HardNorth

## [5.0.12] - 2023-06-19
### Changed
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ rpClient.checkConnect().then((response) => {

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. |
| 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`. |
| launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
| launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if `launchUuidPrint` set to `true`. |
| token | Deprecated | Not set | Use `apiKey` instead. |

## Asynchronous reporting

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.12
5.0.13-SNAPSHOT
20 changes: 20 additions & 0 deletions lib/commons/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
const { ReportPortalRequiredOptionError, ReportPortalValidationError } = require('./errors');
const { OUTPUT_TYPES } = require('../constants/outputs');

const getOption = (options, optionName, defaultValue) => {
if (!Object.prototype.hasOwnProperty.call(options, optionName) || !options[optionName]) {
return defaultValue;
}

return options[optionName];
};

const getRequiredOption = (options, optionName) => {
if (!Object.prototype.hasOwnProperty.call(options, optionName) || !options[optionName]) {
Expand All @@ -15,7 +24,7 @@
if (!calculatedApiKey) {
throw new ReportPortalRequiredOptionError('apiKey');
} else {
console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`);

Check warning on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (10)

Unexpected console statement

Check warning on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (12)

Unexpected console statement

Check warning on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement

Check warning on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

Check warning on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

Check warning on line 27 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement
}
}

Expand All @@ -32,6 +41,15 @@
const project = getRequiredOption(options, 'project');
const endpoint = getRequiredOption(options, 'endpoint');

const launchUuidPrintOutputType = getOption(options, 'launchUuidPrintOutput', 'STDOUT')
.toString()
.toUpperCase();
const launchUuidPrintOutput = getOption(
OUTPUT_TYPES,
launchUuidPrintOutputType,
OUTPUT_TYPES.STDOUT,
);

calculatedOptions = {
apiKey,
project,
Expand All @@ -45,10 +63,12 @@
attributes: options.attributes,
mode: options.mode,
description: options.description,
launchUuidPrint: options.launchUuidPrint,
launchUuidPrintOutput,
};
} catch (error) {
// don't throw the error up to not break the entire process
console.dir(error);

Check warning on line 71 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (10)

Unexpected console statement

Check warning on line 71 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (12)

Unexpected console statement

Check warning on line 71 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement

Check warning on line 71 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

Check warning on line 71 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

Check warning on line 71 in lib/commons/config.js

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement
}

return calculatedOptions;
Expand Down
8 changes: 8 additions & 0 deletions lib/constants/outputs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const OUTPUT_TYPES = {
// eslint-disable-next-line no-console
STDOUT: console.log,
// eslint-disable-next-line no-console
STDERR: console.error,
};

module.exports = { OUTPUT_TYPES };
3 changes: 3 additions & 0 deletions lib/report-portal-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class RPClient {
(response) => {
this.map[tempId].realId = response.id;
this.launchUuid = response.id;
if (this.config.launchUuidPrint) {
this.config.launchUuidPrintOutput(`Report Portal Launch UUID: ${this.launchUuid}`);
}

if (this.isLaunchMergeRequired) {
helpers.saveLaunchIdToFile(response.id);
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions spec/report-portal-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const process = require('process');
const RPClient = require('../lib/report-portal-client');
const RestClient = require('../lib/rest');
const helpers = require('../lib/helpers');
const { OUTPUT_TYPES } = require('../lib/constants/outputs');

describe('ReportPortal javascript client', () => {
describe('constructor', () => {
Expand Down Expand Up @@ -316,6 +317,93 @@ describe('ReportPortal javascript client', () => {
expect(client.restClient.create).not.toHaveBeenCalled();
expect(client.launchUuid).toEqual(id);
});

it('should log Launch UUID if enabled', () => {
spyOn(OUTPUT_TYPES, 'STDOUT');
const client = new RPClient({
apiKey: 'startLaunchTest',
endpoint: 'https://rp.us/api/v1',
project: 'tst',
launchUuidPrint: true,
});
const myPromise = Promise.resolve({ id: 'testidlaunch' });
const time = 12345734;
spyOn(client.restClient, 'create').and.returnValue(myPromise);
return client
.startLaunch({
startTime: time,
})
.promise.then(function () {
expect(OUTPUT_TYPES.STDOUT).toHaveBeenCalledWith(
'Report Portal Launch UUID: testidlaunch',
);
});
});

it('should log Launch UUID into STDERR if enabled', () => {
spyOn(OUTPUT_TYPES, 'STDERR');
const client = new RPClient({
apiKey: 'startLaunchTest',
endpoint: 'https://rp.us/api/v1',
project: 'tst',
launchUuidPrint: true,
launchUuidPrintOutput: 'stderr',
});
const myPromise = Promise.resolve({ id: 'testidlaunch' });
const time = 12345734;
spyOn(client.restClient, 'create').and.returnValue(myPromise);
return client
.startLaunch({
startTime: time,
})
.promise.then(function () {
expect(OUTPUT_TYPES.STDERR).toHaveBeenCalledWith(
'Report Portal Launch UUID: testidlaunch',
);
});
});

it('should log Launch UUID into STDOUT if invalid output is set', () => {
spyOn(OUTPUT_TYPES, 'STDOUT');
const client = new RPClient({
apiKey: 'startLaunchTest',
endpoint: 'https://rp.us/api/v1',
project: 'tst',
launchUuidPrint: true,
launchUuidPrintOutput: 'asdfgh',
});
const myPromise = Promise.resolve({ id: 'testidlaunch' });
const time = 12345734;
spyOn(client.restClient, 'create').and.returnValue(myPromise);
return client
.startLaunch({
startTime: time,
})
.promise.then(function () {
expect(OUTPUT_TYPES.STDOUT).toHaveBeenCalledWith(
'Report Portal Launch UUID: testidlaunch',
);
});
});

it('should not log Launch UUID if not enabled', () => {
spyOn(OUTPUT_TYPES, 'STDOUT');
const client = new RPClient({
apiKey: 'startLaunchTest',
endpoint: 'https://rp.us/api/v1',
project: 'tst',
});
const myPromise = Promise.resolve({ id: 'testidlaunch' });
const time = 12345734;
spyOn(client.restClient, 'create').and.returnValue(myPromise);
return client
.startLaunch({
startTime: time,
})
.promise.then(function () {
expect(OUTPUT_TYPES.STDOUT).not.toHaveBeenCalled();
});
});
});

describe('finishLaunch', () => {
Expand Down
16 changes: 6 additions & 10 deletions statistics/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const axios = require('axios');
const { MEASUREMENT_ID, API_KEY, PJSON_NAME, PJSON_VERSION, INTERPRETER } = require('./constants');
const { getClientId } = require('./client-id');

const hasOption = (options, optionName) => {
return Object.prototype.hasOwnProperty.call(options, optionName);
};

class Statistics {
constructor(eventName, agentParams) {
this.eventName = eventName;
Expand All @@ -14,18 +18,10 @@ class Statistics {
client_name: PJSON_NAME,
client_version: PJSON_VERSION,
};
if (
agentParams &&
Object.prototype.hasOwnProperty.call(agentParams, 'name') &&
agentParams.name
) {
if (agentParams && hasOption(agentParams, 'name') && agentParams.name) {
params.agent_name = agentParams.name;
}
if (
agentParams &&
Object.prototype.hasOwnProperty.call(agentParams, 'version') &&
agentParams.version
) {
if (agentParams && hasOption(agentParams, 'version') && agentParams.version) {
params.agent_version = agentParams.version;
}
return params;
Expand Down