Skip to content
Merged
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
16 changes: 14 additions & 2 deletions packages/playwright/src/common/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
45 changes: 45 additions & 0 deletions tests/playwright-test/test-tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=`,
]);
});
Loading