Skip to content

Commit

Permalink
Merge pull request #42 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.0.2
  • Loading branch information
AmsterGet authored Sep 18, 2020
2 parents a4e0bd2 + 27d8ef9 commit 1e69f86
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Fixed
- Calculating test item status based on first assertion
- Launch options not applied from config file
- Typos in documentation

## [5.0.1] - 2020-06-12
### Changed
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Create rp.json file with reportportal configuration:
"description": "Your launch description",
"rerun": true,
"rerunOf": "launchUuid of already existed launch",
"mode": "DEFAULT",
"debug": false,
"parallelRun": true
}
```
Expand All @@ -43,6 +45,8 @@ Create rp.json file with reportportal configuration:
| project | The name of the project in which the launches will be created. |
| rerun | *Default: false.* Enable [rerun](https://github.com/reportportal/documentation/blob/master/src/md/src/DevGuides/rerun.md)|
| rerunOf | UUID of launch you want to rerun. If not specified, report portal will update the latest launch with the same name|
| mode | Launch mode. Allowable values *DEFAULT* (by default) or *DEBUG*.|
| debug | This flag allows seeing the logs of the client-javascript. Useful for debugging.|
| parallelRun | *Default: false.* Indicates if tests running in parallel (uses for post-factum-reporter)|

## Reporting
Expand Down Expand Up @@ -279,7 +283,7 @@ Example:
```javascript
describe('Suite name', function() {
after((browser, done) => {
ReportingAPI.finishSuite(suiteName);
ReportingAPI.finishSuite('Suite name');
ReportingAPI.startAfterSuite();
// afterSuite related actions
Expand All @@ -302,11 +306,11 @@ Example:
```javascript
describe('Suite name', function() {
beforeEach((browser) => {
ReportingAPI.startBeforeTestCase(suiteName);
ReportingAPI.startBeforeTestCase('Suite name');
// beforeEach related actions
ReportingAPI.finishBeforeTestCase();
ReportingAPI.startTestCase(browser.currentTest, suiteName);
ReportingAPI.startTestCase(browser.currentTest, 'Suite name');
});
});
```
Expand All @@ -323,7 +327,7 @@ describe('Suite name', function() {
afterEach((browser) => {
ReportingAPI.finishTestCase(browser.currentTest);
ReportingAPI.startAfterTestCase(suiteName);
ReportingAPI.startAfterTestCase('Suite name');
// afterEach related actions
ReportingAPI.finishAfterTestCase();
});
Expand Down Expand Up @@ -424,7 +428,7 @@ describe('Suite name', function() {

###### launchLog
Send logs to report portal for the current launch. Should be called inside of the any test.<br/>
`ReportingAPI.log(level: LOG_LEVELS, message: string, file?: Attachment);`<br/>
`ReportingAPI.launchLog(level: LOG_LEVELS, message: string, file?: Attachment);`<br/>
**required**: `level`, `message`<br/>
where `level` can be one of the following: *TRACE*, *DEBUG*, *WARN*, *INFO*, *ERROR*, *FATAL*<br/>
Example:
Expand Down Expand Up @@ -514,13 +518,13 @@ Do not forget to specify custom commands path in your `nightwatch.conf.js` file:
```javascript
module.exports = {
// ...your config,
custom_commands_path: path.resolve('@reportportal/agent-js-nightwatch/commands'),
custom_commands_path: ['./node_modules/@reportportal/agent-js-nightwatch/build/commands'],
}
```

##### rpLog
Send log with corresponding level to report portal for the current test or for provided by name. Should be called inside of corresponding test.<br/>
`ReportingAPI.setStatus(message: string, level: string, itemName?: string);`<br/>
`browser.rpLog(message: string, level: string, itemName?: string);`<br/>
**required**: `message, level = 'INFO'`<br/>
`itemName` **required** only for parallel run<br/>
where `level` can be one of the following: *TRACE*, *DEBUG*, *WARN*, *INFO*, *ERROR*, *FATAL*<br/>
Expand All @@ -538,7 +542,7 @@ describe('Suite name', function() {

##### rpSaveScreenshot
Send log with screenshot attachment with provided name to report portal for the current test or for provided by name. Should be called inside of corresponding test.<br/>
`ReportingAPI.rpSaveScreenshot(fileName: string, itemName?: string, callback?: function);`<br/>
`browser.rpSaveScreenshot(fileName: string, itemName?: string, callback?: function);`<br/>
**required**: `fileName`<br/>
`itemName` **required** only for parallel run<br/>
Example:
Expand All @@ -555,7 +559,7 @@ describe('Suite name', function() {

##### rpScreenshot
Send log with screenshot attachment to report portal for the current test or for provided by name. Should be called inside of corresponding test.<br/>
`ReportingAPI.rpScreenshot(itemName?: string, callback?: function);`<br/>
`browser.rpScreenshot(itemName?: string, callback?: function);`<br/>
`itemName` **required** only for parallel run<br/>
Example:
```javascript
Expand All @@ -571,7 +575,7 @@ describe('Suite name', function() {

#### Integration with Sauce Labs

To integrate with Sauce Labs just add attributes:
To integrate with Sauce Labs just add attributes for the test case:

```javascript
[{
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.1
5.0.2-SNAPSHOT
8 changes: 4 additions & 4 deletions src/__tests__/realTimeReporter/reporter/constructor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ describe('constructor', function() {
expect(reporter.storage).toBeInstanceOf(Storage);
});

test('should override default options', function() {
test('should correctly set launchParams property', function() {
const config = getDefaultMockConfig();
config.rerun = true;
config.rerunOf = 'launchUUID';
const reporter = new RealTimeReporter(config);

// @ts-ignore access to the class private property
expect(reporter.config).toBeDefined();
expect(reporter.launchParams).toBeDefined();

// @ts-ignore access to the class private property
expect(reporter.config.rerunOf).toEqual('launchUUID');
expect(reporter.launchParams.rerunOf).toEqual('launchUUID');

// @ts-ignore access to the class private property
expect(reporter.config.rerun).toEqual(true);
expect(reporter.launchParams.rerun).toEqual(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ describe('launchReporting', function() {

reporter.startLaunch(launchObj);

expect(spyGetStartLaunchObj).toHaveBeenCalledWith(launchObj);
expect(spyGetStartLaunchObj).toHaveBeenCalledWith(launchObj, {
description: 'Launch description',
attributes: [],
});
});

test('should start launch by calling the ReportPortal client startLaunch method', function() {
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/realTimeReporter/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ describe('getStartLaunchObj', function() {
jest.clearAllMocks();
});

test('should return startLaunchObject with updated attributes in case of rp config contains it', function() {
const startLaunchObject = getStartLaunchObj(
{},
{ attributes: [{ value: 'value', key: 'key' }] },
);

expect(startLaunchObject.attributes).toEqual([
{ value: 'value', key: 'key' },
{ value: 'mockValue', key: 'mockKey' },
]);
});

test('should return startLaunchObject with updated attributes in case of launch has it', function() {
const startLaunchObject = getStartLaunchObj({ attributes: [{ value: 'value', key: 'key' }] });

Expand All @@ -70,6 +82,18 @@ describe('getStartLaunchObj', function() {
]);
});

test('should return startLaunchObject with updated attributes in case of launch has it in priority of rp config file', function() {
const startLaunchObject = getStartLaunchObj(
{ attributes: [{ value: 'value', key: 'key' }] },
{ attributes: [{ value: 'configValue', key: 'configKey' }] },
);

expect(startLaunchObject.attributes).toEqual([
{ value: 'value', key: 'key' },
{ value: 'mockValue', key: 'mockKey' },
]);
});

test('should return startLaunchObject with system attributes in case of launch has not any attributes', function() {
const startLaunchObject = getStartLaunchObj({});

Expand Down
4 changes: 2 additions & 2 deletions src/models/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ interface RPItem {
}

export interface RPItemStartRQ extends RPItem {
startTime?: Date;
startTime?: Date | number;
}

export interface RPItemFinishRQ extends RPItem {
status?: STATUSES;
endTime?: Date;
endTime?: Date | number;
}

export interface StorageTestItem extends RPItem {
Expand Down
16 changes: 12 additions & 4 deletions src/postFactumReporter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import moment from 'moment';
import RPClient from '@reportportal/client-javascript';
import { AgentOptions, Attribute, ReportPortalConfig } from '../models';
import { AgentOptions, ReportPortalConfig, StartLaunchRQ } from '../models';
import { buildCodeRef, getSystemAttributes, getLastItem } from '../utils';
import { STATUSES, LOG_LEVELS, TEST_ITEM_TYPES, EVENTS } from '../constants';

Expand All @@ -26,14 +26,22 @@ export default class PostFactumReporter {
private readonly options: AgentOptions;
private launchId: string;
private launchStartTime: number | Date;
private launchParams: { attributes: Attribute[]; description: string };
private launchParams: StartLaunchRQ;

constructor(config: ReportPortalConfig & AgentOptions) {
const { attributes = [], description, parallelRun = false, ...clientConfig } = config;
const {
attributes = [],
description,
rerun,
rerunOf,
mode,
parallelRun = false,
...clientConfig
} = config;
const launchAttributes = attributes.concat(getSystemAttributes());

this.client = new RPClient(clientConfig);
this.launchParams = { attributes: launchAttributes, description };
this.launchParams = { attributes: launchAttributes, description, rerun, rerunOf, mode };
this.options = { parallelRun };
this.launchStartTime = Date.now();
}
Expand Down
9 changes: 5 additions & 4 deletions src/realTimeReporter/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ export default class Reporter {
private client: RPClient;
private launchId: string;
private storage: Storage;
private config: ReportPortalConfig;
private launchParams: StartLaunchRQ;

constructor(config: ReportPortalConfig) {
this.initReporter();
const { attributes = [], description, rerun, rerunOf, mode, ...clientConfig } = config;
const agentInfo = getAgentInfo();

this.config = config;
this.client = new RPClient(config, agentInfo);
this.launchParams = { attributes, description, rerun, rerunOf, mode };
this.client = new RPClient(clientConfig, agentInfo);
this.storage = new Storage();
}

Expand Down Expand Up @@ -109,7 +110,7 @@ export default class Reporter {
}

public startLaunch(launchObj: StartLaunchRQ): void {
const startLaunchObj: StartLaunchRQ = getStartLaunchObj(launchObj);
const startLaunchObj: StartLaunchRQ = getStartLaunchObj(launchObj, this.launchParams);

this.launchId = this.client.startLaunch(startLaunchObj).tempId;
}
Expand Down
17 changes: 12 additions & 5 deletions src/realTimeReporter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ import { Attachment, StartLaunchRQ, Attribute } from '../models';
export const setDefaultFileType = (file: Attachment): Attachment =>
file ? { type: DEFAULT_FILE_TYPE, ...file } : undefined;

export const getStartLaunchObj = (launchObj: StartLaunchRQ): StartLaunchRQ => {
export const getStartLaunchObj = (
launchObj: StartLaunchRQ,
config: StartLaunchRQ = {},
): StartLaunchRQ => {
const systemAttributes: Array<Attribute> = getSystemAttributes();
const attributes = (launchObj.attributes || config.attributes || []).concat(systemAttributes);

return {
description: config.description,
rerun: config.rerun,
rerunOf: config.rerunOf,
mode: config.mode,
...launchObj,
attributes: launchObj.attributes
? launchObj.attributes.concat(systemAttributes)
: systemAttributes,
attributes,
};
};

Expand All @@ -44,7 +50,8 @@ export const calculateTestItemStatus = (
status = STATUSES.SKIPPED;
} else if (currentTestItemResults.failed !== 0) {
status = STATUSES.FAILED;
const assertionsResult = currentTestItemResults.assertions[0];
const assertionsResult =
currentTestItemResults.assertions[currentTestItemResults.assertions.length - 1];

assertionsMessage = `${assertionsResult.fullMsg}<br/>${assertionsResult.stackTrace}`;
} else {
Expand Down

0 comments on commit 1e69f86

Please sign in to comment.