Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(types): allow specifying scope when overriding fixtures (#8139)
Dmitry Gozman052e0e197cd7
diff --git a/tests/playwright-test/types.spec.ts b/tests/playwright-test/types.spec.tsindex 89cdc7a1b2..234eb9b23b 100644--- a/tests/playwright-test/types.spec.ts+++ b/tests/playwright-test/types.spec.ts@@ -37,6 +37,16 @@ test('should check types of fixtures', async ({runTSC}) => {const good7 = test.extend<{ baz: boolean }>({baz: [ false, { auto: true } ],});+ const good8 = test.extend<{ foo: string }>({+ foo: [ async ({}, use) => {+ await use('foo');+ }, { scope: 'test' } ],+ });+ const good9 = test.extend<{}, {}>({+ bar: [ async ({}, use) => {+ await use(42);+ }, { scope: 'worker' } ],+ });// @ts-expect-errorconst fail1 = test.extend<{}>({ foo: 42 });@@ -60,6 +70,18 @@ test('should check types of fixtures', async ({runTSC}) => {// @ts-expect-errorbaz: true,});+ const fail9 = test.extend<{ foo: string }>({+ foo: [ async ({}, use) => {+ await use('foo');+ // @ts-expect-error+ }, { scope: 'test', auto: true } ],+ });+ const fail10 = test.extend<{}, {}>({+ bar: [ async ({}, use) => {+ await use(42);+ // @ts-expect-error+ }, { scope: 'test' } ],+ });`,'playwright.config.ts': `import { MyOptions } from './helper';diff --git a/types/test.d.ts b/types/test.d.tsindex 1c2fcd57d2..32b9764ff6 100644--- a/types/test.d.ts+++ b/types/test.d.ts@@ -2142,9 +2142,9 @@ export type WorkerFixture<R, Args extends KeyValue> = (args: Args, use: (r: R) =type TestFixtureValue<R, Args> = R | TestFixture<R, Args>;type WorkerFixtureValue<R, Args> = R | WorkerFixture<R, Args>;export type Fixtures<T extends KeyValue = {}, W extends KeyValue = {}, PT extends KeyValue = {}, PW extends KeyValue = {}> = {- [K in keyof PW]?: WorkerFixtureValue<PW[K], W & PW>;+ [K in keyof PW]?: WorkerFixtureValue<PW[K], W & PW> | [WorkerFixtureValue<PW[K], W & PW>, { scope: 'worker' }];} & {- [K in keyof PT]?: TestFixtureValue<PT[K], T & W & PT & PW>;+ [K in keyof PT]?: TestFixtureValue<PT[K], T & W & PT & PW> | [TestFixtureValue<PT[K], T & W & PT & PW>, { scope: 'test' }];} & {[K in keyof W]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', auto?: boolean }];} & {diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.tsindex a0d3a5469b..9cf4363f3f 100644--- a/utils/generate_types/overrides-test.d.ts+++ b/utils/generate_types/overrides-test.d.ts@@ -265,9 +265,9 @@ export type WorkerFixture<R, Args extends KeyValue> = (args: Args, use: (r: R) =type TestFixtureValue<R, Args> = R | TestFixture<R, Args>;type WorkerFixtureValue<R, Args> = R | WorkerFixture<R, Args>;export type Fixtures<T extends KeyValue = {}, W extends KeyValue = {}, PT extends KeyValue = {}, PW extends KeyValue = {}> = {- [K in keyof PW]?: WorkerFixtureValue<PW[K], W & PW>;+ [K in keyof PW]?: WorkerFixtureValue<PW[K], W & PW> | [WorkerFixtureValue<PW[K], W & PW>, { scope: 'worker' }];} & {- [K in keyof PT]?: TestFixtureValue<PT[K], T & W & PT & PW>;+ [K in keyof PT]?: TestFixtureValue<PT[K], T & W & PT & PW> | [TestFixtureValue<PT[K], T & W & PT & PW>, { scope: 'test' }];} & {[K in keyof W]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', auto?: boolean }];} & {