Skip to content

Commit

Permalink
refactor: use grep & grepInvert from pw config
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelrhman-arnos committed Feb 6, 2024
1 parent 54a75a8 commit dc62061
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 39 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const RPconfig = {
},
],
description: 'Your launch description',
grep: 'fast', // to run only tests with 'fast' tag in the title
grepInvert: 'fast', // to exclude tests with 'fast' tag in the title
};

const config: PlaywrightTestConfig = {
Expand Down
33 changes: 33 additions & 0 deletions src/__tests__/reporter/startSuiteTestReporting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { RPClientMock } from '../mocks/RPClientMock';
import { StartTestObjType } from '../../models';
import { TEST_ITEM_TYPES } from '../../constants';
import path from 'path';
import { TestCase } from '@playwright/test/reporter';

const rootSuite = 'tests/example.js';
const suiteName = 'suiteName';
Expand Down Expand Up @@ -158,4 +159,36 @@ describe('start reporting suite/test', () => {
expect(reporter.suites).toEqual(new Map());
expect(reporter.testItems).toEqual(new Map());
});

test('@smoke has one tag at the beginning', () => {
const testId = 'testItemId';
const testTitle = 'testTitle';
const attributes = [{ value: 'smoke' }];
const simpleTestCase = <TestCase>{
id: testId,
title: testTitle,
titlePath: () => [rootSuite, suiteName, testTitle],
};

reporter.onTestBegin(simpleTestCase);
expect(reporter.testItems).toEqual(
new Map([[testId, { id: 'tempTestItemId', name: testTitle, attributes }]]),
);
});

test('has one tag at the end @manual', () => {
const testId = 'testItemId';
const testTitle = 'testTitle';
const attributes = [{ value: 'manual' }];
const simpleTestCase = <TestCase>{
id: testId,
title: testTitle,
titlePath: () => [rootSuite, suiteName, testTitle],
};

reporter.onTestBegin(simpleTestCase);
expect(reporter.testItems).toEqual(
new Map([[testId, { id: 'tempTestItemId', name: testTitle, attributes }]]),
);
});
});
2 changes: 0 additions & 2 deletions src/models/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,4 @@ export interface ReportPortalConfig extends ClientConfig, AttachmentsConfig {
includeTestSteps?: boolean;
includePlaywrightProjectNameToCodeReference?: boolean;
extendTestDescriptionWithLastError?: boolean;
grep?: string;
grepInvert?: string;
}
19 changes: 13 additions & 6 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

import RPClient from '@reportportal/client-javascript';
import stripAnsi from 'strip-ansi';
import { Reporter, Suite as PWSuite, TestCase, TestResult } from '@playwright/test/reporter';
import {
Reporter,
Suite as PWSuite,
TestCase,
TestResult,
FullConfig,
} from '@playwright/test/reporter';
import {
Attribute,
FinishTestItemObjType,
Expand Down Expand Up @@ -266,7 +272,7 @@ export class RPReporter implements Reporter {
});
}

onBegin(): void {
onBegin(config?: FullConfig): void {
const { launch, description, attributes, skippedIssue, rerun, rerunOf, mode, launchId } =
this.config;
const systemAttributes: Attribute[] = getSystemAttributes(skippedIssue);
Expand All @@ -284,11 +290,12 @@ export class RPReporter implements Reporter {
};

// Extract grep and grepInvert from config and add as launch attributes
if (this.config.grep) {
startLaunchObj.attributes.push({ key: 'grep', value: this.config.grep });
if (config?.grep) {
startLaunchObj.attributes.push({ key: 'grep', value: config.grep.toString() });
}
if (this.config.grepInvert) {
startLaunchObj.attributes.push({ key: 'grepInvert', value: this.config.grepInvert });

if (config?.grepInvert) {
startLaunchObj.attributes.push({ key: 'grepInvert', value: config.grepInvert.toString() });
}

const { tempId, promise } = this.client.startLaunch(startLaunchObj);
Expand Down
29 changes: 0 additions & 29 deletions tests/example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,3 @@ test('get started link', async ({ page }) => {
// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});

test('has one tag at the end @single', async ({ page }) => {
ReportingApi.addAttributes([
{
value: 'single',
},
]);

await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});

test('@single has one tag at the beginning', async ({ page }) => {
ReportingApi.addAttributes([
{
value: 'single',
},
]);

await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});

test('has no tag', async ({ page }) => {
ReportingApi.addAttributes([]);

await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});

0 comments on commit dc62061

Please sign in to comment.