diff --git a/README.md b/README.md index dd9ee21..b568488 100644 --- a/README.md +++ b/README.md @@ -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 = { diff --git a/src/__tests__/reporter/startSuiteTestReporting.spec.ts b/src/__tests__/reporter/startSuiteTestReporting.spec.ts index 76d02bb..76e99d5 100644 --- a/src/__tests__/reporter/startSuiteTestReporting.spec.ts +++ b/src/__tests__/reporter/startSuiteTestReporting.spec.ts @@ -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'; @@ -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 = { + 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 = { + id: testId, + title: testTitle, + titlePath: () => [rootSuite, suiteName, testTitle], + }; + + reporter.onTestBegin(simpleTestCase); + expect(reporter.testItems).toEqual( + new Map([[testId, { id: 'tempTestItemId', name: testTitle, attributes }]]), + ); + }); }); diff --git a/src/models/configs.ts b/src/models/configs.ts index 379cec5..7c7066a 100644 --- a/src/models/configs.ts +++ b/src/models/configs.ts @@ -56,6 +56,4 @@ export interface ReportPortalConfig extends ClientConfig, AttachmentsConfig { includeTestSteps?: boolean; includePlaywrightProjectNameToCodeReference?: boolean; extendTestDescriptionWithLastError?: boolean; - grep?: string; - grepInvert?: string; } diff --git a/src/reporter.ts b/src/reporter.ts index 749e6b2..0d8052a 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -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, @@ -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); @@ -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); diff --git a/tests/example.spec.js b/tests/example.spec.js index 99853e1..8da530e 100644 --- a/tests/example.spec.js +++ b/tests/example.spec.js @@ -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/); -}); \ No newline at end of file