Skip to content

Commit

Permalink
Merge pull request #107 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.1.1
  • Loading branch information
AmsterGet authored Jun 13, 2023
2 parents cc2533e + 31396d1 commit 8a77184
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Fixed
- Nested steps and launch finishing when `includeTestSteps: true`. Addressed [#76](https://github.com/reportportal/agent-js-playwright/issues/76), [#97](https://github.com/reportportal/agent-js-playwright/issues/97).

## [5.1.0] - 2023-06-05
### Added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.0
5.1.1-SNAPSHOT
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
2 changes: 1 addition & 1 deletion version_fragment
Original file line number Diff line number Diff line change
@@ -1 +1 @@
minor
patch

0 comments on commit 8a77184

Please sign in to comment.