From 664e1f766e9eba9af7041bc3de137ac3c3db87c5 Mon Sep 17 00:00:00 2001 From: Lukas Bockstaller Date: Mon, 4 Mar 2024 14:42:34 +0100 Subject: [PATCH] feat: exposes tags in testInfo --- packages/playwright/src/worker/testInfo.ts | 2 ++ tests/playwright-test/test-tag.spec.ts | 29 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts index e79bd61529..175fceee73 100644 --- a/packages/playwright/src/worker/testInfo.ts +++ b/packages/playwright/src/worker/testInfo.ts @@ -81,6 +81,7 @@ export class TestInfoImpl implements TestInfo { readonly titlePath: string[]; readonly file: string; readonly line: number; + readonly tags: string[]|undefined; readonly column: number; readonly fn: Function; expectedStatus: TestStatus; @@ -156,6 +157,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'; diff --git a/tests/playwright-test/test-tag.spec.ts b/tests/playwright-test/test-tag.spec.ts index e442c2acaa..b062e46899 100644 --- a/tests/playwright-test/test-tag.spec.ts +++ b/tests/playwright-test/test-tag.spec.ts @@ -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: '@tag1' }, async ()=>{ + test('test with tag', async ({}, testInfo) => { + expect(testInfo.tags).toStrictEqual(["@tag1"]); + }); + }); + `, + }); + expect(result.exitCode).toBe(0); +});