Skip to content
Open
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
9 changes: 6 additions & 3 deletions src/__tests__/mocks/RPClientMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ export const mockedDate = Date.now();
export class RPClientMock {
private config: ReportPortalConfig;

constructor(config: ReportPortalConfig) {
this.config = config;
}
constructor(config?: ReportPortalConfig) {
this.config = config || ({} as ReportPortalConfig);

public startLaunch = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
Expand All @@ -35,6 +34,10 @@ export class RPClientMock {
promise: Promise.resolve('ok'),
});

public updateLaunch = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
});

public startTestItem = jest.fn().mockReturnValue({
promise: Promise.resolve('ok'),
tempId: 'tempTestItemId',
Expand Down
11 changes: 9 additions & 2 deletions src/__tests__/reporter/finishSuiteReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
import helpers from '@reportportal/client-javascript/lib/helpers';
import { RPReporter } from '../../reporter';
import { mockConfig } from '../mocks/configMock';
import { RPClientMock, mockedDate } from '../mocks/RPClientMock';

Check failure on line 20 in src/__tests__/reporter/finishSuiteReporting.spec.ts

View workflow job for this annotation

GitHub Actions / test

Parse errors in imported module '../mocks/RPClientMock': Declaration or statement expected. (28:2)
import path from 'path';

const rootSuite = 'rootSuite';
const suiteName = 'example.js';

// Mock object for Playwright FullResult type
const mockFullResult = {
status: 'passed' as const,
startTime: new Date('2021-05-18T12:00:00.000Z'),
duration: 1000,
};

// TODO: add tests for skipped status and different workerIndex values
// TODO: add tests for serial mode
describe('finish suites on finish all of their children', () => {
Expand Down Expand Up @@ -117,7 +124,7 @@
});

test('client.finishTestItem should be called with suite id in case of run end with unfinished suites', () => {
reporter.onEnd();
reporter.onEnd(mockFullResult);

expect(spyFinishTestItem).toHaveBeenNthCalledWith(1, 'rootsuiteId', {
endTime: mockedDate,
Expand All @@ -130,7 +137,7 @@

test('client.finishTestItem should be called with suite id in case of run end without unfinished suites', () => {
reporter.suites = new Map();
reporter.onEnd();
reporter.onEnd(mockFullResult);

expect(spyFinishTestItem).toBeCalledTimes(0);
expect(reporter.suites).toEqual(new Map());
Expand Down
18 changes: 14 additions & 4 deletions src/__tests__/reporter/launchesReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@
import { LAUNCH_MODES } from '../../constants';

import { mockConfig } from '../mocks/configMock';
import { RPClientMock, mockedDate } from '../mocks/RPClientMock';

Check failure on line 25 in src/__tests__/reporter/launchesReporting.spec.ts

View workflow job for this annotation

GitHub Actions / test

Parse errors in imported module '../mocks/RPClientMock': Declaration or statement expected. (28:2)

// Mock object for Playwright FullResult type
const mockFullResult = {
status: 'passed' as const,
startTime: new Date('2021-05-18T12:00:00.000Z'),
duration: 1000,
};

describe('start launch', () => {
jest.spyOn(helpers, 'now').mockReturnValue(mockedDate);

Expand Down Expand Up @@ -145,12 +152,15 @@
reporter.client = new RPClientMock(mockConfig);
reporter.launchId = 'tempLaunchId';

beforeAll(() => reporter.onEnd());
beforeAll(() => reporter.onEnd(mockFullResult));

test('launch should be finished', () => {
expect(reporter.client.finishLaunch).toHaveBeenCalledTimes(1);
const expectedEndTime = new Date(
mockFullResult.startTime.getTime() + mockFullResult.duration,
).toISOString();
expect(reporter.client.finishLaunch).toHaveBeenCalledWith('tempLaunchId', {
endTime: mockedDate,
endTime: expectedEndTime,
});
expect(reporter.isLaunchFinishSend).toBe(true);
});
Expand All @@ -165,7 +175,7 @@
reporter.client = new RPClientMock(customConfig);
reporter.launchId = 'tempLaunchId';

beforeAll(() => reporter.onEnd());
beforeAll(() => reporter.onEnd(mockFullResult));

test('launch finish request should not be sent', () => {
expect(reporter.client.finishLaunch).toHaveBeenCalledTimes(0);
Expand All @@ -182,7 +192,7 @@
reporter.client = new RPClientMock(mockConfig);
reporter.launchId = 'tempLaunchId';

reporter.onEnd();
reporter.onEnd(mockFullResult);
});

afterAll(() => {
Expand Down
14 changes: 10 additions & 4 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
import RPClient from '@reportportal/client-javascript';
import clientHelpers from '@reportportal/client-javascript/lib/helpers';
import stripAnsi from 'strip-ansi';
import { Reporter, Suite as PWSuite, TestCase, TestResult } from '@playwright/test/reporter';
import {
Reporter,
Suite as PWSuite,
TestCase,
TestResult,
FullResult,
} from '@playwright/test/reporter';
import {
Attribute,
FinishTestItemObjType,
Expand Down Expand Up @@ -120,7 +126,7 @@
}

onEventReport(
{ type, data, suiteName }: { type: string; data: any; suiteName?: string },

Check warning on line 129 in src/reporter.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
test?: TestCase,
): void {
switch (type) {
Expand Down Expand Up @@ -645,8 +651,7 @@
});
}

async onEnd(): Promise<void> {
// Force finish unfinished suites in case of interruptions
async onEnd(result: FullResult) {
if (this.suites.size > 0) {
this.suites.forEach((value, key) => {
this.suites.set(key, {
Expand All @@ -659,8 +664,9 @@
}

if (!this.config.launchId) {
const endTime = new Date(result.startTime.getTime() + result.duration).toISOString();
const { promise } = this.client.finishLaunch(this.launchId, {
endTime: clientHelpers.now(),
endTime: endTime,
...(this.customLaunchStatus && { status: this.customLaunchStatus }),
});
this.addRequestToPromisesQueue(promise, 'Failed to finish launch.');
Expand Down
1 change: 1 addition & 0 deletions src/types/@reportportal/client-javascript/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

declare module '@reportportal/client-javascript' {
export default class {
constructor(config: any, agentInfo?: any);

Check warning on line 20 in src/types/@reportportal/client-javascript/index.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 20 in src/types/@reportportal/client-javascript/index.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

public startLaunch(launchObj: any): any;

Check warning on line 22 in src/types/@reportportal/client-javascript/index.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 22 in src/types/@reportportal/client-javascript/index.d.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
public finishLaunch(launchId: string, launchObj: any): any;
public updateLaunch(launchId: string, launchObj: any): any;
public startTestItem(itemObj: any, launchId: string, parentId?: string): any;
public finishTestItem(itemId: string, itemObj: any): any;
public sendLog(itemId: string, itemObj: any, fileObj?: any): any;
Expand Down
Loading