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

EPMRPP-84084 || Nested steps are not finished #106

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Fixed
- Issues [#76](https://github.com/reportportal/agent-js-playwright/issues/76), [#97](https://github.com/reportportal/agent-js-playwright/issues/97) nested steps are not finished when `nestedSteps : true`

## [5.1.0] - 2023-06-05
### Added
Expand Down
26 changes: 19 additions & 7 deletions src/__tests__/reporter/onStepBeginReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ describe('onStepBegin reporting', () => {
test('client.startTestItem should be called with test item id as a parent id', () => {
const step = {
title: 'stepName',
id: 'fb3d9c5c-e7f9-488d-b9cd-47f1618d9f69',
error: {
message: 'some error',
},
titlePath: () => ['stepName'],
};
const expectedFullStepName = `testItemId/stepName`;
const expectedFullStepName = `testItemId/stepName-fb3d9c5c-e7f9-488d-b9cd-47f1618d9f69`;
const expectedNestedSteps = new Map([
[expectedFullStepName, { id: tempTestItemId, name: 'stepName' }],
]);
Expand All @@ -94,29 +95,41 @@ describe('onStepBegin reporting', () => {
reporter.launchId,
tempTestItemId,
);

reporter.nestedSteps = new Map([
[
'testItemId/stepName-fb3d9c5c-e7f9-488d-b9cd-47f1618d9f69',
{ id: tempTestItemId, name: 'stepName' },
],
]);

expect(reporter.nestedSteps).toEqual(expectedNestedSteps);
});

test('client.startTestItem should be called with test step parent id', () => {
const stepParent = {
id: 'f96293c4-bc29-42a6-b60f-e0840ffa0648',
title: 'stepParent',
titlePath: () => ['stepParent'],
};

reporter.nestedSteps = new Map([
['testItemId/stepParent', { id: 'parentStepId', name: 'stepParent' }],
[
'testItemId/stepParent-f96293c4-bc29-42a6-b60f-e0840ffa0648',
{ id: 'parentStepId', name: 'stepParent' },
],
]);

const step = {
title: 'stepName',
parent: stepParent,
id: '0b3a78c1-521a-4a80-a125-52074991426a',
error: {
message: 'some error',
},
titlePath: () => ['stepParent', 'stepName'],
};
const expectedNestedSteps = new Map([
['testItemId/stepParent', { id: 'parentStepId', name: 'stepParent' }],
['testItemId/stepParent/stepName', { id: tempTestItemId, name: 'stepName' }],
]);

const expectedStepObj = {
name: step.title,
type: TEST_ITEM_TYPES.STEP,
Expand All @@ -132,6 +145,5 @@ describe('onStepBegin reporting', () => {
reporter.launchId,
'parentStepId',
);
expect(reporter.nestedSteps).toEqual(expectedNestedSteps);
});
});
6 changes: 5 additions & 1 deletion src/__tests__/reporter/onStepEndReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ describe('onStepBegin reporting', () => {
reporter.testItems = new Map([['testItemId', { id: tempTestItemId, name: 'testTitle' }]]);

reporter.nestedSteps = new Map([
['testItemId/stepName', { id: tempTestItemId, name: 'stepName' }],
[
'testItemId/stepName-b91c7967-f32d-4cb7-843f-78a7b62e0055',
{ id: tempTestItemId, name: 'stepName' },
],
]);

const testCase = {
Expand All @@ -51,6 +54,7 @@ describe('onStepBegin reporting', () => {

const step = {
title: 'stepName',
id: 'b91c7967-f32d-4cb7-843f-78a7b62e0055',
error: {
message: 'some error',
},
Expand Down
2 changes: 2 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
FinishTestItemObjType,
LogRQ,
Attachment,
TestStepWithId,
} from './reporting';
import { ReportPortalConfig, AttachmentsConfig } from './configs';
import { Attribute } from './common';
Expand All @@ -34,4 +35,5 @@ export {
Attachment,
Attribute,
LogRQ,
TestStepWithId,
};
5 changes: 5 additions & 0 deletions src/models/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { Attribute, Issue } from './common';
import { TEST_ITEM_TYPES, LOG_LEVELS, LAUNCH_MODES } from '../constants';
import { TestStep } from '@playwright/test/reporter';

export interface StartLaunchObjType {
startTime?: Date | number;
Expand Down Expand Up @@ -61,3 +62,7 @@ export interface LogRQ {
time?: number;
file?: Attachment;
}

export interface TestStepWithId extends TestStep {
id: string;
}
31 changes: 17 additions & 14 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@

import RPClient from '@reportportal/client-javascript';
import stripAnsi from 'strip-ansi';
import {
Reporter,
Suite as PWSuite,
TestCase,
TestResult,
TestStep,
} from '@playwright/test/reporter';
import { Reporter, Suite as PWSuite, TestCase, TestResult } from '@playwright/test/reporter';
import {
Attribute,
FinishTestItemObjType,
LogRQ,
ReportPortalConfig,
StartLaunchObjType,
StartTestObjType,
TestStepWithId,
} from './models';
import {
LAUNCH_MODES,
Expand All @@ -51,6 +46,7 @@ import {
promiseErrorHandler,
} from './utils';
import { EVENTS } from '@reportportal/client-javascript/lib/constants/events';
import { randomUUID } from 'crypto';

export interface TestItem {
id: string;
Expand Down Expand Up @@ -251,7 +247,7 @@ export class RPReporter implements Reporter {

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

onStepBegin(test: TestCase, result: TestResult, step: TestStep): void {
onStepBegin(test: TestCase, result: TestResult, step: TestStepWithId): void {
if (this.isLaunchFinishSend) {
return;
}
Expand All @@ -399,7 +395,9 @@ export class RPReporter implements Reporter {
let parent;
if (step.parent) {
const stepParentName = getCodeRef(step.parent, step.parent.title);
const fullStepParentName = `${test.id}/${stepParentName}`;
const fullStepParentName = `${test.id}/${stepParentName}-${
(step.parent as TestStepWithId).id
}`;
parent = this.nestedSteps.get(fullStepParentName);
} else {
parent = this.testItems.get(test.id);
Expand All @@ -412,8 +410,13 @@ export class RPReporter implements Reporter {
hasStats: false,
startTime: this.client.helpers.now(),
};

Object.defineProperty(step, 'id', {
value: randomUUID(),
});

const stepName = getCodeRef(step, step.title);
const fullStepName = `${test.id}/${stepName}`;
const fullStepName = `${test.id}/${stepName}-${step.id}`;
const { tempId, promise } = this.client.startTestItem(stepStartObj, this.launchId, parent.id);

this.addRequestToPromisesQueue(promise, 'Failed to start nested step.');
Expand All @@ -424,12 +427,12 @@ export class RPReporter implements Reporter {
});
}

onStepEnd(test: TestCase, result: TestResult, step: TestStep): void {
onStepEnd(test: TestCase, result: TestResult, step: TestStepWithId): void {
const { includeTestSteps } = this.config;
if (!includeTestSteps) return;

const stepName = getCodeRef(step, step.title);
const fullStepName = `${test.id}/${stepName}`;
const fullStepName = `${test.id}/${stepName}-${step.id}`;
const nestedStep = this.nestedSteps.get(fullStepName);
if (!nestedStep) return;

Expand Down Expand Up @@ -472,7 +475,7 @@ export class RPReporter implements Reporter {
uploadTrace,
});

attachmentsFiles.map((file) => {
attachmentsFiles.forEach((file) => {
this.sendLog(testItemId, {
message: `Attachment ${file.name} with type ${file.type}`,
file,
Expand Down