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/VERSION b/VERSION index 50e2274..c880334 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.0.3 +5.0.4-SNAPSHOT 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/__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); + }); + }); }); diff --git a/src/reporter.ts b/src/reporter.ts index 00a3933..7b4fd91 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 { @@ -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 @@ -388,14 +388,15 @@ export class RPReporter implements Reporter { const { includeTestSteps } = this.config; if (!includeTestSteps) return; const playwrightProjectName = test.parent.project().name; - const { id: testItemId } = this.findTestItem(this.testItems, test.title, playwrightProjectName); + const testItem = this.findTestItem(this.testItems, test.title, playwrightProjectName); + if (!testItem) 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, testItemId); + const { tempId, promise } = this.client.startTestItem(stepStartObj, this.launchId, testItem.id); this.addRequestToPromisesQueue(promise, 'Failed to start nested step.'); @@ -410,16 +411,17 @@ export class RPReporter implements Reporter { const { includeTestSteps } = this.config; if (!includeTestSteps) return; const playwrightProjectName = test.parent.project().name; - const { id } = this.findTestItem(this.nestedSteps, step.title, playwrightProjectName); + const testItem = this.findTestItem(this.nestedSteps, step.title, playwrightProjectName); + if (!testItem) return; const stepFinishObj = { status: step.error ? STATUSES.FAILED : STATUSES.PASSED, endTime: this.client.helpers.now(), }; - const { promise } = this.client.finishTestItem(id, stepFinishObj); + const { promise } = this.client.finishTestItem(testItem.id, stepFinishObj); this.addRequestToPromisesQueue(promise, 'Failed to finish nested step.'); - this.nestedSteps.delete(id); + this.nestedSteps.delete(testItem.id); } async onTestEnd(test: TestCase, result: TestResult): Promise { @@ -475,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); } } 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 })); };