Update types, address comments

This commit is contained in:
Yury Semikhatsky 2024-12-17 10:25:13 -08:00
parent dc833d7347
commit 0f707affa1
5 changed files with 19 additions and 28 deletions

View file

@ -1779,8 +1779,9 @@ Maximum time in milliseconds for the step to finish. Defaults to `0` (no timeout
Marks a test step as "should fail". Playwright runs this test step and ensures that it actually fails. This is useful for documentation purposes to acknowledge that some functionality is broken until it is fixed.
To declare a "failing" step:
* `test.step.fail(title, body)`
:::note
If the step exceeds the timeout, a [TimeoutError] is thrown. This indicates the step did not fail as expected.
:::
**Usage**
@ -1791,7 +1792,7 @@ import { test, expect } from '@playwright/test';
test('my test', async ({ page }) => {
// ...
await test.step.fail('not yet ready', async () => {
await test.step.fail('currently failing', async () => {
// ...
});
});
@ -1833,9 +1834,6 @@ Maximum time in milliseconds for the step to finish. Defaults to `0` (no timeout
Mark a test step as "fixme", with the intention to fix it. Playwright will not run the step.
To declare a "fixme" step:
* `test.step.fixme(title, body)`
**Usage**
You can declare a test step as failing, so that Playwright ensures it actually fails.

View file

@ -5714,9 +5714,6 @@ export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {
/**
* Mark a test step as "fixme", with the intention to fix it. Playwright will not run the step.
*
* To declare a "fixme" step:
* - `test.step.fixme(title, body)`
*
* **Usage**
*
* You can declare a test step as failing, so that Playwright ensures it actually fails.
@ -5736,13 +5733,13 @@ export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {
* @param body Step body.
* @param options
*/
fixme(title: string, body: () => void | Promise<void>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<void>;
fixme(title: string, body: () => any | Promise<any>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<void>;
/**
* Marks a test step as "should fail". Playwright runs this test step and ensures that it actually fails. This is
* useful for documentation purposes to acknowledge that some functionality is broken until it is fixed.
*
* To declare a "failing" step:
* - `test.step.fail(title, body)`
* **NOTE** If the step exceeds the timeout, a [TimeoutError](https://playwright.dev/docs/api/class-timeouterror) is
* thrown. This indicates the step did not fail as expected.
*
* **Usage**
*
@ -5753,7 +5750,7 @@ export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {
*
* test('my test', async ({ page }) => {
* // ...
* await test.step.fail('not yet ready', async () => {
* await test.step.fail('currently failing', async () => {
* // ...
* });
* });
@ -5763,7 +5760,7 @@ export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {
* @param body Step body.
* @param options
*/
fail(title: string, body: () => void | Promise<void>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<void>;
fail(title: string, body: () => any | Promise<any>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<void>;
}
/**
* `expect` function can be used to create test assertions. Read more about [test assertions](https://playwright.dev/docs/test-assertions).

View file

@ -1519,7 +1519,7 @@ test('test.step.fail and test.step.fixme should work', async ({ runInlineTest })
});
});
`
}, { reporter: '', workers: 1, timeout: 3000 });
}, { reporter: '' });
expect(result.exitCode).toBe(0);
expect(result.report.stats.expected).toBe(1);
@ -1553,7 +1553,7 @@ test('timeout inside test.step.fail is an error', async ({ runInlineTest }) => {
});
});
`
}, { reporter: '', workers: 2, timeout: 1000 });
}, { reporter: '', timeout: 2500 });
expect(result.exitCode).toBe(1);
expect(result.report.stats.unexpected).toBe(1);
@ -1563,7 +1563,7 @@ test.step |outer step 2 @ a.test.ts:4
test.step | inner step 2 @ a.test.ts:5
hook |After Hooks
hook |Worker Cleanup
|Test timeout of 1000ms exceeded.
|Test timeout of 2500ms exceeded.
`);
});
@ -1583,7 +1583,7 @@ test('skip test.step.fixme body', async ({ runInlineTest }) => {
expect(didRun).toBe(false);
});
`
}, { reporter: '', workers: 1, timeout: 1000 });
}, { reporter: '' });
expect(result.exitCode).toBe(0);
expect(result.report.stats.expected).toBe(1);

View file

@ -212,20 +212,16 @@ test('step.fail and step.fixme return void ', async ({ runTSC }) => {
test('test step.fail', async ({ }) => {
// @ts-expect-error
const bad1: string = await test.step.fail('my step', () => { });
// @ts-expect-error
const bad2: void = await test.step.fail('my step', async () => {
return 10;
const good: void = await test.step.fail('my step', async () => {
return 2024;
});
const good: void = await test.step.fail('my step', async () => { });
});
test('test step.fixme', async ({ }) => {
// @ts-expect-error
const bad1: string = await test.step.fixme('my step', () => { });
// @ts-expect-error
const bad2: void = await test.step.fixme('my step', async () => {
return 10;
const good: void = await test.step.fixme('my step', async () => {
return 2024;
});
const good: void = await test.step.fixme('my step', async () => { });
});
`
});

View file

@ -164,8 +164,8 @@ export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {
use(fixtures: Fixtures<{}, {}, TestArgs, WorkerArgs>): void;
step: {
<T>(title: string, body: () => T | Promise<T>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<T>;
fixme(title: string, body: () => void | Promise<void>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<void>;
fail(title: string, body: () => void | Promise<void>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<void>;
fixme(title: string, body: () => any | Promise<any>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<void>;
fail(title: string, body: () => any | Promise<any>, options?: { box?: boolean, location?: Location, timeout?: number }): Promise<void>;
}
expect: Expect<{}>;
extend<T extends {}, W extends {} = {}>(fixtures: Fixtures<T, W, TestArgs, WorkerArgs>): TestType<TestArgs & T, WorkerArgs & W>;