Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: don't parse file names for tags (#38949)
Yury Semikhatsky5f72237a03ba
diff --git a/packages/playwright/src/common/test.ts b/packages/playwright/src/common/test.tsindex dce6cbcd83..fa8d8c2003 100644--- a/packages/playwright/src/common/test.ts+++ b/packages/playwright/src/common/test.ts@@ -142,6 +142,16 @@ export class Suite extends Base {path.push(...this._tags);}+ _collectTagTitlePath(path: string[]) {+ this.parent?._collectTagTitlePath(path);+ // Only collect titles from describe blocks for tag extraction.+ // Skip root/project/file titles to avoid parsing file names as tags.+ // Note that file suite may have explicit global tags as well.+ if (this._type === 'describe')+ path.push(this.title);+ path.push(...this._tags);+ }+_getOnlyItems(): (TestCase | Suite)[] {const items: (TestCase | Suite)[] = [];if (this._only)@@ -289,8 +299,10 @@ export class TestCase extends Base implements reporterTypes.TestCase {}get tags(): string[] {- const titleTags = this._grepBaseTitlePath().join(' ').match(/@[\S]+/g) || [];-+ const path: string[] = [];+ this.parent._collectTagTitlePath(path);+ path.push(this.title);+ const titleTags = path.join(' ').match(/@[\S]+/g) || [];return [...titleTags,...this._tags,diff --git a/tests/playwright-test/test-tag.spec.ts b/tests/playwright-test/test-tag.spec.tsindex 1ed8a9da55..31cc1371b4 100644--- a/tests/playwright-test/test-tag.spec.ts+++ b/tests/playwright-test/test-tag.spec.ts@@ -182,3 +182,48 @@ test('should be included in testInfo if coming from describe or global tag', asy});expect(result.exitCode).toBe(0);});++test('should not parse file names as tags', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'reporter.ts': `+ export default class Reporter {+ onBegin(config, suite) {+ const visit = suite => {+ for (const test of suite.tests || [])+ console.log('\\n%%title=' + test.title + ', tags=' + test.tags.join(','));+ for (const child of suite.suites || [])+ visit(child);+ };+ visit(suite);+ }+ onError(error) {+ console.log(error);+ }+ }+ `,+ 'playwright.config.ts': `+ module.exports = {+ reporter: './reporter',+ };+ `,+ '@sample.test.ts': `+ import { test, expect } from '@playwright/test';+ test('test in file', () => {+ });+ test('test with tag @inline', { tag: '@foo' }, () => {+ });+ `,+ 'dir/@nested/regular.test.ts': `+ import { test, expect } from '@playwright/test';+ test('test in nested dir', () => {+ });+ `,+ });+ expect(result.exitCode).toBe(0);+ // File names should NOT be parsed as tags, only inline tags in describe/test titles+ expect(result.outputLines).toEqual([+ `title=test in file, tags=`,+ `title=test with tag @inline, tags=@inline,@foo`,+ `title=test in nested dir, tags=`,+ ]);+});