fix(test runner types): allow sync step functions (#20996)

This commit is contained in:
Dmitry Gozman 2023-02-17 14:26:40 -08:00 committed by GitHub
parent 5483006499
commit 55f4b670a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 2 deletions

View file

@ -3184,7 +3184,7 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue
* @param title Step name. * @param title Step name.
* @param body Step body. * @param body Step body.
*/ */
step<T>(title: string, body: () => Promise<T>): Promise<T>; step<T>(title: string, body: () => T | Promise<T>): Promise<T>;
/** /**
* `expect` function can be used to create test assertions. Read more about [test assertions](https://playwright.dev/docs/test-assertions). * `expect` function can be used to create test assertions. Read more about [test assertions](https://playwright.dev/docs/test-assertions).
* *

View file

@ -160,6 +160,7 @@ test('step should inherit return type from its callback ', async ({ runTSC }) =>
return 'foo'; return 'foo';
}); });
await test.step('my step', async () => { }); await test.step('my step', async () => { });
const good2: string = await test.step('my step', () => 'foo');
}); });
` `
}); });

View file

@ -152,7 +152,7 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue
beforeAll(inner: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<any> | any): void; beforeAll(inner: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<any> | any): void;
afterAll(inner: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<any> | any): void; afterAll(inner: (args: TestArgs & WorkerArgs, testInfo: TestInfo) => Promise<any> | any): void;
use(fixtures: Fixtures<{}, {}, TestArgs, WorkerArgs>): void; use(fixtures: Fixtures<{}, {}, TestArgs, WorkerArgs>): void;
step<T>(title: string, body: () => Promise<T>): Promise<T>; step<T>(title: string, body: () => T | Promise<T>): Promise<T>;
expect: Expect; expect: Expect;
extend<T extends KeyValue, W extends KeyValue = {}>(fixtures: Fixtures<T, W, TestArgs, WorkerArgs>): TestType<TestArgs & T, WorkerArgs & W>; extend<T extends KeyValue, W extends KeyValue = {}>(fixtures: Fixtures<T, W, TestArgs, WorkerArgs>): TestType<TestArgs & T, WorkerArgs & W>;
info(): TestInfo; info(): TestInfo;