From 5da0a09cb29b2cece20073e49f734f389c7900d2 Mon Sep 17 00:00:00 2001 From: Aleksandr Zyabrev Date: Mon, 16 May 2022 01:17:31 +0300 Subject: [PATCH 1/3] EPMRPP-76809 || Same filename catch error --- src/reporter.ts | 8 ++++---- src/utils.ts | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/reporter.ts b/src/reporter.ts index 00a3933..ed102cb 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -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 { @@ -480,10 +480,10 @@ export class RPReporter implements Reporter { rootSuiteLength: rootSuite.rootSuiteLength - 1, }); - 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), @@ -492,7 +492,7 @@ export class RPReporter implements Reporter { }); if (this.suites.get(fullSuiteName).testsLength === 0) { - this.finishSuites(testFileName, rootSuiteName); + this.finishSuites(testfilePath, rootSuiteName); } } diff --git a/src/utils.ts b/src/utils.ts index 84778d7..d46968f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 })); }; From a1ae080b5890c464a31f1b5e16ec5c0ad53adcd3 Mon Sep 17 00:00:00 2001 From: Aleksandr Zyabrev Date: Mon, 16 May 2022 14:35:48 +0300 Subject: [PATCH 2/3] EPMRPP-76809 || Fix retry error --- CHANGELOG.md | 4 ++++ src/__tests__/reporter/finishTestItemReporting.spec.ts | 2 +- src/reporter.ts | 10 ++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cf5332..a18cbc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/__tests__/reporter/finishTestItemReporting.spec.ts b/src/__tests__/reporter/finishTestItemReporting.spec.ts index b55eefa..b8d7a83 100644 --- a/src/__tests__/reporter/finishTestItemReporting.spec.ts +++ b/src/__tests__/reporter/finishTestItemReporting.spec.ts @@ -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, diff --git a/src/reporter.ts b/src/reporter.ts index ed102cb..8106d0d 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -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 @@ -475,9 +475,11 @@ 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 testfilePath = getTestFilePath(test, test.title); @@ -487,11 +489,11 @@ export class RPReporter implements Reporter { .map(([key, { testsLength }]) => { this.suites.set(key, { ...this.suites.get(key), - testsLength: testsLength - 1, + testsLength: testsLength - decreaseIndex, }); }); - if (this.suites.get(fullSuiteName).testsLength === 0) { + if (this.suites.get(fullSuiteName).testsLength < 1) { this.finishSuites(testfilePath, rootSuiteName); } } From e8a21089e1649175d8ab4f2fa5b32f5adab27f25 Mon Sep 17 00:00:00 2001 From: Aleksandr Zyabrev Date: Mon, 16 May 2022 18:43:39 +0300 Subject: [PATCH 3/3] EPMRPP-76809 || code review fixes - 1 --- src/__tests__/utils.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/__tests__/utils.spec.ts b/src/__tests__/utils.spec.ts index 0d809ca..0c75f85 100644 --- a/src/__tests__/utils.spec.ts +++ b/src/__tests__/utils.spec.ts @@ -27,6 +27,7 @@ import { getAttachments, isErrorLog, convertToRpStatus, + getTestFilePath, } from '../utils'; import fs from 'fs'; import path from 'path'; @@ -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); + }); + }); });