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:
parent
a678561cda
commit
425f737eb6
|
|
@ -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]>
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
7
packages/playwright/types/test.d.ts
vendored
7
packages/playwright/types/test.d.ts
vendored
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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'}],
|
||||
});
|
||||
`;
|
||||
`;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue