Skip to content

Commit

Permalink
Merge pull request #53 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.0.5
  • Loading branch information
AmsterGet authored Jul 12, 2022
2 parents a9d27c3 + f7e891b commit a08f71c
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 49 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Fixed
- Error with test steps finishing
- Test steps nesting structure
- Launch mode property support

## [5.0.4] - 2022-05-30
### Fixed
Expand All @@ -19,7 +23,7 @@

## [5.0.1] - 2022-01-17
### Added
- Ability to attach screenshots and other files via [test info attachments](https://playwright.dev/docs/1.17/api/class-testinfo#test-info-attachments)
- Ability to attach screenshots and other files via [test info attachments](https://playwright.dev/docs/api/class-testinfo#test-info-attachments)
- TypeScript definitions provided
### Fixed
- Error when reporting tests without describe blocks
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ npm install --save-dev @reportportal/agent-js-playwright

### Attachments

Attachments can be easily added during test run via `testInfo.attachments` according to the Playwright [docs](https://playwright.dev/docs/1.17/api/class-testinfo#test-info-attachments).
Attachments can be easily added during test run via `testInfo.attachments` according to the Playwright [docs](https://playwright.dev/docs/api/class-testinfo#test-info-attachments).

```typescript
import { test, expect } from '@playwright/test';
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.4
5.0.5-SNAPSHOT
14 changes: 11 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@reportportal/client-javascript": "^5.0.6",
"axios": "^0.24.0",
"strip-ansi": "^6.0.1"
},
"files": [
Expand Down
71 changes: 52 additions & 19 deletions src/__tests__/reporter/launchesReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,62 @@
*/

import { RPReporter } from '../../reporter';
import { mockConfig } from '../mocks/configMock';
import { StartLaunchObjType } from '../../models';
import { RPClientMock } from '../mocks/RPClientMock';
import { getSystemAttributes } from '../../utils';
import { LAUNCH_MODES } from '../../constants';

import { mockConfig } from '../mocks/configMock';
import { RPClientMock } from '../mocks/RPClientMock';

describe('start report launch', () => {
const reporter = new RPReporter(mockConfig);
reporter.client = new RPClientMock(mockConfig);
const startLaunchObj: StartLaunchObjType = {
name: mockConfig.launch,
startTime: reporter.client.helpers.now(),
attributes: getSystemAttributes(),
description: mockConfig.description,
};

reporter.onBegin();

test('client.startLaunch should be called with corresponding params', () => {
expect(reporter.client.startLaunch).toHaveBeenCalledTimes(1);
expect(reporter.client.startLaunch).toHaveBeenCalledWith(startLaunchObj);
describe('DEFAULT mode', () => {
const reporter = new RPReporter(mockConfig);
reporter.client = new RPClientMock(mockConfig);
const startLaunchObj: StartLaunchObjType = {
name: mockConfig.launch,
startTime: reporter.client.helpers.now(),
attributes: getSystemAttributes(),
description: mockConfig.description,
mode: LAUNCH_MODES.DEFAULT,
};

beforeAll(() => reporter.onBegin());

test('client.startLaunch should be called with corresponding params', () => {
expect(reporter.client.startLaunch).toHaveBeenCalledTimes(1);
expect(reporter.client.startLaunch).toHaveBeenCalledWith(startLaunchObj);
});

test('reporter.launchId should be set', () => {
expect(reporter.launchId).toEqual('tempLaunchId');
});
});

test('reporter.launchId should be set', () => {
expect(reporter.launchId).toEqual('tempLaunchId');
describe('DEBUG mode', () => {
const customConfig = {
...mockConfig,
mode: LAUNCH_MODES.DEBUG,
};
const reporter = new RPReporter(customConfig);
reporter.client = new RPClientMock(customConfig);
const startLaunchObj: StartLaunchObjType = {
name: customConfig.launch,
startTime: reporter.client.helpers.now(),
attributes: getSystemAttributes(),
description: customConfig.description,
mode: customConfig.mode,
};

beforeAll(() => reporter.onBegin());

test('should allow to pass mode to startLaunch', () => {
expect(reporter.client.startLaunch).toHaveBeenCalledTimes(1);
expect(reporter.client.startLaunch).toHaveBeenCalledWith(startLaunchObj);
});

test('reporter.launchId should be set', () => {
expect(reporter.launchId).toEqual('tempLaunchId');
});
});
});

Expand All @@ -48,8 +80,9 @@ describe('finish report launch', () => {
reporter.client = new RPClientMock(mockConfig);
reporter.launchId = 'tempLaunchId';

beforeAll(() => reporter.onEnd());

test('launch should be finished', () => {
reporter.onEnd();
expect(reporter.client.finishLaunch).toHaveBeenCalledTimes(1);
expect(reporter.client.finishLaunch).toHaveBeenCalledWith('tempLaunchId', {
endTime: reporter.client.helpers.now(),
Expand Down
8 changes: 8 additions & 0 deletions src/models/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
*
*/

import { AxiosRequestConfig } from 'axios';
import { AgentOptions } from 'https';

import { Attribute } from './common';
import { LAUNCH_MODES } from '../constants';

export interface RestClientConfig extends AxiosRequestConfig {
agent?: AgentOptions;
}

export interface ReportPortalConfig {
token: string;
project: string;
Expand All @@ -33,4 +40,5 @@ export interface ReportPortalConfig {
isLaunchMergeRequired?: boolean;
skippedIssue?: boolean;
includeTestSteps?: boolean;
restClientConfig?: RestClientConfig;
}
3 changes: 2 additions & 1 deletion src/models/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { Attribute } from './common';
import { TEST_ITEM_TYPES, LOG_LEVELS } from '../constants';
import { TEST_ITEM_TYPES, LOG_LEVELS, LAUNCH_MODES } from '../constants';

export interface StartLaunchObjType {
startTime?: Date | number;
Expand All @@ -25,6 +25,7 @@ export interface StartLaunchObjType {
name?: string;
rerun?: boolean;
rerunOf?: string;
mode?: LAUNCH_MODES;
}

export interface StartTestObjType {
Expand Down
50 changes: 29 additions & 21 deletions src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 EPAM Systems
* Copyright 2022 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 Down Expand Up @@ -32,7 +32,7 @@ import {
StartLaunchObjType,
StartTestObjType,
} from './models';
import { LOG_LEVELS, STATUSES, TEST_ITEM_TYPES } from './constants';
import { LAUNCH_MODES, LOG_LEVELS, STATUSES, TEST_ITEM_TYPES } from './constants';
import {
convertToRpStatus,
getAgentInfo,
Expand Down Expand Up @@ -221,24 +221,24 @@ export class RPReporter implements Reporter {
}

finishSuites(testFileName?: string, rootSuiteName?: string): void {
let finishSuites: [string, Suite][];
let suitesToFinish: [string, Suite][];
const suitesArray = Array.from(this.suites);

const isExistTestsInRootSuite = this.suites.get(rootSuiteName).rootSuiteLength < 1;
const isTestsExistInRootSuite = this.suites.get(rootSuiteName).rootSuiteLength < 1;

if (isExistTestsInRootSuite) {
finishSuites = testFileName
if (isTestsExistInRootSuite) {
suitesToFinish = testFileName
? suitesArray.filter(([key]) => key.includes(rootSuiteName))
: suitesArray;
} else {
finishSuites = testFileName
suitesToFinish = testFileName
? suitesArray.filter(
([key, { testsLength }]) => key.includes(rootSuiteName) && testsLength < 1,
)
: suitesArray;
}

finishSuites.forEach(([key, { id, status, logs }]) => {
suitesToFinish.forEach(([key, { id, status, logs }]) => {
if (logs) {
logs.map((log) => {
this.sendLog(id, log);
Expand All @@ -256,7 +256,7 @@ export class RPReporter implements Reporter {
}

onBegin(): void {
const { launch, description, attributes, skippedIssue, rerun, rerunOf } = this.config;
const { launch, description, attributes, skippedIssue, rerun, rerunOf, mode } = this.config;
const systemAttributes: Attribute[] = getSystemAttributes(skippedIssue);

const startLaunchObj: StartLaunchObjType = {
Expand All @@ -267,14 +267,15 @@ export class RPReporter implements Reporter {
attributes && attributes.length ? attributes.concat(systemAttributes) : systemAttributes,
rerun,
rerunOf,
mode: mode || LAUNCH_MODES.DEFAULT,
};
const { tempId, promise } = this.client.startLaunch(startLaunchObj);
this.addRequestToPromisesQueue(promise, 'Failed to launch run.');
this.launchId = tempId;
}

findTestItem(testItems: Map<string, TestItem>, title: string, projectName?: string): Suite {
if (projectName) {
if (projectName !== undefined) {
for (const [, value] of testItems) {
if (value.name === title && projectName === value.playwrightProjectName) {
return value;
Expand Down Expand Up @@ -388,15 +389,20 @@ export class RPReporter implements Reporter {
const { includeTestSteps } = this.config;
if (!includeTestSteps) return;
const playwrightProjectName = test.parent.project().name;
const testItem = this.findTestItem(this.testItems, test.title, playwrightProjectName);
if (!testItem) return;
let parent;
if (step.parent) {
parent = this.findTestItem(this.nestedSteps, step.parent.title, playwrightProjectName);
} else {
parent = this.findTestItem(this.testItems, test.title, playwrightProjectName);
}
if (!parent) return;
const stepStartObj = {
name: step.title,
type: TEST_ITEM_TYPES.STEP,
hasStats: false,
startTime: this.client.helpers.now(),
};
const { tempId, promise } = this.client.startTestItem(stepStartObj, this.launchId, testItem.id);
const { tempId, promise } = this.client.startTestItem(stepStartObj, this.launchId, parent.id);

this.addRequestToPromisesQueue(promise, 'Failed to start nested step.');

Expand Down Expand Up @@ -472,31 +478,33 @@ export class RPReporter implements Reporter {
this.addRequestToPromisesQueue(promise, 'Failed to finish test.');
this.testItems.delete(testItemId);

const fullSuiteName = getCodeRef(test, test.parent.title);
const parentSuiteObj = this.suites.get(fullSuiteName);
const rootSuiteName = parentSuiteObj.rootSuite;
const fullParentName = getCodeRef(test, test.parent.title);
const parentObj = this.suites.get(fullParentName);
const rootSuiteName = parentObj.rootSuite;
const rootSuite = this.suites.get(rootSuiteName);

const decreaseIndex = test.retries > 0 && result.status === 'passed' ? test.retries + 1 : 1;
const decreaseIndex =
test.retries > 0 && result.status === STATUSES.PASSED ? test.retries + 1 : 1;

this.suites.set(rootSuiteName, {
...rootSuite,
rootSuiteLength: rootSuite.rootSuiteLength - decreaseIndex,
});

const testfilePath = getTestFilePath(test, test.title);
const testFilePath = getTestFilePath(test, test.title);

Array.from(this.suites)
.filter(([key]) => key.includes(testfilePath))
.filter(([key]) => key.includes(testFilePath))
.map(([key, { testsLength }]) => {
this.suites.set(key, {
...this.suites.get(key),
testsLength: testsLength - decreaseIndex,
});
});

if (this.suites.get(fullSuiteName).testsLength < 1) {
this.finishSuites(testfilePath, rootSuiteName);
// if all children of the test parent have already finished, then finish the parent
if (this.suites.get(fullParentName).testsLength < 1) {
this.finishSuites(testFilePath, rootSuiteName);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 EPAM Systems
* Copyright 2022 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 Down Expand Up @@ -122,7 +122,7 @@ export const isErrorLog = (message: string): boolean => {
return message.toLowerCase().includes('error');
};

// https://playwright.dev/docs/1.17/api/class-testresult#test-result-status
// https://playwright.dev/docs/api/class-testresult#test-result-status
export const convertToRpStatus = (status: TestStatus): string => {
const isRpStatus = Object.values(STATUSES).includes(<STATUSES>status);

Expand Down

0 comments on commit a08f71c

Please sign in to comment.