Skip to content

Commit

Permalink
EPMRPP-76809 || Same filename error (#48)
Browse files Browse the repository at this point in the history
* EPMRPP-76809 || Same filename catch error

* EPMRPP-76809 || Fix retry error

* EPMRPP-76809 || code review fixes - 1

Co-authored-by: Aleksandr Zyabrev <[email protected]>
  • Loading branch information
renkyoji and Aleksandr Zyabrev authored May 17, 2022
1 parent 9a4b940 commit 0db4de9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Fixed
- [#42](https://github.com/reportportal/agent-js-playwright/issues/42) Error when using same filenames
- Error is related to retries due to which the launch is not finish
- [#45](https://github.com/reportportal/agent-js-playwright/issues/45) Agent failed when enabled includeTestSteps

## [5.0.3] - 2022-04-04
### Added
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/reporter/finishTestItemReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('finish test reporting', () => {
// @ts-ignore
await reporter.onTestEnd(testParams, result);

expect(reporter.client.finishTestItem).toHaveBeenCalledTimes(1);
expect(reporter.client.finishTestItem).toHaveBeenCalledTimes(3);
expect(reporter.client.finishTestItem).toHaveBeenCalledWith(
'tempTestItemId',
finishTestItemObj,
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getAttachments,
isErrorLog,
convertToRpStatus,
getTestFilePath,
} from '../utils';
import fs from 'fs';
import path from 'path';
Expand Down Expand Up @@ -286,4 +287,21 @@ describe('testing utils', () => {
expect(status).not.toBe(STATUSES.FAILED);
});
});
describe('getTestFilePath', () => {
test('getTestFilePath should return test file path string', () => {
const mockedTest = {
title: 'first',
location: {
file: `C:${path.sep}project${path.sep}tests${path.sep}simpleTest.spec.ts`,
},
titlePath: () => ['', 'project', 'tests/simpleTest.spec.ts', 'first'],
};

// @ts-ignore
const receivedValue = getTestFilePath(mockedTest, mockedTest.title);
const expectedValue = 'project/tests/simpleTest.spec.ts';

expect(receivedValue).toBe(expectedValue);
});
});
});
18 changes: 10 additions & 8 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ import {
getAttachments,
getCodeRef,
getSystemAttributes,
getTestFilePath,
isErrorLog,
isFalse,
promiseErrorHandler,
} from './utils';
import path from 'path';
import { EVENTS } from '@reportportal/client-javascript/lib/constants/events';

export interface TestItem {
Expand Down Expand Up @@ -224,7 +224,7 @@ export class RPReporter implements Reporter {
let finishSuites: [string, Suite][];
const suitesArray = Array.from(this.suites);

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

if (isExistTestsInRootSuite) {
finishSuites = testFileName
Expand Down Expand Up @@ -477,24 +477,26 @@ export class RPReporter implements Reporter {
const rootSuiteName = parentSuiteObj.rootSuite;
const rootSuite = this.suites.get(rootSuiteName);

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

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

const testFileName = path.parse(test.location.file).base;
const testfilePath = getTestFilePath(test, test.title);

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

if (this.suites.get(fullSuiteName).testsLength === 0) {
this.finishSuites(testFileName, rootSuiteName);
if (this.suites.get(fullSuiteName).testsLength < 1) {
this.finishSuites(testfilePath, rootSuiteName);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ export const getCodeRef = (
.replace(new RegExp('\\'.concat(path.sep), 'g'), '/');
};

export const getTestFilePath = (testItem: testItemPick, itemTitle: string): string => {
const codeRefArray = getCodeRef(testItem, itemTitle).split('/');
const testFileName = path.parse(testItem.location.file).base;
const testFileNameIndex = codeRefArray.indexOf(testFileName);
return codeRefArray.slice(0, testFileNameIndex + 1).join('/');
};

export const sendEventToReporter = (type: string, data: any, suite?: string): void => {
process.stdout.write(JSON.stringify({ type, data, suite }));
};
Expand Down

0 comments on commit 0db4de9

Please sign in to comment.