Skip to content

Commit

Permalink
EPMRPP-78272 || Code review fixes - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzmitry Kosarau authored and Dzmitry Kosarau committed Oct 17, 2023
1 parent 29050d4 commit ee554d7
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 113 deletions.
70 changes: 4 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ This reporter provides Reporting API to use it directly in tests to send some ad

To start using the `ReportingApi` in tests, just import it from `'@reportportal/agent-js-playwright/promises'`:
```javascript
import { ReportingApi } from '@reportportal/agent-js-playwright';
// or
import { ReportingApi } from '@reportportal/agent-js-playwright/promises'
```

Expand All @@ -145,25 +143,6 @@ If you want to add a data to the suite, you must pass the suite name as the last

##### addAttributes
Add attributes (tags) to the current test. Should be called inside of corresponding test.<br/>
`ReportingApi.addAttributes(attributes: Array<Attribute>, suite?: string);`<br/>
**required**: `attributes`<br/>
**optional**: `suite`<br/>
Example:
```javascript
test('should have the correct attributes', () => {
ReportingApi.addAttributes([
{
key: 'testKey',
value: 'testValue',
},
{
value: 'testValueTwo',
},
]);
expect(true).toBe(true);
});
```

`ReportingApi.addAttributes(attributes: Array<Attribute>, suite?: string):Promise<void>;`<br/>
**required**: `attributes`<br/>
**optional**: `suite`<br/>
Expand All @@ -187,21 +166,10 @@ test('should have the correct attributes', async () => {

##### setTestCaseId
Set test case id to the current test ([About test case id](https://reportportal.io/docs/Test-case-ID%3Ewhat-is-it-test-case-id)). Should be called inside of corresponding test.<br/>
`ReportingApi.setTestCaseId(id: string, suite?: string);`<br/>
**required**: `id`<br/>
**optional**: `suite`<br/>
If `testCaseId` not specified, it will be generated automatically based on [codeRef](https://reportportal.io/docs/Test-case-ID%3Ewhat-does-happen-if-you-do-not-report-items-with-test-case-id-).<br/>
Example:
```javascript
test('should have the correct testCaseId', () => {
ReportingApi.setTestCaseId('itemTestCaseId');
expect(true).toBe(true);
});
```

`ReportingApi.setTestCaseId(id: string, suite?: string):Promise<void>;`<br/>
**required**: `id`<br/>
**optional**: `suite`<br/>
If `testCaseId` not specified, it will be generated automatically based on [codeRef](https://reportportal.io/docs/Test-case-ID%3Ewhat-does-happen-if-you-do-not-report-items-with-test-case-id-).<br/>
Example:
```javascript
import { ReportingApi } from '@reportportal/agent-js-playwright/promises'
Expand Down Expand Up @@ -306,23 +274,12 @@ test('should contain logs with attachments', () => {

##### setStatus
Assign corresponding status to the current test item. Should be called inside of corresponding test.<br/>
`ReportingApi.setStatus(status: string, suite?: string);`<br/>
`ReportingApi.setStatus(status: string, suite?: string):Promise<void>;`<br/>
**required**: `status`<br/>
**optional**: `suite`<br/>
where `status` must be one of the following: *passed*, *failed*, *stopped*, *skipped*, *interrupted*, *cancelled*<br/>
Example:
```javascript
test('should have status FAILED', () => {
ReportingApi.setStatus('failed');

expect(true).toBe(true);
});
```

`ReportingApi.setStatus(status: string, suite?: string):Promise<void>;`<br/>
**required**: `status`<br/>
**optional**: `suite`<br/>
```javascript
import { ReportingApi } from '@reportportal/agent-js-playwright/promises'

test('should have status FAILED', async () => {
Expand All @@ -334,25 +291,6 @@ test('should have status FAILED', async () => {

##### setStatusFailed, setStatusPassed, setStatusSkipped, setStatusStopped, setStatusInterrupted, setStatusCancelled
Assign corresponding status to the current test item. Should be called inside of corresponding test.<br/>
`ReportingApi.setStatusFailed(suite?: string);`<br/>
`ReportingApi.setStatusPassed(suite?: string);`<br/>
`ReportingApi.setStatusSkipped(suite?: string);`<br/>
`ReportingApi.setStatusStopped(suite?: string);`<br/>
`ReportingApi.setStatusInterrupted(suite?: string);`<br/>
`ReportingApi.setStatusCancelled(suite?: string);`<br/>
**optional**: `suite`<br/>
Example:
```javascript
test('should call ReportingApi to set statuses', () => {
ReportingAPI.setStatusFailed();
ReportingAPI.setStatusPassed();
ReportingAPI.setStatusSkipped();
ReportingAPI.setStatusStopped();
ReportingAPI.setStatusInterrupted();
ReportingAPI.setStatusCancelled();
});

```
`ReportingApi.setStatusFailed(suite?: string):Promise<void>;`<br/>
`ReportingApi.setStatusPassed(suite?: string):Promise<void>;`<br/>
`ReportingApi.setStatusSkipped(suite?: string):Promise<void>;`<br/>
Expand All @@ -366,12 +304,12 @@ import { ReportingApi } from '@reportportal/agent-js-playwright/promises'

test('should call ReportingApi to set statuses', async () => {
await Promise.all[
ReportingAPI.setStatusFailed();
ReportingAPI.setStatusFailed(),
ReportingAPI.setStatusPassed(),
ReportingAPI.setStatusSkipped(),
ReportingAPI.setStatusStopped(),
ReportingAPI.setStatusInterrupted(),
ReportingAPI.setStatusCancelled()
ReportingAPI.setStatusCancelled(),
]
});
```
Expand Down
28 changes: 13 additions & 15 deletions src/__tests__/reporter/finishTestItemReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* limitations under the License.
*/

import { EVENTS } from '@reportportal/client-javascript/lib/constants/events';
import { RPReporter } from '../../reporter';
import { mockConfig } from '../mocks/configMock';
import { RPClientMock } from '../mocks/RPClientMock';
import { FinishTestItemObjType } from '../../models';
import { RPTestInfo, STATUSES } from '../../constants';
import { STATUSES } from '../../constants';

const rootSuite = 'rootSuite';
const suiteName = 'suiteName';
Expand Down Expand Up @@ -110,12 +111,12 @@ describe('finish test reporting', () => {
{
attachments: [
{
name: RPTestInfo.attributes,
name: EVENTS.ADD_ATTRIBUTES,
body: Buffer.from(JSON.stringify([{ key: 'key', value: 'value' }])),
contentType: 'application/json',
},
{
name: RPTestInfo.description,
name: EVENTS.SET_DESCRIPTION,
body: Buffer.from('description'),
contentType: 'text/plain',
},
Expand Down Expand Up @@ -157,12 +158,12 @@ describe('finish test reporting', () => {
{
attachments: [
{
name: RPTestInfo.attributes,
name: EVENTS.ADD_ATTRIBUTES,
body: Buffer.from(JSON.stringify([{ key: 'key', value: 'value' }])),
contentType: 'application/json',
},
{
name: RPTestInfo.description,
name: EVENTS.SET_DESCRIPTION,
body: Buffer.from('description'),
contentType: 'text/plain',
},
Expand Down Expand Up @@ -249,7 +250,7 @@ describe('finish test reporting', () => {
{
attachments: [
{
name: RPTestInfo.attributes,
name: EVENTS.ADD_ATTRIBUTES,
contentType: 'application/json',
body: Buffer.from(
JSON.stringify([
Expand All @@ -259,22 +260,22 @@ describe('finish test reporting', () => {
),
},
{
name: RPTestInfo.description,
name: EVENTS.SET_DESCRIPTION,
contentType: 'plain/text',
body: Buffer.from('Description'),
},
{
name: RPTestInfo.status,
name: EVENTS.SET_STATUS,
contentType: 'plain/text',
body: Buffer.from('skipped'),
},
{
name: RPTestInfo.status,
name: EVENTS.SET_STATUS,
contentType: 'plain/text',
body: Buffer.from('interrupted'),
},
{
name: RPTestInfo.testCaseId,
name: EVENTS.SET_TEST_CASE_ID,
contentType: 'plain/text',
body: Buffer.from('testCaseId'),
},
Expand All @@ -293,11 +294,8 @@ describe('finish test reporting', () => {
const finishStepObject: FinishTestItemObjType = {
endTime: reporter.client.helpers.now(),
status: STATUSES.INTERRUPTED,
attributes: [
{ key: 'key1', value: 'value1', system: false },
{ key: 'key2', value: 'value2', system: false },
],
description: 'Description',
attributes: [{ key: 'key', value: 'value' }],
description: 'description',
testCaseId: 'testCaseId',
};

Expand Down
18 changes: 9 additions & 9 deletions src/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

import { EVENTS } from '@reportportal/client-javascript/lib/constants/events';
// @ts-ignore
import { name as pjsonName, version as pjsonVersion } from '../../package.json';
import {
Expand All @@ -36,7 +37,6 @@ import {
TestOutcome,
BASIC_ATTACHMENT_CONTENT_TYPES,
BASIC_ATTACHMENT_NAMES,
RPTestInfo,
} from '../constants';
import { TestCase } from '@playwright/test/reporter';
import { TestAdditionalInfo } from '../models/reporting';
Expand Down Expand Up @@ -430,7 +430,7 @@ describe('testing utils', () => {
{
attachments: [
{
name: RPTestInfo.attributes,
name: EVENTS.ADD_ATTRIBUTES,
contentType: 'application/json',
body: Buffer.from(
JSON.stringify([
Expand All @@ -440,22 +440,22 @@ describe('testing utils', () => {
),
},
{
name: RPTestInfo.description,
name: EVENTS.SET_DESCRIPTION,
contentType: 'plain/text',
body: Buffer.from('Description'),
},
{
name: RPTestInfo.status,
name: EVENTS.SET_STATUS,
contentType: 'plain/text',
body: Buffer.from('skipped'),
},
{
name: RPTestInfo.status,
name: EVENTS.SET_STATUS,
contentType: 'plain/text',
body: Buffer.from('failed'),
},
{
name: RPTestInfo.testCaseId,
name: EVENTS.SET_TEST_CASE_ID,
contentType: 'plain/text',
body: Buffer.from('testCaseId'),
},
Expand Down Expand Up @@ -490,20 +490,20 @@ describe('testing utils', () => {
{
attachments: [
{
name: RPTestInfo.attributes,
name: EVENTS.ADD_ATTRIBUTES,
contentType: 'application/json',
body: Buffer.from(
`{ key: 'key1', value: 'value1', system: true },
{ key: 'key2', value: 'value2', system: true }`,
),
},
{
name: RPTestInfo.description,
name: EVENTS.SET_DESCRIPTION,
contentType: 'plain/text',
body: Buffer.from('Description'),
},
{
name: RPTestInfo.status,
name: EVENTS.SET_STATUS,
contentType: 'plain/text',
body: Buffer.from('skipped'),
},
Expand Down
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export { LAUNCH_MODES } from './launchModes';
export { TEST_ITEM_TYPES } from './testItemTypes';
export { STATUSES } from './statuses';
export { LOG_LEVELS } from './logLevels';
export { RPTestInfo } from './testInfo';
export { RPTestInfo, RpEventsToAdditionalInfoMap } from './testInfo';
export {
TestAnnotation,
TestOutcome,
Expand Down
21 changes: 15 additions & 6 deletions src/constants/testInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
*
*/

export const RPTestInfo = {
status: 'status',
attributes: 'attributes',
description: 'description',
testCaseId: 'testCaseId',
} as const;
import { EVENTS } from '@reportportal/client-javascript/lib/constants/events';

export enum RPTestInfo {
STATUS = 'status',
ATTRIBUTES = 'attributes',
DESCRIPTION = 'description',
TEST_CASE_ID = 'testCaseId',
}

export const RpEventsToAdditionalInfoMap = {
[EVENTS.ADD_ATTRIBUTES]: RPTestInfo.ATTRIBUTES,
[EVENTS.SET_DESCRIPTION]: RPTestInfo.DESCRIPTION,
[EVENTS.SET_TEST_CASE_ID]: RPTestInfo.TEST_CASE_ID,
[EVENTS.SET_STATUS]: RPTestInfo.STATUS,
};
12 changes: 6 additions & 6 deletions src/promises/reportingApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 EPAM Systems
* Copyright 2023 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@
import { EVENTS } from '@reportportal/client-javascript/lib/constants/events';
import { sendEventToReporter } from '../utils';
import { Attribute } from '../models';
import { STATUSES, LOG_LEVELS, RPTestInfo } from '../constants';
import { STATUSES, LOG_LEVELS } from '../constants';
import { Attachment } from '../models/reporting';
import { test } from '@playwright/test';

Expand All @@ -30,7 +30,7 @@ export const ReportingApi = {
return Promise.resolve();
}

return test.info().attach(RPTestInfo.attributes, {
return test.info().attach(EVENTS.ADD_ATTRIBUTES, {
body: JSON.stringify(attrs),
contentType: 'application/json',
});
Expand All @@ -43,7 +43,7 @@ export const ReportingApi = {
return Promise.resolve();
}

return test.info().attach(RPTestInfo.description, {
return test.info().attach(EVENTS.SET_DESCRIPTION, {
body: description,
contentType: 'text/plain',
});
Expand All @@ -55,7 +55,7 @@ export const ReportingApi = {
return Promise.resolve();
}

return test.info().attach(RPTestInfo.testCaseId, {
return test.info().attach(EVENTS.SET_TEST_CASE_ID, {
body: testCaseId,
contentType: 'text/plain',
});
Expand All @@ -67,7 +67,7 @@ export const ReportingApi = {
return Promise.resolve();
}

return test.info().attach(RPTestInfo.status, {
return test.info().attach(EVENTS.SET_STATUS, {
body: status,
contentType: 'text/plain',
});
Expand Down
Loading

0 comments on commit ee554d7

Please sign in to comment.