From 9d94ad152e5687afabaaa07f0a14808f8de56d38 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 5 Nov 2024 16:18:10 -0800 Subject: [PATCH] chore: dedupe tags in base reporter title (#33461) --- packages/playwright/src/reporters/base.ts | 5 +++-- tests/playwright-test/reporter-base.spec.ts | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/playwright/src/reporters/base.ts b/packages/playwright/src/reporters/base.ts index 3e452d6c44..9317e4e1bc 100644 --- a/packages/playwright/src/reporters/base.ts +++ b/packages/playwright/src/reporters/base.ts @@ -383,8 +383,9 @@ export function formatTestTitle(config: FullConfig, test: TestCase, step?: TestS else location = `${relativeTestPath(config, test)}:${step?.location?.line ?? test.location.line}:${step?.location?.column ?? test.location.column}`; const projectTitle = projectName ? `[${projectName}] › ` : ''; - const tags = test.tags.length > 0 ? ` ${test.tags.join(' ')}` : ''; - return `${projectTitle}${location} › ${titles.join(' › ')}${stepSuffix(step)}${tags}`; + const testTitle = `${projectTitle}${location} › ${titles.join(' › ')}`; + const extraTags = test.tags.filter(t => !testTitle.includes(t)); + return `${testTitle}${stepSuffix(step)}${extraTags.length ? ' ' + extraTags.join(' ') : ''}`; } export function formatTestHeader(config: FullConfig, test: TestCase, options: { indent?: string, index?: number, mode?: 'default' | 'error' } = {}): string { diff --git a/tests/playwright-test/reporter-base.spec.ts b/tests/playwright-test/reporter-base.spec.ts index 780739eb83..3e398f9160 100644 --- a/tests/playwright-test/reporter-base.spec.ts +++ b/tests/playwright-test/reporter-base.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { test, expect } from './playwright-test-fixtures'; +import { test, expect, stripAnsi } from './playwright-test-fixtures'; import * as path from 'path'; for (const useIntermediateMergeReport of [false, true] as const) { @@ -470,14 +470,21 @@ for (const useIntermediateMergeReport of [false, true] as const) { const result = await runInlineTest({ 'a.test.ts': ` const { test, expect } = require('@playwright/test'); - test('passes', { tag: ['@foo', '@bar'] }, async ({}) => { + test('passes', { tag: ['@foo1', '@foo2'] }, async ({}) => { + expect(0).toBe(0); + }); + test('passes @bar1 @bar2', async ({}) => { + expect(0).toBe(0); + }); + test('passes @baz1', { tag: ['@baz2'] }, async ({}) => { expect(0).toBe(0); }); `, }); - const text = result.output; - - expect(text).toContain('passes @foo @bar'); + const text = stripAnsi(result.output); + expect(text).toContain('› passes @foo1 @foo2 ('); + expect(text).toContain('› passes @bar1 @bar2 ('); + expect(text).toContain('› passes @baz1 @baz2 ('); }); }); }