Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/describe-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"e2e": patch
---

Add `test.describe.fail(title, fn)` and the `fail` option on `describe`, which mark every test in the group expected to fail.
3 changes: 2 additions & 1 deletion docs/ja/migrate/playwright.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ test('checkout', async ({ app, agent, screen }) => {
| `test.setTimeout()` | テスト本体、`beforeEach`、`beforeAll`(そのフック自身のタイムアウト)では同じ。`afterEach` と `afterAll` からは呼び出せません。`describe` のコールバック内では、代わりに `test.describe` に `{ timeout }` を渡します。タイムアウトなしを意味する `0` はないため、大きな値を渡します |
| `beforeEach`, `afterEach`, `beforeAll`, `afterAll` | 同じ。ただしタイトルなし。`beforeAll` と `afterAll` が受け取るのはワーカーフィクスチャで、`browser`、`app`、`screen` は受け取らない |
| `test.describe.skip`, `test.describe.serial`, `describe.configure({ mode: 'serial', retries, timeout })` | `test.describe(title, { skip, serial, retries, timeout }, fn)` |
| describe に対する `test.fail()` | `test.describe.fail(title, fn)`、またはグループの `{ fail: 'reason' }`。条件付きなら `beforeEach` 内で `test.fail(condition, 'reason')` |
| `{ tag: '@smoke' }` | テストまたはグループの `{ tags: ['smoke'] }` |
| `test.extend({ fixture })` | 同じ形式で、必要に応じてセットアップ。テスト、フック、フィクスチャは、最初の引数で指定したフィクスチャを受け取る |
| `[fn, { scope: 'worker' }]` のフィクスチャ | 同じ。`extend` の 2 番目の型引数で型を指定 |
Expand Down Expand Up @@ -281,7 +282,7 @@ export const test = base.extend<{ accountPage: AccountPage }>({
| `globalSetup`、`globalTeardown`、`webServer` の配列 | 実行の前後を囲むスクリプト、または全プロセスを起動する 1 つの `app.command` |
| `projects[].testMatch`, `testDir`, `testIgnore`, `grep` | テストの `platforms` やタグ、またはターゲットごとに別の実行 |
| `--ui`, `npx playwright show-report`, `--reporter html` | `--watch --headed`。`npx e2e report`(`htmlReporter()` が書き出す `<output>/report.html` を開く) |
| `test.slow()`、`test.describe.only()`、`test.describe.fixme()`、`test.fixme(title, details, body)`、describe に対する `test.fail()` | テストやグループに `{ timeout }` または `{ skip: 'fixme' }`、details の `tags` があればその横に指定(スキップ原因は `fixme` ではなく `explicit` と報告)。各テストに `test.only` と `test.fail()` |
| `test.slow()`、`test.describe.only()`、`test.describe.fixme()`、`test.fixme(title, details, body)` | テストやグループに `{ timeout }` または `{ skip: 'fixme' }`、details の `tags` があればその横に指定(スキップ原因は `fixme` ではなく `explicit` と報告)。各テストに `test.only` |
| `test.skip(callback, description)`、`test.fixme(callback, description)` | テスト本体内で `test.skip(condition, reason)` または `test.fixme(condition, reason)`、またはテストに `platforms` |
| `failOnFlakyTests`, `use.navigationTimeout`, `--timeout`, `--quiet` | `report.json` の `run.summary.flaky`。`browser.goto(url, { timeout })`。設定の `timeout` |
| `blob` レポーターと `merge-reports` | シャードごとに 1 つのレポート |
Expand Down
61 changes: 48 additions & 13 deletions docs/ja/reference/test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('checkout', { tags: ['billing'] }, () => {
| [`test.setup`](#test-setup) | `TestCase` |
| [`test.extend`](#test-extend) | `TestAPI` |
| [`describe`](#describe) | `void` |
| [`describe.fail`](#describe-fail) | `void` |
| [フック](#hooks) | `void` |

`describe` と 4 つのフックはトップレベルからもエクスポートされます。`test.describe`、`test.beforeEach` などと同じ関数です。`import { describe, beforeEach, test } from 'e2e'` のように使えます。
Expand Down Expand Up @@ -232,6 +233,8 @@ test.fail('known gap'); // inside a body, always
test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); // by option
```

To mark every test in a group, use [`describe.fail`](#describe-fail).
Comment thread
Vishwas1345 marked this conversation as resolved.
Resolved

- 呼び出し後もテスト本体は続行します。`beforeEach` フックから印を付けることもできます。
- アサーションやアクションの失敗、スローされたエラー、タイムアウトは、テストを `passed` にします。レポートには理由とエラーが残ります。
- 成功した場合は `UNEXPECTED_PASS` で `failed` になります。原因が修正されたら印を外してください。
Expand Down Expand Up @@ -347,6 +350,29 @@ describe('checkout', { tags: ['smoke'], serial: true }, () => {
| `COLLECTION_ERROR` | 本体が `async` の場合。型エラーにもなります。 |
| `COLLECTION_ERROR` | 本体内に `test.setup` がある場合。 |

#### `describe.fail`

Declares a group whose tests are all expected to fail, the same as
`fail: true` on `describe`. For a reason, use the [`fail`](#fail) option.

```ts
describe.fail('legacy checkout', () => {
test('pays by card', async ({ screen }) => {}); // expected to fail
test('applies a coupon', async ({ screen }) => {}); // expected to fail
});
describe('legacy checkout', { fail: 'old payment form' }, () => {}); // with a reason
```

- Each test is judged on its own, as with [`test.fail`](#test-fail): a
failure passes it, and a pass fails it with `UNEXPECTED_PASS`.
- A `fail` reason on a test or an inner group wins over an outer one.
`fail: false` on a test or an inner group does not unmark it.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | The group is serial or inside a serial group, or a serial group is inside it. |
| `COLLECTION_ERROR` | A `fail` option on `describe.fail`. It is also a type error. |

### フック

| フック | 実行タイミング |
Expand Down Expand Up @@ -468,7 +494,7 @@ afterAll(async () => {
| [`serial`](#serial) | `boolean` | - |
| [`sessions`](#sessions) | `readonly string[]` | 必須 |

`test` は `serial` と `sessions` 以外を受け付けます。`describe` は `only`、`fail`、`sessions` 以外を受け付けます。`test.setup` では `sessions` が必須で、`session`、`only`、`skip`、`fail` は受け付けません。
`test` は `serial` と `sessions` 以外を受け付けます。`describe` は `only` と `sessions` 以外を受け付けます。`test.setup` では `sessions` が必須で、`session`、`only`、`skip`、`fail` は受け付けません。

優先順位は、テスト、最も近いグループ、外側のグループ、設定、組み込みのデフォルト値の順です。[直列実行グループ](#serial)内では、グループの `retries`、`trace`、`video` を適用します。

Expand Down Expand Up @@ -516,10 +542,11 @@ test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app })

#### `fail`

テストの失敗を期待します。[`test.fail`](#test-fail) を参照してください。文字列は理由になります。直列実行グループ内では使えません。
テストの失敗を期待します。[`test.fail`](#test-fail) を参照してください。文字列は理由になります。 A layer with `true` or any string marks, and the innermost reason wins. Not allowed on, inside, or around a serial group.

```ts
test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {});
describe('legacy checkout', { fail: 'old payment form' }, () => {});
```

#### `only`
Expand Down Expand Up @@ -784,6 +811,19 @@ export const test = base.extend({
### `TestAPI`

```ts
/** The two call forms of `describe`. */
export interface DescribeRegistrar<Options = DescribeOptions> {
/** Declares a group synchronously. */
<Result>(title: string, body: SynchronousBody<Result>): void;
/** Declares a configured group synchronously. */
<Result>(title: string, options: Options, body: SynchronousBody<Result>): void;
}

export interface DescribeAPI extends DescribeRegistrar {
/** Declares a group whose tests are expected to fail, as if it had `fail: true`; a reason goes in the `fail` option of `describe`. */
fail: DescribeRegistrar<Omit<DescribeOptions, 'fail'>>;
}

/** The two call forms of `test`, shared with what `test.skipIf` and `test.runIf` return. */
export interface TestRegistrar<Fixtures = TestFixtures & WorkerFixtures> {
/** Registers one test synchronously during module evaluation. */
Expand Down Expand Up @@ -949,14 +989,8 @@ export interface TestAPI<Fixtures = TestFixtures, Worker = WorkerFixtures> exten
extend<Extra = {}, ExtraWorker = {}>(
fixtures: FixtureDefinitions<Fixtures & Worker, Extra, Worker, ExtraWorker>,
): TestAPI<Fixtures & Extra, Worker & ExtraWorker>;
/** Declares a group synchronously. */
describe<Result>(title: string, body: SynchronousBody<Result>): void;
/** Declares a configured group synchronously. */
describe<Result>(
title: string,
options: DescribeOptions,
body: SynchronousBody<Result>,
): void;
/** Declares a group synchronously; `describe.fail` declares one whose tests are expected to fail. */
describe: DescribeAPI;
/** Registers a test-attempt setup hook: it runs after the test's fixtures are set up. */
beforeEach(fn: TestHookFn<Fixtures & Worker>): void;
/** Registers a test-attempt teardown hook: it runs before the test's fixtures are torn down. */
Expand Down Expand Up @@ -989,8 +1023,9 @@ export interface TestOptions {
skip?: boolean | string;
/**
* Expects the test to fail; a string is the reason. A test failure then
* passes it, and a pass fails it with `UNEXPECTED_PASS`. Not allowed inside
* a serial group.
* passes it, and a pass fails it with `UNEXPECTED_PASS`. A layer with `true`
* or any string marks; the innermost reason wins. Not allowed on, inside, or
* around a serial group.
*/
fail?: boolean | string;
/** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */
Expand Down Expand Up @@ -1027,7 +1062,7 @@ export interface TestOptions {
video?: RecordingMode;
}

export interface DescribeOptions extends Omit<TestOptions, 'only' | 'fail'> {
export interface DescribeOptions extends Omit<TestOptions, 'only'> {
/** Runs the group as one ordered retry unit with shared app state. Nesting one serial group in another is a `COLLECTION_ERROR`. */
serial?: boolean;
}
Expand Down
3 changes: 2 additions & 1 deletion docs/migrate/playwright.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ run only in a browser, so a test that uses it declares
| `test.setTimeout()` | the same inside a test body, `beforeEach`, or `beforeAll` (that hook's own timeout); `afterEach` and `afterAll` cannot call it. In a `describe` callback, pass `{ timeout }` to `test.describe` instead. There is no `0` for no timeout: pass a large value |
| `beforeEach`, `afterEach`, `beforeAll`, `afterAll` | the same, with no title; `beforeAll` and `afterAll` get worker fixtures, not `browser`, `app`, or `screen` |
| `test.describe.skip`, `test.describe.serial`, `describe.configure({ mode: 'serial', retries, timeout })` | `test.describe(title, { skip, serial, retries, timeout }, fn)` |
| `test.fail()` on a describe | `test.describe.fail(title, fn)`, or `{ fail: 'reason' }` on the group; for a condition, `test.fail(condition, 'reason')` in a `beforeEach` |
| `{ tag: '@smoke' }` | `{ tags: ['smoke'] }` on a test or group |
| `test.extend({ fixture })` | the same shape, set up on demand: a test, a hook, or a fixture gets the fixtures it names in its first parameter |
| `[fn, { scope: 'worker' }]` fixtures | the same, typed with the second type argument of `extend` |
Expand Down Expand Up @@ -296,7 +297,7 @@ purpose. Use the workaround, or keep the test in Playwright.
| `globalSetup`, `globalTeardown`, a `webServer` array | A script around the run, or one `app.command` that starts every process |
| `projects[].testMatch`, `testDir`, `testIgnore`, `grep` | `platforms` or tags on the tests, or one run for each target |
| `--ui`, `npx playwright show-report`, `--reporter html` | `--watch --headed`; `npx e2e report` (opens `<output>/report.html` written by `htmlReporter()`) |
| `test.slow()`, `test.describe.only()`, `test.describe.fixme()`, `test.fixme(title, details, body)`, `test.fail()` on a describe | `{ timeout }` or `{ skip: 'fixme' }` on the test or group, with any `tags` from the details beside it, reported with skip cause `explicit`, not `fixme`; `test.only` and `test.fail()` on each test |
| `test.slow()`, `test.describe.only()`, `test.describe.fixme()`, `test.fixme(title, details, body)` | `{ timeout }` or `{ skip: 'fixme' }` on the test or group, with any `tags` from the details beside it, reported with skip cause `explicit`, not `fixme`; `test.only` on each test |
| `test.skip(callback, description)`, `test.fixme(callback, description)` | `test.skip(condition, reason)` or `test.fixme(condition, reason)` inside the body, or `platforms` on the test |
| `failOnFlakyTests`, `use.navigationTimeout`, `--timeout`, `--quiet` | `run.summary.flaky` in `report.json`; `browser.goto(url, { timeout })`; `timeout` in the config |
| The `blob` reporter and `merge-reports` | One report for each shard |
Expand Down
62 changes: 49 additions & 13 deletions docs/reference/test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('checkout', { tags: ['billing'] }, () => {
| [`test.setup`](#test-setup) | `TestCase` |
| [`test.extend`](#test-extend) | `TestAPI` |
| [`describe`](#describe) | `void` |
| [`describe.fail`](#describe-fail) | `void` |
| [Hooks](#hooks) | `void` |

`describe` and the four hooks are also top-level exports, the same functions
Expand Down Expand Up @@ -285,6 +286,8 @@ test.fail('known gap'); // inside a body, always
test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); // by option
```

To mark every test in a group, use [`describe.fail`](#describe-fail).

- The body keeps running after the call. A `beforeEach` hook can mark the
test too.
- A failed assertion, action, thrown error, or timeout makes the test
Expand Down Expand Up @@ -420,6 +423,29 @@ describe('checkout', { tags: ['smoke'], serial: true }, () => {
| `COLLECTION_ERROR` | An `async` body. It is also a type error. |
| `COLLECTION_ERROR` | `test.setup` inside the body. |

#### `describe.fail`

Declares a group whose tests are all expected to fail, the same as
`fail: true` on `describe`. For a reason, use the [`fail`](#fail) option.

```ts
describe.fail('legacy checkout', () => {
test('pays by card', async ({ screen }) => {}); // expected to fail
test('applies a coupon', async ({ screen }) => {}); // expected to fail
});
describe('legacy checkout', { fail: 'old payment form' }, () => {}); // with a reason
```

- Each test is judged on its own, as with [`test.fail`](#test-fail): a
failure passes it, and a pass fails it with `UNEXPECTED_PASS`.
- A `fail` reason on a test or an inner group wins over an outer one.
`fail: false` on a test or an inner group does not unmark it.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | The group is serial or inside a serial group, or a serial group is inside it. |
| `COLLECTION_ERROR` | A `fail` option on `describe.fail`. It is also a type error. |

### Hooks

| Hook | Runs |
Expand Down Expand Up @@ -575,7 +601,7 @@ blocked event loop hangs it.
| [`sessions`](#sessions) | `readonly string[]` | required |

`test` takes every option but `serial` and `sessions`. `describe` takes
every option but `only`, `fail`, and `sessions`. `test.setup` requires
every option but `only` and `sessions`. `test.setup` requires
`sessions` and takes no `session`, `only`, `skip`, or `fail`.

Resolution order: test, nearest group, outer groups, config, built-in
Expand Down Expand Up @@ -630,10 +656,12 @@ test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app })
#### `fail`

Expects the test to fail; see [`test.fail`](#test-fail). A string is the
reason. Not allowed inside a serial group.
reason. A layer with `true` or any string marks, and the innermost reason
wins. Not allowed on, inside, or around a serial group.

```ts
test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {});
describe('legacy checkout', { fail: 'old payment form' }, () => {});
```

#### `only`
Expand Down Expand Up @@ -990,6 +1018,19 @@ export const test = base.extend({
### `TestAPI`

```ts
/** The two call forms of `describe`. */
export interface DescribeRegistrar<Options = DescribeOptions> {
/** Declares a group synchronously. */
<Result>(title: string, body: SynchronousBody<Result>): void;
/** Declares a configured group synchronously. */
<Result>(title: string, options: Options, body: SynchronousBody<Result>): void;
}

export interface DescribeAPI extends DescribeRegistrar {
/** Declares a group whose tests are expected to fail, as if it had `fail: true`; a reason goes in the `fail` option of `describe`. */
fail: DescribeRegistrar<Omit<DescribeOptions, 'fail'>>;
}

/** The two call forms of `test`, shared with what `test.skipIf` and `test.runIf` return. */
export interface TestRegistrar<Fixtures = TestFixtures & WorkerFixtures> {
/** Registers one test synchronously during module evaluation. */
Expand Down Expand Up @@ -1155,14 +1196,8 @@ export interface TestAPI<Fixtures = TestFixtures, Worker = WorkerFixtures> exten
extend<Extra = {}, ExtraWorker = {}>(
fixtures: FixtureDefinitions<Fixtures & Worker, Extra, Worker, ExtraWorker>,
): TestAPI<Fixtures & Extra, Worker & ExtraWorker>;
/** Declares a group synchronously. */
describe<Result>(title: string, body: SynchronousBody<Result>): void;
/** Declares a configured group synchronously. */
describe<Result>(
title: string,
options: DescribeOptions,
body: SynchronousBody<Result>,
): void;
/** Declares a group synchronously; `describe.fail` declares one whose tests are expected to fail. */
describe: DescribeAPI;
/** Registers a test-attempt setup hook: it runs after the test's fixtures are set up. */
beforeEach(fn: TestHookFn<Fixtures & Worker>): void;
/** Registers a test-attempt teardown hook: it runs before the test's fixtures are torn down. */
Expand Down Expand Up @@ -1195,8 +1230,9 @@ export interface TestOptions {
skip?: boolean | string;
/**
* Expects the test to fail; a string is the reason. A test failure then
* passes it, and a pass fails it with `UNEXPECTED_PASS`. Not allowed inside
* a serial group.
* passes it, and a pass fails it with `UNEXPECTED_PASS`. A layer with `true`
* or any string marks; the innermost reason wins. Not allowed on, inside, or
* around a serial group.
*/
fail?: boolean | string;
/** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */
Expand Down Expand Up @@ -1233,7 +1269,7 @@ export interface TestOptions {
video?: RecordingMode;
}

export interface DescribeOptions extends Omit<TestOptions, 'only' | 'fail'> {
export interface DescribeOptions extends Omit<TestOptions, 'only'> {
/** Runs the group as one ordered retry unit with shared app state. Nesting one serial group in another is a `COLLECTION_ERROR`. */
serial?: boolean;
}
Expand Down
Loading
Loading