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

Output launch UUID to file and ENV variable #197

Merged
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
- Output launch UUID to file and ENV variable

## [5.1.2] - 2024-02-20
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ When creating a client instance, you need to specify the following options:
| 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`. |
| 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`. |
| 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`. |
| 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`. |
| token | Deprecated | Not set | Use `apiKey` instead. |

## Asynchronous reporting
Expand Down
9 changes: 7 additions & 2 deletions lib/constants/outputs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const helpers = require('../helpers');

const OUTPUT_TYPES = {
// eslint-disable-next-line no-console
STDOUT: console.log,
STDOUT: (launchUuid) => console.log(`Report Portal Launch UUID: ${launchUuid}`),
// eslint-disable-next-line no-console
STDERR: console.error,
STDERR: (launchUuid) => console.error(`Report Portal Launch UUID: ${launchUuid}`),
// eslint-disable-next-line no-return-assign
ENVIRONMENT: (launchUuid) => (process.env.RP_LAUNCH_UUID = launchUuid),
FILE: helpers.saveLaunchUuidToFile,
};

module.exports = { OUTPUT_TYPES };
9 changes: 9 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@ module.exports = {

return `${codeRef}[${parameters}]`;
},

saveLaunchUuidToFile(launchUuid) {
const filename = `rp-launch-uuid-${launchUuid}.tmp`;
fs.open(filename, 'w', (err) => {
if (err) {
throw err;
}
});
},
};
2 changes: 1 addition & 1 deletion lib/report-portal-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class RPClient {
this.map[tempId].realId = response.id;
this.launchUuid = response.id;
if (this.config.launchUuidPrint) {
this.config.launchUuidPrintOutput(`Report Portal Launch UUID: ${this.launchUuid}`);
this.config.launchUuidPrintOutput(this.launchUuid);
}

if (this.isLaunchMergeRequired) {
Expand Down
14 changes: 14 additions & 0 deletions spec/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,18 @@ describe('Helpers', () => {
expect(testCaseId).toEqual('codeRef[value,valueTwo,valueThree]');
});
});

describe('saveLaunchUuidToFile', () => {
it('should call fs.open method with right parameters', () => {
spyOn(fs, 'open');

helpers.saveLaunchUuidToFile('fileOne');

expect(fs.open).toHaveBeenCalledWith(
'rp-launch-uuid-fileOne.tmp',
'w',
jasmine.any(Function),
);
});
});
});
54 changes: 45 additions & 9 deletions spec/report-portal-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,7 @@ describe('ReportPortal javascript client', () => {
startTime: time,
})
.promise.then(function () {
expect(OUTPUT_TYPES.STDOUT).toHaveBeenCalledWith(
'Report Portal Launch UUID: testidlaunch',
);
expect(OUTPUT_TYPES.STDOUT).toHaveBeenCalledWith('testidlaunch');
});
});

Expand All @@ -357,9 +355,7 @@ describe('ReportPortal javascript client', () => {
startTime: time,
})
.promise.then(function () {
expect(OUTPUT_TYPES.STDERR).toHaveBeenCalledWith(
'Report Portal Launch UUID: testidlaunch',
);
expect(OUTPUT_TYPES.STDERR).toHaveBeenCalledWith('testidlaunch');
});
});

Expand All @@ -380,9 +376,49 @@ describe('ReportPortal javascript client', () => {
startTime: time,
})
.promise.then(function () {
expect(OUTPUT_TYPES.STDOUT).toHaveBeenCalledWith(
'Report Portal Launch UUID: testidlaunch',
);
expect(OUTPUT_TYPES.STDOUT).toHaveBeenCalledWith('testidlaunch');
});
});

it('should log Launch UUID into ENVIRONMENT if enabled', () => {
spyOn(OUTPUT_TYPES, 'ENVIRONMENT');
const client = new RPClient({
apiKey: 'startLaunchTest',
endpoint: 'https://rp.us/api/v1',
project: 'tst',
launchUuidPrint: true,
launchUuidPrintOutput: 'environment',
});
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.ENVIRONMENT).toHaveBeenCalledWith('testidlaunch');
});
});

it('should log Launch UUID into FILE if enabled', () => {
spyOn(OUTPUT_TYPES, 'FILE');
const client = new RPClient({
apiKey: 'startLaunchTest',
endpoint: 'https://rp.us/api/v1',
project: 'tst',
launchUuidPrint: true,
launchUuidPrintOutput: 'file',
});
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.FILE).toHaveBeenCalledWith('testidlaunch');
});
});

Expand Down
Loading