Skip to content

Commit

Permalink
Merge pull request #31 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.0.2
  • Loading branch information
AmsterGet authored Feb 4, 2022
2 parents ae36d36 + 7f5d607 commit 9e3b46a
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 153 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ jobs:
run: npm run build
- name: Run lint
run: npm run lint
# - name: Run tests and check coverage
# run: npm run test:coverage
- name: Run tests and check coverage
run: npm run test:coverage
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
run: npm run build
- name: Run lint
run: npm run lint
- name: Run tests and check coverage
run: npm run test:coverage

publish-to-npm-and-gpr:
needs: build
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Added
- Ability to attach logs to items via `console.*` [methods](./README.md#logging)
### Fixed
- [#26](https://github.com/reportportal/agent-js-playwright/issues/26) Error when value is not allowed for field 'status'

## [5.0.1] - 2022-01-17
### Added
Expand Down
56 changes: 45 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,28 @@ test('basic test', async ({ page }, testInfo) => {
});
```

*Note:* attachment body can be provided instead of path.
*Note:* attachment body can be provided instead of path.

As an alternative to this approach the [`ReportingAPI`](#log) methods can be used.

### Logging

You can use the following `console` native methods to report logs to tests:

```typescript
console.log();
console.info();
console.debug();
console.warn();
console.error();
```

console`log`, `info`,`dubug` report as info log.

console `error`, `warn` report as error log if message contains "error" mention.
In other cases report as warn log.

As an alternative to this approach the [`ReportingAPI`](#log) methods can be used.

### Reporting API

Expand Down Expand Up @@ -119,11 +140,11 @@ test('should have the correct attributes', () => {
```

##### setTestCaseId
Set test case id to the current test. Should be called inside of corresponding test or fixture.<br/>
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.<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', () => {
Expand All @@ -133,7 +154,7 @@ test('should have the correct testCaseId', () => {
```

##### log
Send logs to report portal for the current test. Should be called inside of corresponding test or fixture.<br/>
Send logs to report portal for the current test. Should be called inside of corresponding test.<br/>
`ReportingApi.log(level: LOG_LEVELS, message: string, file?: Attachment, suite?: string);`<br/>
**required**: `level`, `message`<br/>
**optional**: `file`, `suite`<br/>
Expand All @@ -155,7 +176,7 @@ test('should contain logs with attachments',() => {
```

##### info, debug, warn, error, trace, fatal
Send logs with corresponding level to report portal for the current test or for provided by name. Should be called inside of corresponding test or fixture.<br/>
Send logs with corresponding level to report portal for the current test. Should be called inside of corresponding test.<br/>
`ReportingApi.info(message: string, file?: Attachment, suite?: string);`<br/>
`ReportingApi.debug(message: string, file?: Attachment, suite?: string);`<br/>
`ReportingApi.warn(message: string, file?: Attachment, suite?: string);`<br/>
Expand All @@ -179,7 +200,7 @@ test('should contain logs with attachments', () => {
```

##### launchLog
Send logs to report portal for the current launch. Should be called inside of the any test or fixture.<br/>
Send logs to report portal for the current launch. Should be called inside of the any test or suite.<br/>
`ReportingApi.launchLog(level: LOG_LEVELS, message: string, file?: Attachment);`<br/>
**required**: `level`, `message`<br/>
**optional**: `file`<br/>
Expand All @@ -201,7 +222,7 @@ test('should contain logs with attachments', async () => {
```

##### launchInfo, launchDebug, launchWarn, launchError, launchTrace, launchFatal
Send logs with corresponding level to report portal for the current launch. Should be called inside of the any test or fixture.<br/>
Send logs with corresponding level to report portal for the current launch. Should be called inside of the any test or suite.<br/>
`ReportingApi.launchInfo(message: string, file?: Attachment);`<br/>
`ReportingApi.launchDebug(message: string, file?: Attachment);`<br/>
`ReportingApi.launchWarn(message: string, file?: Attachment);`<br/>
Expand All @@ -225,7 +246,7 @@ test('should contain logs with attachments', () => {
```

##### setStatus
Assign corresponding status to the current test item.<br/>
Assign corresponding status to the current test item. Should be called inside of corresponding test.<br/>
`ReportingApi.setStatus(status: string, suite?: string);`<br/>
**required**: `status`<br/>
**optional**: `suite`<br/>
Expand All @@ -240,7 +261,7 @@ test('should have status FAILED', () => {
```

##### setStatusFailed, setStatusPassed, setStatusSkipped, setStatusStopped, setStatusInterrupted, setStatusCancelled
Assign corresponding status to the current test item.<br/>
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/>
Expand All @@ -261,7 +282,7 @@ test('should call ReportingApi to set statuses', () => {
```

##### setLaunchStatus
Assign corresponding status to the current launch.<br/>
Assign corresponding status to the current launch. Should be called inside of the any test or suite.<br/>
`ReportingApi.setLaunchStatus(status: string);`<br/>
**required**: `status`<br/>
where `status` must be one of the following: *passed*, *failed*, *stopped*, *skipped*, *interrupted*, *cancelled*<br/>
Expand All @@ -274,7 +295,7 @@ test('launch should have status FAILED', () => {
```

##### setLaunchStatusFailed, setLaunchStatusPassed, setLaunchStatusSkipped, setLaunchStatusStopped, setLaunchStatusInterrupted, setLaunchStatusCancelled
Assign corresponding status to the current test item.<br/>
Assign corresponding status to the current test item. Should be called inside of the any test or suite.<br/>
`ReportingApi.setLaunchStatusFailed();`<br/>
`ReportingApi.setLaunchStatusPassed();`<br/>
`ReportingApi.setLaunchStatusSkipped();`<br/>
Expand All @@ -293,3 +314,16 @@ test('should call ReportingApi to set launch statuses', () => {
});
```

### Integration with Sauce Labs

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

```javascript
[{
"key": "SLID",
"value": "# of the job in Sauce Labs"
}, {
"key": "SLDC",
"value": "EU (your job region in Sauce Labs)"
}]
```
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"strip-ansi": "^6.0.1"
},
"files": [
"/build",
"/VERSION"
"/build"
],
"devDependencies": {
"@playwright/test": "^1.17.1",
Expand Down
51 changes: 51 additions & 0 deletions src/__tests__/reporter/onStdErr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2021 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { RPReporter } from '../../reporter';
import { mockConfig } from '../mocks/configMock';
import { RPClientMock } from '../mocks/RPClientMock';
import { LOG_LEVELS } from '../../constants';

describe('onStdErr testing', () => {
const reporter = new RPReporter(mockConfig);
reporter.client = new RPClientMock(mockConfig);

test('onStdErr call sendTestItemLog with LOG_LEVELS.ERROR', () => {
const test = {
title: 'some test',
};
jest.spyOn(reporter, 'sendTestItemLog');
// @ts-ignore
reporter.onStdErr('Some error log', test);
expect(reporter.sendTestItemLog).toHaveBeenCalledWith(
{ level: LOG_LEVELS.ERROR, message: 'Some error log' },
test,
);
});

test('onStdErr call sendTestItemLog with LOG_LEVELS.WARN', () => {
const test = {
title: 'some test',
};
jest.spyOn(reporter, 'sendTestItemLog');
// @ts-ignore
reporter.onStdErr('Some warn message', test);
expect(reporter.sendTestItemLog).toHaveBeenCalledWith(
{ level: LOG_LEVELS.WARN, message: 'Some warn message' },
test,
);
});
});
10 changes: 10 additions & 0 deletions src/__tests__/reporter/onStdOut.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,14 @@ describe('onStdOut testing', () => {
reporter.onStdOut(chunk);
expect(reporter.sendLaunchLog).toHaveBeenCalled();
});

test('case stdOut logs', () => {
const test = {
title: 'some test',
};
jest.spyOn(reporter, 'sendTestItemLog');
// @ts-ignore
reporter.onStdOut('Some logs', test);
expect(reporter.sendTestItemLog).toHaveBeenCalledWith({ message: 'Some logs' }, test);
});
});
39 changes: 18 additions & 21 deletions src/__tests__/reporter/retriesReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,36 @@ describe('retries reporting', () => {
reporter.client = new RPClientMock(mockConfig);

const testParams = {
title: 'testName',
title: 'testTitle',
parent: {
title: 'suiteName',
location: 'tests/example.js',
},
location: {
file: `C:${path.sep}testProject${path.sep}test${path.sep}example.js`,
file: `C:${path.sep}testProject${path.sep}tests${path.sep}example.js`,
line: 5,
column: 3,
},
titlePath: () => ['example.js', 'rootDescribe', 'parentDescribe', 'testTitle'],
titlePath: () => ['suiteName', 'testTitle'],
results: [{}, {}],
};
jest.spyOn(process, 'cwd').mockImplementation(() => `C:${path.sep}testProject`);

const parentId = 'tempTestItemId';
const expectedStartObj: StartTestObjType = {
startTime: reporter.client.helpers.now(),
name: testParams.title,
type: TEST_ITEM_TYPES.STEP,
codeRef: 'test/example.js/rootDescribe/parentDescribe/testTitle',
retry: true,
};
const spyStartTestItem = jest.spyOn(reporter.client, 'startTestItem');

reporter.suites = new Map([['tempTestItemId', { id: 'tempTestItemId', name: 'suiteName' }]]);
test('client.startTestItem should be called with retry=true params', () => {
const parentId = 'tempTestItemId';
const expectedTestObj: StartTestObjType = {
startTime: reporter.client.helpers.now(),
name: 'testTitle',
type: TEST_ITEM_TYPES.STEP,
codeRef: 'suiteName/testTitle',
retry: true,
};
reporter.suites = new Map([['suiteName', { id: 'tempTestItemId', name: 'suiteName' }]]);

// @ts-ignore
reporter.onTestBegin(testParams);
// @ts-ignore
reporter.onTestBegin(testParams);

test('client.startTestItem should be called with retry=true params', () => {
expect(reporter.client.startTestItem).toHaveBeenCalledWith(
expectedStartObj,
reporter.launchId,
parentId,
);
expect(spyStartTestItem).toHaveBeenCalledWith(expectedTestObj, reporter.launchId, parentId);
});
});
Loading

0 comments on commit 9e3b46a

Please sign in to comment.