chore: enforce tags format via typescript types (#32384)
Leverage [template literal types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html). Fixes https://github.com/microsoft/playwright/issues/32382
This commit is contained in:
parent
0a40862bc8
commit
90e7b9ebac
4
packages/playwright/types/test.d.ts
vendored
4
packages/playwright/types/test.d.ts
vendored
|
|
@ -1825,8 +1825,10 @@ type TestDetailsAnnotation = {
|
||||||
description?: string;
|
description?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type TestDetailsTag = `@${string}`;
|
||||||
|
|
||||||
export type TestDetails = {
|
export type TestDetails = {
|
||||||
tag?: string | string[];
|
tag?: TestDetailsTag | TestDetailsTag[];
|
||||||
annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];
|
annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,18 @@ test('should enforce @ symbol', async ({ runInlineTest }) => {
|
||||||
expect(result.output).toContain(`Error: Tag must start with "@" symbol, got "foo" instead.`);
|
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) => {
|
test('should be included in testInfo', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
|
|
|
||||||
4
utils/generate_types/overrides-test.d.ts
vendored
4
utils/generate_types/overrides-test.d.ts
vendored
|
|
@ -70,8 +70,10 @@ type TestDetailsAnnotation = {
|
||||||
description?: string;
|
description?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type TestDetailsTag = `@${string}`;
|
||||||
|
|
||||||
export type TestDetails = {
|
export type TestDetails = {
|
||||||
tag?: string | string[];
|
tag?: TestDetailsTag | TestDetailsTag[];
|
||||||
annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];
|
annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue