feat: exposes tags in testInfo (#29794)

Fixes #29793.

---------

Signed-off-by: Lukas Bockstaller <lukas.bockstaller@everest-erp.com>
Co-authored-by: Dmitry Gozman <dgozman@gmail.com>
This commit is contained in:
Lukas Bockstaller 2024-03-06 17:33:06 +01:00 committed by GitHub
parent a678561cda
commit 425f737eb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 49 additions and 3 deletions

View file

@ -210,6 +210,14 @@ Optional description that will be reflected in a test report.
Test function as passed to `test(title, testFunction)`.
## property: TestInfo.tags
* since: v1.43
- type: <[Array]<[string]>>
Tags that apply to the test. Learn more about [tags](../test-annotations.md#tag-tests).
Note that any changes made to this list while the test is running will not be visible to test reporters.
## property: TestInfo.testId
* since: v1.32
- type: <[string]>

View file

@ -92,6 +92,7 @@ export class TestInfoImpl implements TestInfo {
readonly titlePath: string[];
readonly file: string;
readonly line: number;
readonly tags: string[];
readonly column: number;
readonly fn: Function;
expectedStatus: TestStatus;
@ -167,6 +168,7 @@ export class TestInfoImpl implements TestInfo {
this.file = test?.location.file ?? '';
this.line = test?.location.line ?? 0;
this.column = test?.location.column ?? 0;
this.tags = test?.tags ?? [];
this.fn = test?.fn ?? (() => {});
this.expectedStatus = test?.expectedStatus ?? 'skipped';

View file

@ -2312,6 +2312,13 @@ export interface TestInfo {
*/
status?: "passed"|"failed"|"timedOut"|"skipped"|"interrupted";
/**
* Tags that apply to the test. Learn more about [tags](https://playwright.dev/docs/test-annotations#tag-tests).
*
* Note that any changes made to this list while the test is running will not be visible to test reporters.
*/
tags: Array<string>;
/**
* Test id matching the test case id in the reporter API.
*/

View file

@ -254,8 +254,8 @@ type Fixtures = {
};
export const test = base
.extend<CommonFixtures, CommonWorkerFixtures>(commonFixtures)
.extend<ServerFixtures, ServerWorkerOptions>(serverFixtures)
.extend<CommonFixtures, CommonWorkerFixtures>(commonFixtures as any)
.extend<ServerFixtures, ServerWorkerOptions>(serverFixtures as any)
.extend<Fixtures>({
writeFiles: async ({}, use, testInfo) => {
await use(files => writeFiles(testInfo, files, false));
@ -455,4 +455,4 @@ export default defineConfig({
},
projects: [{name: 'default'}],
});
`;
`;

View file

@ -146,3 +146,32 @@ test('should enforce @ symbol', async ({ runInlineTest }) => {
expect(result.exitCode).toBe(1);
expect(result.output).toContain(`Error: Tag must start with "@" symbol, got "foo" instead.`);
});
test('should be included in testInfo', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('test without tag', async ({}, testInfo) => {
expect(testInfo.tags).toStrictEqual([]);
});
test('test with tag',{ tag: '@tag1' }, async ({}, testInfo) => {
expect(testInfo.tags).toStrictEqual(["@tag1"]);
});
`,
});
expect(result.exitCode).toBe(0);
});
test('should be included in testInfo if comming from describe', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'a.test.ts': `
import { test, expect } from '@playwright/test';
test.describe('describe with tag', { tag: '@tag2' }, async ()=>{
test('test with tag', async ({}, testInfo) => {
expect(testInfo.tags).toStrictEqual(["@tag2"]);
});
});
`,
});
expect(result.exitCode).toBe(0);
});