fix(types): allow specifying scope when overriding fixtures (#8139)

Otherwise it show a confusing error.
This commit is contained in:
Dmitry Gozman 2021-08-11 10:44:15 -07:00 committed by GitHub
parent e9e3349e2f
commit 052e0e197c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View File

@ -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-error
const fail1 = test.extend<{}>({ foo: 42 });
@ -60,6 +70,18 @@ test('should check types of fixtures', async ({runTSC}) => {
// @ts-expect-error
baz: 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';

4
types/test.d.ts vendored
View File

@ -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 }];
} & {

View File

@ -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 }];
} & {