Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 5.0.4 #49

Merged
merged 4 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.3
5.0.4-SNAPSHOT
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);
});
});
});
30 changes: 17 additions & 13 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 @@ -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.');

Expand All @@ -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<void> {
Expand Down Expand Up @@ -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);
}
}

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