Skip to content

Commit

Permalink
chore: enforce tags format via typescript types (#32384)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Aug 29, 2024
1 parent 0a40862 commit 90e7b9e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1825,8 +1825,10 @@ type TestDetailsAnnotation = {
description?: string;
};

type TestDetailsTag = `@${string}`;

export type TestDetails = {
tag?: string | string[];
tag?: TestDetailsTag | TestDetailsTag[];
annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];
}

Expand Down
12 changes: 12 additions & 0 deletions tests/playwright-test/test-tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ test('should enforce @ symbol', async ({ runInlineTest }) => {
expect(result.output).toContain(`Error: Tag must start with "@" symbol, got "foo" instead.`);
});

test('types should enforce @ symbol', async ({ runTSC }) => {
const result = await runTSC({
'stdio.spec.ts': `
import { test, expect } from '@playwright/test';
test('test1', { tag: 'foo' }, () => {
});
`
});
expect(result.exitCode).toBe(2);
expect(result.output).toContain('error TS2322: Type \'"foo"\' is not assignable to type \'`@${string}` | `@${string}`[] | undefined');
});

test('should be included in testInfo', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'a.test.ts': `
Expand Down
4 changes: 3 additions & 1 deletion utils/generate_types/overrides-test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ type TestDetailsAnnotation = {
description?: string;
};

type TestDetailsTag = `@${string}`;

export type TestDetails = {
tag?: string | string[];
tag?: TestDetailsTag | TestDetailsTag[];
annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];
}

Expand Down

0 comments on commit 90e7b9e

Please sign in to comment.