From 4f7450da19a85b728e7abaf8b86ebec586c3fd37 Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Wed, 18 Nov 2026 14:15:52 +0530 Subject: [PATCH 1/6] feat(test): add test.describe.fail and the fail option on describe A test now reads fail from its groups as well as itself. Any truthy layer marks it, the innermost reason wins, and fail: false does not unmark. Refused on, inside, or around a serial group. Part of #1855. --- .changeset/describe-fail.md | 5 ++ docs/ja/migrate/playwright.mdx | 3 +- docs/ja/reference/test.mdx | 60 ++++++++++++++---- docs/migrate/playwright.mdx | 3 +- docs/reference/test.mdx | 61 +++++++++++++++---- docs/zh/migrate/playwright.mdx | 3 +- docs/zh/reference/test.mdx | 60 ++++++++++++++---- packages/core/src/types.ts | 29 +++++---- packages/e2e/src/collect/registry.ts | 59 ++++++++++++------ packages/e2e/src/collect/select.ts | 8 ++- .../integration/expected-failure.test.ts | 37 +++++++++++ packages/e2e/tests/types/sdk-types.ts | 13 +++- packages/e2e/tests/unit/registry.test.ts | 34 ++++++++++- packages/e2e/tests/unit/select.test.ts | 27 ++++++++ .../skills/e2e/references/writing-tests.md | 3 +- skills/e2e/references/writing-tests.md | 3 +- 16 files changed, 330 insertions(+), 78 deletions(-) create mode 100644 .changeset/describe-fail.md diff --git a/.changeset/describe-fail.md b/.changeset/describe-fail.md new file mode 100644 index 0000000000..ca08710107 --- /dev/null +++ b/.changeset/describe-fail.md @@ -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. diff --git a/docs/ja/migrate/playwright.mdx b/docs/ja/migrate/playwright.mdx index cd4091f396..16b5e8222f 100644 --- a/docs/ja/migrate/playwright.mdx +++ b/docs/ja/migrate/playwright.mdx @@ -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)` | +| `test.fail()` on a describe | `test.describe.fail(title, fn)`, or `{ fail: 'reason' }` on the group | | `{ tag: '@smoke' }` | テストまたはグループの `{ tags: ['smoke'] }` | | `test.extend({ fixture })` | 同じ形式で、必要に応じてセットアップ。テスト、フック、フィクスチャは、最初の引数で指定したフィクスチャを受け取る | | `[fn, { scope: 'worker' }]` のフィクスチャ | 同じ。`extend` の 2 番目の型引数で型を指定 | @@ -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()` が書き出す `/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 つのレポート | diff --git a/docs/ja/reference/test.mdx b/docs/ja/reference/test.mdx index 9e2dc0bd51..ecc83b43f5 100644 --- a/docs/ja/reference/test.mdx +++ b/docs/ja/reference/test.mdx @@ -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'` のように使えます。 @@ -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). + - 呼び出し後もテスト本体は続行します。`beforeEach` フックから印を付けることもできます。 - アサーションやアクションの失敗、スローされたエラー、タイムアウトは、テストを `passed` にします。レポートには理由とエラーが残ります。 - 成功した場合は `UNEXPECTED_PASS` で `failed` になります。原因が修正されたら印を外してください。 @@ -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. | + ### フック | フック | 実行タイミング | @@ -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` を適用します。 @@ -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) を参照してください。文字列は理由になります。 Any truthy layer marks, and the innermost reason wins. Not allowed on or inside a serial group. ```ts test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); +describe('legacy checkout', { fail: 'old payment form' }, () => {}); ``` #### `only` @@ -784,6 +811,19 @@ export const test = base.extend({ ### `TestAPI` ```ts +/** The two call forms of `describe`. */ +export interface DescribeRegistrar { + /** Declares a group synchronously. */ + (title: string, body: SynchronousBody): void; + /** Declares a configured group synchronously. */ + (title: string, options: Options, body: SynchronousBody): 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>; +} + /** The two call forms of `test`, shared with what `test.skipIf` and `test.runIf` return. */ export interface TestRegistrar { /** Registers one test synchronously during module evaluation. */ @@ -949,14 +989,8 @@ export interface TestAPI exten extend( fixtures: FixtureDefinitions, ): TestAPI; - /** Declares a group synchronously. */ - describe(title: string, body: SynchronousBody): void; - /** Declares a configured group synchronously. */ - describe( - title: string, - options: DescribeOptions, - body: SynchronousBody, - ): 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): void; /** Registers a test-attempt teardown hook: it runs before the test's fixtures are torn down. */ @@ -989,8 +1023,8 @@ 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`. Any truthy layer + * marks; the innermost reason wins. Not allowed on or inside a serial group. */ fail?: boolean | string; /** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */ @@ -1027,7 +1061,7 @@ export interface TestOptions { video?: RecordingMode; } -export interface DescribeOptions extends Omit { +export interface DescribeOptions extends Omit { /** Runs the group as one ordered retry unit with shared app state. Nesting one serial group in another is a `COLLECTION_ERROR`. */ serial?: boolean; } diff --git a/docs/migrate/playwright.mdx b/docs/migrate/playwright.mdx index a8c97c6868..94ebf39db4 100644 --- a/docs/migrate/playwright.mdx +++ b/docs/migrate/playwright.mdx @@ -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 | | `{ 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` | @@ -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 `/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 | diff --git a/docs/reference/test.mdx b/docs/reference/test.mdx index 44bfef808a..329624910b 100644 --- a/docs/reference/test.mdx +++ b/docs/reference/test.mdx @@ -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 @@ -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 @@ -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 | @@ -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 @@ -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. Any truthy layer marks, and the innermost reason wins. Not allowed on +or inside a serial group. ```ts test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); +describe('legacy checkout', { fail: 'old payment form' }, () => {}); ``` #### `only` @@ -990,6 +1018,19 @@ export const test = base.extend({ ### `TestAPI` ```ts +/** The two call forms of `describe`. */ +export interface DescribeRegistrar { + /** Declares a group synchronously. */ + (title: string, body: SynchronousBody): void; + /** Declares a configured group synchronously. */ + (title: string, options: Options, body: SynchronousBody): 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>; +} + /** The two call forms of `test`, shared with what `test.skipIf` and `test.runIf` return. */ export interface TestRegistrar { /** Registers one test synchronously during module evaluation. */ @@ -1155,14 +1196,8 @@ export interface TestAPI exten extend( fixtures: FixtureDefinitions, ): TestAPI; - /** Declares a group synchronously. */ - describe(title: string, body: SynchronousBody): void; - /** Declares a configured group synchronously. */ - describe( - title: string, - options: DescribeOptions, - body: SynchronousBody, - ): 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): void; /** Registers a test-attempt teardown hook: it runs before the test's fixtures are torn down. */ @@ -1195,8 +1230,8 @@ 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`. Any truthy layer + * marks; the innermost reason wins. Not allowed on or inside a serial group. */ fail?: boolean | string; /** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */ @@ -1233,7 +1268,7 @@ export interface TestOptions { video?: RecordingMode; } -export interface DescribeOptions extends Omit { +export interface DescribeOptions extends Omit { /** Runs the group as one ordered retry unit with shared app state. Nesting one serial group in another is a `COLLECTION_ERROR`. */ serial?: boolean; } diff --git a/docs/zh/migrate/playwright.mdx b/docs/zh/migrate/playwright.mdx index a3329c936d..a912c66cc0 100644 --- a/docs/zh/migrate/playwright.mdx +++ b/docs/zh/migrate/playwright.mdx @@ -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)` | +| `test.fail()` on a describe | `test.describe.fail(title, fn)`, or `{ fail: 'reason' }` on the group | | `{ tag: '@smoke' }` | 测试或组上的 `{ tags: ['smoke'] }` | | `test.extend({ fixture })` | 结构相同,按需准备:测试、钩子或测试夹具会得到它在第一个参数中列出的测试夹具 | | `[fn, { scope: 'worker' }]` 测试夹具 | 相同,用 `extend` 的第二个类型参数提供类型 | @@ -281,7 +282,7 @@ export const test = base.extend<{ accountPage: AccountPage }>({ | `globalSetup`, `globalTeardown`, `webServer` 数组 | 在运行前后执行的脚本,或启动所有进程的一个 `app.command` | | `projects[].testMatch`, `testDir`, `testIgnore`, `grep` | 测试上的 `platforms` 或标签,或为每个测试目标单独运行 | | `--ui`, `npx playwright show-report`, `--reporter html` | `--watch --headed`;`npx e2e report`(打开 `htmlReporter()` 写入的 `/report.html`) | -| `test.slow()`、`test.describe.only()`、`test.describe.fixme()`、`test.fixme(title, details, body)`、describe 上的 `test.fail()` | 测试或组上的 `{ timeout }` 或 `{ skip: 'fixme' }`,details 中的 `tags` 一并写在旁边(报告的跳过原因为 `explicit`,而非 `fixme`);每个测试上的 `test.only` 和 `test.fail()` | +| `test.slow()`、`test.describe.only()`、`test.describe.fixme()`、`test.fixme(title, details, body)` | 测试或组上的 `{ timeout }` 或 `{ skip: 'fixme' }`,details 中的 `tags` 一并写在旁边(报告的跳过原因为 `explicit`,而非 `fixme`);每个测试上的 `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` | 每个分片一份报告 | diff --git a/docs/zh/reference/test.mdx b/docs/zh/reference/test.mdx index 1b7623ff4d..cbd9a1f97b 100644 --- a/docs/zh/reference/test.mdx +++ b/docs/zh/reference/test.mdx @@ -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` 和四个钩子也作为顶层导出提供,与 `test.describe`、`test.beforeEach` 等是相同的函数:`import { describe, beforeEach, test } from 'e2e'`。 @@ -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). + - 调用后主体继续执行。`beforeEach` 钩子也可以标记测试。 - 断言失败、操作失败、抛出错误或超时会使测试状态为 `passed`。报告保留原因和错误。 - 通过则使测试以 `UNEXPECTED_PASS` 变为 `failed`。原因修复后应移除标记。 @@ -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. | + ### 钩子 | 钩子 | 执行时机 | @@ -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`。 @@ -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)。字符串表示原因。 Any truthy layer marks, and the innermost reason wins. Not allowed on or inside a serial group. ```ts test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); +describe('legacy checkout', { fail: 'old payment form' }, () => {}); ``` #### `only` @@ -784,6 +811,19 @@ export const test = base.extend({ ### `TestAPI` ```ts +/** The two call forms of `describe`. */ +export interface DescribeRegistrar { + /** Declares a group synchronously. */ + (title: string, body: SynchronousBody): void; + /** Declares a configured group synchronously. */ + (title: string, options: Options, body: SynchronousBody): 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>; +} + /** The two call forms of `test`, shared with what `test.skipIf` and `test.runIf` return. */ export interface TestRegistrar { /** Registers one test synchronously during module evaluation. */ @@ -949,14 +989,8 @@ export interface TestAPI exten extend( fixtures: FixtureDefinitions, ): TestAPI; - /** Declares a group synchronously. */ - describe(title: string, body: SynchronousBody): void; - /** Declares a configured group synchronously. */ - describe( - title: string, - options: DescribeOptions, - body: SynchronousBody, - ): 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): void; /** Registers a test-attempt teardown hook: it runs before the test's fixtures are torn down. */ @@ -989,8 +1023,8 @@ 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`. Any truthy layer + * marks; the innermost reason wins. Not allowed on or inside a serial group. */ fail?: boolean | string; /** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */ @@ -1027,7 +1061,7 @@ export interface TestOptions { video?: RecordingMode; } -export interface DescribeOptions extends Omit { +export interface DescribeOptions extends Omit { /** Runs the group as one ordered retry unit with shared app state. Nesting one serial group in another is a `COLLECTION_ERROR`. */ serial?: boolean; } diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 857ae999ec..5fb43e777a 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -755,8 +755,8 @@ 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`. Any truthy layer + * marks; the innermost reason wins. Not allowed on or inside a serial group. */ fail?: boolean | string; /** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */ @@ -793,7 +793,7 @@ export interface TestOptions { video?: RecordingMode; } -export interface DescribeOptions extends Omit { +export interface DescribeOptions extends Omit { /** Runs the group as one ordered retry unit with shared app state. Nesting one serial group in another is a `COLLECTION_ERROR`. */ serial?: boolean; } @@ -836,6 +836,19 @@ export interface TestCase { readonly [testCaseBrand]: true; } +/** The two call forms of `describe`. */ +export interface DescribeRegistrar { + /** Declares a group synchronously. */ + (title: string, body: SynchronousBody): void; + /** Declares a configured group synchronously. */ + (title: string, options: Options, body: SynchronousBody): 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>; +} + /** The two call forms of `test`, shared with what `test.skipIf` and `test.runIf` return. */ export interface TestRegistrar { /** Registers one test synchronously during module evaluation. */ @@ -1033,14 +1046,8 @@ export interface TestAPI exten extend( fixtures: FixtureDefinitions, ): TestAPI; - /** Declares a group synchronously. */ - describe(title: string, body: SynchronousBody): void; - /** Declares a configured group synchronously. */ - describe( - title: string, - options: DescribeOptions, - body: SynchronousBody, - ): 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): void; /** Registers a test-attempt teardown hook: it runs before the test's fixtures are torn down. */ diff --git a/packages/e2e/src/collect/registry.ts b/packages/e2e/src/collect/registry.ts index 815fb17fda..326bc6e6b1 100644 --- a/packages/e2e/src/collect/registry.ts +++ b/packages/e2e/src/collect/registry.ts @@ -10,7 +10,7 @@ import { CollectionError } from '@e2e-dev/core/lib/internal/errors'; import { MAX_TIMER_MS } from '@e2e-dev/core/lib/internal/time'; import { validateTitle } from '@e2e-dev/core/lib/internal/ids'; import { realmSlot } from '@e2e-dev/core/lib/internal/realm-slot'; -import { markRunningTestExpectedToFail } from '@e2e-dev/core/lib/internal/expected-failure'; +import { expectedFailureOption, markRunningTestExpectedToFail } from '@e2e-dev/core/lib/internal/expected-failure'; import { setRunningTestTimeout } from '@e2e-dev/core/lib/internal/test-timeout'; import { fixmeReason, parseModifierCall, skipRunningTest } from '../internal/skip.ts'; import { formatEachTitle, readRows } from './each.ts'; @@ -19,6 +19,7 @@ import type { SourceLocation } from '@e2e-dev/core/lib/internal/source'; import { fixtureNames, type FixtureUserFn } from './fixture-names.ts'; import { checkDeclaredFixtures, describeFixture, describeUser } from './fixture-plan.ts'; import type { + DescribeAPI, DescribeOptions, EachFn, EachRegistrar, @@ -253,8 +254,8 @@ class Collector { return Object.freeze({ [testCaseBrand]: true as const }); } - registerDescribe(title: string, options: DescribeOptions, body: () => unknown): void { - this.assertOpen('describe()'); + registerDescribe(title: string, options: DescribeOptions, body: () => unknown, api = 'describe()'): void { + this.assertOpen(api); const normalizedTitle = this.title(title); if (typeof body !== 'function') throw new CollectionError('describe body must be a function'); validateDescribeOptions(options, this.currentGroup); @@ -396,6 +397,7 @@ const DESCRIBE_OPTION_KEYS: readonly string[] = Object.keys({ retries: true, tags: true, skip: true, + fail: true, platforms: true, requires: true, session: true, @@ -503,10 +505,7 @@ function insideSerial(group: GroupNode | undefined): boolean { function validateTestOptions(options: TestOptions, group: GroupNode | undefined, kind: 'test' | 'setup'): void { if (kind === 'setup') validateCommonOptions(options, 'setup options', SETUP_OPTION_KEYS); else validateCommonOptions(options, 'test options', TEST_OPTION_KEYS); - const fail: unknown = options.fail; - if (fail !== undefined && typeof fail !== 'boolean' && typeof fail !== 'string') { - throw new CollectionError(`test options: fail must be true, false, or a reason string, got ${describeValue(fail)}`); - } + validateFailOption(options.fail, 'test options'); if (insideSerial(group)) { const forbidden: (keyof TestOptions)[] = [ 'retries', @@ -529,11 +528,25 @@ function validateTestOptions(options: TestOptions, group: GroupNode | undefined, } } +function validateFailOption(fail: unknown, label: string): void { + if (fail !== undefined && typeof fail !== 'boolean' && typeof fail !== 'string') { + throw new CollectionError(`${label}: fail must be true, false, or a reason string, got ${describeValue(fail)}`); + } +} + function validateDescribeOptions(options: DescribeOptions, parent: GroupNode | undefined): void { validateCommonOptions(options, 'describe options', DESCRIBE_OPTION_KEYS); + validateFailOption(options.fail, 'describe options'); if (options.serial === true && insideSerial(parent)) { throw new CollectionError('nested serial groups are collection errors'); } + // A serial group's members cannot be marked expected to fail, so neither can the group. + if (options.fail !== undefined && (options.serial === true || insideSerial(parent))) { + throw new CollectionError('describe option "fail" cannot be set on or inside a serial group, which runs as one unit'); + } + if (options.serial === true && groupChain(parent).some((group) => expectedFailureOption(group.options.fail) !== undefined)) { + throw new CollectionError('a serial group cannot sit inside a group marked fail; its members cannot be expected to fail'); + } // The serial group records as one unit, so a describe inside it cannot choose its own recordings. for (const kind of ['trace', 'video'] as const) { if (options[kind] !== undefined && insideSerial(parent)) { @@ -814,6 +827,27 @@ function createTestAPI(chain: readonly FixtureDefinition[]): TestAPI { }; }; + /** The `describe()` call forms; `describe.fail` marks the group as if it had `fail: true`, so it takes no `fail` of its own. */ + const groupRegistrar = (api: string, fail: boolean) => ( + title: string, + optionsOrBody: DescribeOptions | (() => Result), + maybeBody?: () => Result, + ): void => { + const given = typeof optionsOrBody === 'function' ? {} : optionsOrBody; + const body = typeof optionsOrBody === 'function' ? optionsOrBody : maybeBody; + if (body === undefined) throw new CollectionError('describe body function is required'); + const collector = requireCollector(api); + // Non-object options reach validation untouched, exactly as describe() passes them. + const marks = fail && typeof given === 'object' && given !== null; + if (marks && given.fail !== undefined) { + throw new CollectionError(`${api} takes no fail option; give a reason with describe(title, { fail: 'reason' }, fn)`); + } + collector.registerDescribe(title, marks ? { ...given, fail: true } : given, body, api); + }; + const describe = Object.assign(groupRegistrar('describe()', false), { + fail: groupRegistrar('describe.fail()', true), + }) as DescribeAPI; + const api: TestAPI = Object.assign(testFunction, { skip(first?: string | boolean, second?: TestBody | string): TestCase | undefined { const call = parseModifierCall(first, second); @@ -864,16 +898,7 @@ function createTestAPI(chain: readonly FixtureDefinition[]): TestAPI { const { sessions, ...rest } = options; return requireCollector('test.setup()').registerTest('setup', 'normal', title, rest, sessions, fn, chain); }, - describe( - title: string, - optionsOrBody: DescribeOptions | (() => Result), - maybeBody?: () => Result, - ): void { - const options = typeof optionsOrBody === 'function' ? {} : optionsOrBody; - const body = typeof optionsOrBody === 'function' ? optionsOrBody : maybeBody; - if (body === undefined) throw new CollectionError('describe body function is required'); - requireCollector('describe()').registerDescribe(title, options, body); - }, + describe, beforeEach(fn: TestBody): void { requireCollector('beforeEach()').registerHook({ kind: 'beforeEach', fn, fixtures: chain }); }, diff --git a/packages/e2e/src/collect/select.ts b/packages/e2e/src/collect/select.ts index 3222446d5f..4f0e3812c2 100644 --- a/packages/e2e/src/collect/select.ts +++ b/packages/e2e/src/collect/select.ts @@ -28,7 +28,7 @@ export interface ResolvedTestOptions { */ readonly agents: readonly string[]; readonly skipReason: string | undefined; - /** Why the test is expected to fail (its `fail` option), or undefined when it is not. */ + /** Why the test is expected to fail (its or a group's `fail` option), or undefined when it is not. */ readonly expectedFailure: string | undefined; readonly serial: boolean; /** @@ -143,6 +143,7 @@ export function resolveOptions(test: CollectedTest, config: ResolvedConfig): Res let session: string | undefined; let pin: readonly string[] | undefined; let skipReason: string | undefined; + let fail: TestOptions['fail']; let trace: TestOptions['trace']; let video: TestOptions['video']; const agentContextParts: string[] = []; @@ -160,6 +161,9 @@ export function resolveOptions(test: CollectedTest, config: ResolvedConfig): Res if (layer.skip !== undefined && layer.skip !== false) { skipReason = typeof layer.skip === 'string' ? layer.skip : 'skipped'; } + // A mark without a reason (`true` or a blank string) keeps an outer layer's reason. + if (typeof layer.fail === 'string' && layer.fail.trim() !== '') fail = layer.fail; + else if (expectedFailureOption(layer.fail) !== undefined && fail === undefined) fail = true; } // Retries and recordings belong to the serial unit: one retry loop and one @@ -198,7 +202,7 @@ export function resolveOptions(test: CollectedTest, config: ResolvedConfig): Res agents: effectiveAgents(test, pin, config.agentNames), agentContext: agentContextParts.length === 0 ? undefined : agentContextParts.join('\n'), skipReason: skipReason === undefined ? undefined : truncateUtf8(sanitizeRecordedText(staticSecretLedger(config.allSecrets).redact(skipReason)), 8192), - expectedFailure: expectedFailureOption(test.options.fail), + expectedFailure: expectedFailureOption(fail), serial: serialRoot !== undefined, trace, video, diff --git a/packages/e2e/tests/integration/expected-failure.test.ts b/packages/e2e/tests/integration/expected-failure.test.ts index 208c330e98..31a7332664 100644 --- a/packages/e2e/tests/integration/expected-failure.test.ts +++ b/packages/e2e/tests/integration/expected-failure.test.ts @@ -98,6 +98,43 @@ test('times out', { fail: 'too slow', timeout: 500 }, async () => { 120_000, ); + it( + 'marks every test in a describe.fail group, each judged on its own', + async () => { + const file = `import { describe, expect, test } from 'e2e'; + +describe.fail('legacy', () => { + test('still broken', async () => { + expect(1).toBe(2); + }); + test('fixed since', async () => {}); +}); + +describe('known gaps', { fail: 'old checkout' }, () => { + test('card form', async () => { + throw new Error('the gap'); + }); +}); + +test('outside the group', async () => {}); +`; + const { outcome, project } = await runProject({ 'tests/group.e2e.ts': file }, {}); + assertValidReport(outcome.report); + const byTitle = (title: string) => outcome.report.run.results.find((result) => result.titlePath.at(-1) === title)!; + + expect(byTitle('still broken')).toMatchObject({ status: 'passed', expectedFailure: { reason: 'expected to fail' } }); + const fixed = byTitle('fixed since'); + expect(fixed.status).toBe('failed'); + expect(fixed.attempts[0]?.error).toMatchObject({ code: 'UNEXPECTED_PASS' }); + expect(byTitle('card form')).toMatchObject({ status: 'passed', expectedFailure: { reason: 'old checkout' } }); + const outside = byTitle('outside the group'); + expect(outside.status).toBe('passed'); + expect(outside.expectedFailure).toBeUndefined(); + project.cleanup(); + }, + 120_000, + ); + it( 'takes a mark from a beforeEach hook and refuses one from an afterEach hook', async () => { diff --git a/packages/e2e/tests/types/sdk-types.ts b/packages/e2e/tests/types/sdk-types.ts index fd8843e141..5be87b6e41 100644 --- a/packages/e2e/tests/types/sdk-types.ts +++ b/packages/e2e/tests/types/sdk-types.ts @@ -683,7 +683,7 @@ test.for([1])('no body'); test.each([[1, 'one']])('%i', async (_n, { app }) => { void app; }); // @ts-expect-error test.for passes the row whole, not spread test.for([[1, 'one']])('%i', async (n: number) => { void n; }); -// fail takes the same three shapes and returns nothing inside a body; describe and setup take no fail option. +// fail takes the same three shapes and returns nothing inside a body; a group takes it as an option or describe.fail, setup never. test.fail(true, 'known gap'); test.fail('known gap'); test.setTimeout(60_000); @@ -692,8 +692,15 @@ test.setTimeout('60s'); test.fail('gap', async () => {}) satisfies ReturnType; void (test.fail(false) satisfies void); test('gap', { fail: 'known gap' }, async () => {}); -// @ts-expect-error a group cannot expect failure; mark each test -test.describe('gaps', { fail: true }, () => {}); +test.describe('gaps', { fail: 'legacy checkout' }, () => {}); +void (test.describe.fail('gaps', () => {}) satisfies void); +describe.fail('gaps', { tags: ['legacy'] }, () => {}); +// @ts-expect-error describe.fail is already marked; a reason goes in describe's fail option +describe.fail('gaps', { fail: 'legacy checkout' }, () => {}); +// @ts-expect-error describe.fail registration must be synchronous +test.describe.fail('asynchronous', async () => {}); +// @ts-expect-error a group cannot be focused; describe options take no only +test.describe.fail('gaps', { only: true }, () => {}); void screen.getByLabel('Plan').selectOption({ value: 'pro' }); // @ts-expect-error one of label, value, or index, never two void screen.getByLabel('Plan').selectOption({ value: 'pro', index: 1 }); diff --git a/packages/e2e/tests/unit/registry.test.ts b/packages/e2e/tests/unit/registry.test.ts index cc355bf076..903cf1c543 100644 --- a/packages/e2e/tests/unit/registry.test.ts +++ b/packages/e2e/tests/unit/registry.test.ts @@ -493,10 +493,42 @@ describe('registration', () => { await expect(collectModule(async () => test('bad', { fail: 1 } as never, noop))).rejects.toThrow( 'test options: fail must be true, false, or a reason string, got 1', ); - await expect(collectModule(async () => test.describe('group', { fail: true } as never, () => {}))).rejects.toThrow(/unknown key "fail"/); await expect(collectModule(async () => test.setup('login', { sessions: ['admin'], fail: true } as never, noop))).rejects.toThrow(/unknown key "fail"/); }); + it('marks a group by describe.fail(title, fn) or the fail option, and checks both', async () => { + const registration = await collectModule(async () => { + test.describe.fail('shortcut', () => test('a', noop)); + test.describe.fail('shortcut with options', { tags: ['legacy'] }, () => test('b', noop)); + test.describe('by option', { fail: 'known gap' }, () => test('c', noop)); + registry.describe.fail('top-level import', () => test('d', noop)); + }); + expect(registration.tests.map((item) => item.group?.options.fail)).toEqual([true, true, 'known gap', true]); + expect(registration.tests[1]!.tags).toEqual(['legacy']); + await expect(collectModule(async () => test.describe('group', { fail: 1 } as never, () => {}))).rejects.toThrow( + 'describe options: fail must be true, false, or a reason string, got 1', + ); + for (const fail of ['legacy checkout', false, 1]) { + await expect(collectModule(async () => test.describe.fail('group', { fail } as never, () => {}))).rejects.toThrow( + "describe.fail() takes no fail option; give a reason with describe(title, { fail: 'reason' }, fn)", + ); + } + }); + + it('refuses fail on, inside, or around a serial group', async () => { + const serialRule = 'describe option "fail" cannot be set on or inside a serial group, which runs as one unit'; + await expect(collectModule(async () => test.describe('unit', { serial: true, fail: true }, () => {}))).rejects.toThrow(serialRule); + await expect( + collectModule(async () => test.describe('unit', { serial: true }, () => test.describe.fail('inner', () => {}))), + ).rejects.toThrow(serialRule); + await expect( + collectModule(async () => test.describe.fail('outer', () => test.describe('unit', { serial: true }, () => {}))), + ).rejects.toThrow('a serial group cannot sit inside a group marked fail; its members cannot be expected to fail'); + await expect( + collectModule(async () => test.describe('outer', { fail: false }, () => test.describe('unit', { serial: true }, () => {}))), + ).resolves.toBeDefined(); + }); + it('rejects test.fail(condition) outside a test body', async () => { expect(() => test.fail(true, 'not here')).toThrow(CollectionError); expect(() => test.fail(false)).toThrow(/must be called inside a test body/); diff --git a/packages/e2e/tests/unit/select.test.ts b/packages/e2e/tests/unit/select.test.ts index c9ff8fc390..4fa3efd381 100644 --- a/packages/e2e/tests/unit/select.test.ts +++ b/packages/e2e/tests/unit/select.test.ts @@ -257,6 +257,33 @@ describe('resolveOptions', () => { expect(options.requires).toEqual(['web']); expect(options.session).toBe('b'); }); + + it('expects a test to fail when it or any group marks it, the innermost reason first', async () => { + const col = await collection(() => { + test.describe('legacy', { fail: 'legacy checkout' }, () => { + test('inherits', noop); + test('own reason', { fail: 'card form' }, noop); + test('bare mark keeps the group reason', { fail: true }, noop); + test('false does not unmark', { fail: false }, noop); + test('blank reason keeps the group reason', { fail: ' ' }, noop); + test.describe.fail('inner bare', () => test('nested', noop)); + test.describe('inner false', { fail: false }, () => test('still marked', noop)); + }); + test.describe.fail('no reason', () => test('default', noop)); + test.describe('plain', () => test('unmarked', noop)); + }); + expect(col.tests.map((entry) => resolveOptions(entry, config()).expectedFailure)).toEqual([ + 'legacy checkout', + 'card form', + 'legacy checkout', + 'legacy checkout', + 'legacy checkout', + 'legacy checkout', + 'legacy checkout', + 'expected to fail', + undefined, + ]); + }); }); describe('select', () => { diff --git a/plugins/e2e/skills/e2e/references/writing-tests.md b/plugins/e2e/skills/e2e/references/writing-tests.md index 5a8e48481e..3a011efa02 100644 --- a/plugins/e2e/skills/e2e/references/writing-tests.md +++ b/plugins/e2e/skills/e2e/references/writing-tests.md @@ -135,6 +135,7 @@ test.fixme('not yet', async () => {}); // test.skip's three forms; reported skip test('big import', async () => { test.setTimeout(180_000); }); // body or beforeEach: the attempt's timeout, counted from its start; in beforeAll: that hook's own test.fail('known gap', async () => {}); // expected to fail: a test failure passes it, a pass fails it with UNEXPECTED_PASS test('gap on web', async ({ platform }) => { test.fail(platform === 'web', 'known gap'); }); // marks, does not throw; the body runs on +describe.fail('legacy', () => {}); // every test inside expected to fail; a reason: describe('legacy', { fail: 'reason' }, fn) test.setup('sign in', { sessions: ['admin'] }, async ({ app, screen, session }) => {}); // see Sign-in sessions const wsTest = test.extend<{ ws: Ws }>({ ws: async ({ browser }, use) => { await use(await seed()); await drop(); } }); wsTest('uses the workspace', async ({ ws }) => {}); // code after use() is teardown, runs after failures too @@ -153,7 +154,7 @@ or a blocked agent verdict still fails the test. | `retries` | `config.retries` | 0 to 10; a serial group's value applies to its members. | | `tags` | `[]` | Distinct, non-blank, no comma or edge whitespace (`'Login Form'` is fine); union across layers. `--tag smoke` selects, `--tag-mode all` requires every tag. | | `skip` | unset | `true` or a reason string. | -| `fail` | unset | `true` or a reason string: expected to fail, as `test.fail`. Tests only, not groups or setup tests. | +| `fail` | unset | `true` or a reason string: expected to fail, as `test.fail`. On a group, marks every test in it; not on setup tests or on or inside a serial group. | | `platforms` | unset | Only targets with these platforms, e.g. `['ios']`. | | `requires` | `[]` | Engine capabilities, e.g. `['browser']`; missing ones skip the test at selection rather than failing it with `UNSUPPORTED_CAPABILITY`. | | `session` | unset | Restore state saved by a setup test. | diff --git a/skills/e2e/references/writing-tests.md b/skills/e2e/references/writing-tests.md index 5a8e48481e..3a011efa02 100644 --- a/skills/e2e/references/writing-tests.md +++ b/skills/e2e/references/writing-tests.md @@ -135,6 +135,7 @@ test.fixme('not yet', async () => {}); // test.skip's three forms; reported skip test('big import', async () => { test.setTimeout(180_000); }); // body or beforeEach: the attempt's timeout, counted from its start; in beforeAll: that hook's own test.fail('known gap', async () => {}); // expected to fail: a test failure passes it, a pass fails it with UNEXPECTED_PASS test('gap on web', async ({ platform }) => { test.fail(platform === 'web', 'known gap'); }); // marks, does not throw; the body runs on +describe.fail('legacy', () => {}); // every test inside expected to fail; a reason: describe('legacy', { fail: 'reason' }, fn) test.setup('sign in', { sessions: ['admin'] }, async ({ app, screen, session }) => {}); // see Sign-in sessions const wsTest = test.extend<{ ws: Ws }>({ ws: async ({ browser }, use) => { await use(await seed()); await drop(); } }); wsTest('uses the workspace', async ({ ws }) => {}); // code after use() is teardown, runs after failures too @@ -153,7 +154,7 @@ or a blocked agent verdict still fails the test. | `retries` | `config.retries` | 0 to 10; a serial group's value applies to its members. | | `tags` | `[]` | Distinct, non-blank, no comma or edge whitespace (`'Login Form'` is fine); union across layers. `--tag smoke` selects, `--tag-mode all` requires every tag. | | `skip` | unset | `true` or a reason string. | -| `fail` | unset | `true` or a reason string: expected to fail, as `test.fail`. Tests only, not groups or setup tests. | +| `fail` | unset | `true` or a reason string: expected to fail, as `test.fail`. On a group, marks every test in it; not on setup tests or on or inside a serial group. | | `platforms` | unset | Only targets with these platforms, e.g. `['ios']`. | | `requires` | `[]` | Engine capabilities, e.g. `['browser']`; missing ones skip the test at selection rather than failing it with `UNSUPPORTED_CAPABILITY`. | | `session` | unset | Restore state saved by a setup test. | From 252bce6bb6af5db0079288076c7255c8b2c93aa3 Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Wed, 18 Nov 2026 14:23:23 +0530 Subject: [PATCH 2/6] test(collect): check an inner group's fail reason wins over an outer one --- packages/e2e/tests/unit/select.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/e2e/tests/unit/select.test.ts b/packages/e2e/tests/unit/select.test.ts index 4fa3efd381..d83d904140 100644 --- a/packages/e2e/tests/unit/select.test.ts +++ b/packages/e2e/tests/unit/select.test.ts @@ -268,6 +268,7 @@ describe('resolveOptions', () => { test('blank reason keeps the group reason', { fail: ' ' }, noop); test.describe.fail('inner bare', () => test('nested', noop)); test.describe('inner false', { fail: false }, () => test('still marked', noop)); + test.describe('inner reason', { fail: 'coupon API' }, () => test('nested reason', noop)); }); test.describe.fail('no reason', () => test('default', noop)); test.describe('plain', () => test('unmarked', noop)); @@ -280,6 +281,7 @@ describe('resolveOptions', () => { 'legacy checkout', 'legacy checkout', 'legacy checkout', + 'coupon API', 'expected to fail', undefined, ]); From cebd9286137e9c6445098a3fdc8f85b618e1cca6 Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Wed, 18 Nov 2026 16:40:54 +0530 Subject: [PATCH 3/6] fix(test): type describe without a cast and point the test.fail error at describe.fail The collection error for test.fail(condition) outside a body now names describe.fail and the describe option, since a migrating Playwright user hits it first. The Playwright migrate row gains the conditional form, and the ja/zh rows take cubic's translations. --- docs/ja/migrate/playwright.mdx | 2 +- docs/migrate/playwright.mdx | 2 +- docs/zh/migrate/playwright.mdx | 2 +- packages/core/src/internal/expected-failure.ts | 2 +- packages/e2e/src/collect/registry.ts | 7 ++++--- packages/e2e/tests/unit/registry.test.ts | 1 + 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/ja/migrate/playwright.mdx b/docs/ja/migrate/playwright.mdx index 16b5e8222f..8a8c9d53d7 100644 --- a/docs/ja/migrate/playwright.mdx +++ b/docs/ja/migrate/playwright.mdx @@ -166,7 +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)` | -| `test.fail()` on a describe | `test.describe.fail(title, fn)`, or `{ fail: 'reason' }` on the group | +| 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 番目の型引数で型を指定 | diff --git a/docs/migrate/playwright.mdx b/docs/migrate/playwright.mdx index 94ebf39db4..b0ae63f759 100644 --- a/docs/migrate/playwright.mdx +++ b/docs/migrate/playwright.mdx @@ -177,7 +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 | +| `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` | diff --git a/docs/zh/migrate/playwright.mdx b/docs/zh/migrate/playwright.mdx index a912c66cc0..ad883102a7 100644 --- a/docs/zh/migrate/playwright.mdx +++ b/docs/zh/migrate/playwright.mdx @@ -166,7 +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)` | -| `test.fail()` on a describe | `test.describe.fail(title, fn)`, or `{ fail: 'reason' }` on the group | +| 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` 的第二个类型参数提供类型 | diff --git a/packages/core/src/internal/expected-failure.ts b/packages/core/src/internal/expected-failure.ts index 767d25f489..7c7d295c79 100644 --- a/packages/core/src/internal/expected-failure.ts +++ b/packages/core/src/internal/expected-failure.ts @@ -39,7 +39,7 @@ export function markRunningTestExpectedToFail(condition: boolean, reason: string const attempt = currentAttempt(); if (attempt === undefined) { throw new CollectionError( - 'test.fail(condition, reason) marks the running test and must be called inside a test body; to mark at collection, use test.fail(title, fn) or pass { fail: true } or a reason string as the test option', + 'test.fail(condition, reason) marks the running test and must be called inside a test body; to mark at collection, use test.fail(title, fn) or describe.fail(title, fn), or pass { fail: true } or a reason string as the test or describe option', ); } if (!condition) return; diff --git a/packages/e2e/src/collect/registry.ts b/packages/e2e/src/collect/registry.ts index 326bc6e6b1..ddd6c0dab8 100644 --- a/packages/e2e/src/collect/registry.ts +++ b/packages/e2e/src/collect/registry.ts @@ -21,6 +21,7 @@ import { checkDeclaredFixtures, describeFixture, describeUser } from './fixture- import type { DescribeAPI, DescribeOptions, + DescribeRegistrar, EachFn, EachRegistrar, FixtureFn, @@ -828,7 +829,7 @@ function createTestAPI(chain: readonly FixtureDefinition[]): TestAPI { }; /** The `describe()` call forms; `describe.fail` marks the group as if it had `fail: true`, so it takes no `fail` of its own. */ - const groupRegistrar = (api: string, fail: boolean) => ( + const groupRegistrar = (api: string, fail: boolean): DescribeRegistrar => ( title: string, optionsOrBody: DescribeOptions | (() => Result), maybeBody?: () => Result, @@ -844,9 +845,9 @@ function createTestAPI(chain: readonly FixtureDefinition[]): TestAPI { } collector.registerDescribe(title, marks ? { ...given, fail: true } : given, body, api); }; - const describe = Object.assign(groupRegistrar('describe()', false), { + const describe: DescribeAPI = Object.assign(groupRegistrar('describe()', false), { fail: groupRegistrar('describe.fail()', true), - }) as DescribeAPI; + }); const api: TestAPI = Object.assign(testFunction, { skip(first?: string | boolean, second?: TestBody | string): TestCase | undefined { diff --git a/packages/e2e/tests/unit/registry.test.ts b/packages/e2e/tests/unit/registry.test.ts index 903cf1c543..027c52ebdd 100644 --- a/packages/e2e/tests/unit/registry.test.ts +++ b/packages/e2e/tests/unit/registry.test.ts @@ -532,6 +532,7 @@ describe('registration', () => { it('rejects test.fail(condition) outside a test body', async () => { expect(() => test.fail(true, 'not here')).toThrow(CollectionError); expect(() => test.fail(false)).toThrow(/must be called inside a test body/); + expect(() => test.fail(false)).toThrow(/describe\.fail\(title, fn\).*test or describe option/); }); it('validates titles', async () => { From f7230c62dd3314bff52b0910e865dfaeaf160967 Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Fri, 20 Nov 2026 18:19:41 +0530 Subject: [PATCH 4/6] fix(test): validate describe.fail options before adding the mark describe.fail copied its options with a spread before validation, so an array or a non-enumerable bad key passed where describe() rejects it. The caller's options are now validated first, then again with fail: true for the serial rules. The fail docs now say true or any string marks, since a blank string marks too. --- docs/ja/reference/test.mdx | 7 ++++--- docs/reference/test.mdx | 9 +++++---- docs/zh/reference/test.mdx | 7 ++++--- packages/core/src/types.ts | 5 +++-- packages/e2e/src/collect/registry.ts | 9 +++++++-- packages/e2e/tests/unit/registry.test.ts | 7 +++++++ 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/docs/ja/reference/test.mdx b/docs/ja/reference/test.mdx index ecc83b43f5..85049ad53a 100644 --- a/docs/ja/reference/test.mdx +++ b/docs/ja/reference/test.mdx @@ -542,7 +542,7 @@ test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app }) #### `fail` -テストの失敗を期待します。[`test.fail`](#test-fail) を参照してください。文字列は理由になります。 Any truthy layer marks, and the innermost reason wins. Not allowed on or inside a serial group. +テストの失敗を期待します。[`test.fail`](#test-fail) を参照してください。文字列は理由になります。 A layer with `true` or any string marks, and the innermost reason wins. Not allowed on or inside a serial group. ```ts test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); @@ -1023,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`. Any truthy layer - * marks; the innermost reason wins. Not allowed on or 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 or inside a + * serial group. */ fail?: boolean | string; /** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */ diff --git a/docs/reference/test.mdx b/docs/reference/test.mdx index 329624910b..cffec2e904 100644 --- a/docs/reference/test.mdx +++ b/docs/reference/test.mdx @@ -656,8 +656,8 @@ 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. Any truthy layer marks, and the innermost reason wins. Not allowed on -or inside a serial group. +reason. A layer with `true` or any string marks, and the innermost reason +wins. Not allowed on or inside a serial group. ```ts test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); @@ -1230,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`. Any truthy layer - * marks; the innermost reason wins. Not allowed on or 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 or inside a + * serial group. */ fail?: boolean | string; /** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */ diff --git a/docs/zh/reference/test.mdx b/docs/zh/reference/test.mdx index cbd9a1f97b..52fa0f853b 100644 --- a/docs/zh/reference/test.mdx +++ b/docs/zh/reference/test.mdx @@ -542,7 +542,7 @@ test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app }) #### `fail` -预期测试失败;参阅 [`test.fail`](#test-fail)。字符串表示原因。 Any truthy layer marks, and the innermost reason wins. Not allowed on or inside a serial group. +预期测试失败;参阅 [`test.fail`](#test-fail)。字符串表示原因。 A layer with `true` or any string marks, and the innermost reason wins. Not allowed on or inside a serial group. ```ts test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); @@ -1023,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`. Any truthy layer - * marks; the innermost reason wins. Not allowed on or 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 or inside a + * serial group. */ fail?: boolean | string; /** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */ diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 5fb43e777a..9221b0e9ac 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -755,8 +755,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`. Any truthy layer - * marks; the innermost reason wins. Not allowed on or 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 or inside a + * serial group. */ fail?: boolean | string; /** Focuses the test locally. CI rejects it with `ONLY_IN_CI`. */ diff --git a/packages/e2e/src/collect/registry.ts b/packages/e2e/src/collect/registry.ts index ddd6c0dab8..5bd537c50c 100644 --- a/packages/e2e/src/collect/registry.ts +++ b/packages/e2e/src/collect/registry.ts @@ -255,11 +255,16 @@ class Collector { return Object.freeze({ [testCaseBrand]: true as const }); } - registerDescribe(title: string, options: DescribeOptions, body: () => unknown, api = 'describe()'): void { + registerDescribe(title: string, options: DescribeOptions, body: () => unknown, api = 'describe()', markFail = false): void { this.assertOpen(api); const normalizedTitle = this.title(title); if (typeof body !== 'function') throw new CollectionError('describe body must be a function'); validateDescribeOptions(options, this.currentGroup); + // The caller's own options are checked first: the copy that adds the mark keeps only enumerable keys. + if (markFail) { + options = { ...options, fail: true }; + validateDescribeOptions(options, this.currentGroup); + } const group: GroupNode = { title: normalizedTitle, options, @@ -843,7 +848,7 @@ function createTestAPI(chain: readonly FixtureDefinition[]): TestAPI { if (marks && given.fail !== undefined) { throw new CollectionError(`${api} takes no fail option; give a reason with describe(title, { fail: 'reason' }, fn)`); } - collector.registerDescribe(title, marks ? { ...given, fail: true } : given, body, api); + collector.registerDescribe(title, given, body, api, marks); }; const describe: DescribeAPI = Object.assign(groupRegistrar('describe()', false), { fail: groupRegistrar('describe.fail()', true), diff --git a/packages/e2e/tests/unit/registry.test.ts b/packages/e2e/tests/unit/registry.test.ts index 027c52ebdd..8e259f72cf 100644 --- a/packages/e2e/tests/unit/registry.test.ts +++ b/packages/e2e/tests/unit/registry.test.ts @@ -508,6 +508,12 @@ describe('registration', () => { await expect(collectModule(async () => test.describe('group', { fail: 1 } as never, () => {}))).rejects.toThrow( 'describe options: fail must be true, false, or a reason string, got 1', ); + // describe.fail rejects what describe() rejects, including keys a spread would drop. + const hidden = Object.defineProperty({}, 'bogus', { value: 1, enumerable: false }); + for (const [options, message] of [[[], 'unknown key "length"'], [hidden, 'unknown key "bogus"']] as const) { + await expect(collectModule(async () => test.describe('group', options as never, () => {}))).rejects.toThrow(message); + await expect(collectModule(async () => test.describe.fail('group', options as never, () => {}))).rejects.toThrow(message); + } for (const fail of ['legacy checkout', false, 1]) { await expect(collectModule(async () => test.describe.fail('group', { fail } as never, () => {}))).rejects.toThrow( "describe.fail() takes no fail option; give a reason with describe(title, { fail: 'reason' }, fn)", @@ -518,6 +524,7 @@ describe('registration', () => { it('refuses fail on, inside, or around a serial group', async () => { const serialRule = 'describe option "fail" cannot be set on or inside a serial group, which runs as one unit'; await expect(collectModule(async () => test.describe('unit', { serial: true, fail: true }, () => {}))).rejects.toThrow(serialRule); + await expect(collectModule(async () => test.describe.fail('unit', { serial: true }, () => {}))).rejects.toThrow(serialRule); await expect( collectModule(async () => test.describe('unit', { serial: true }, () => test.describe.fail('inner', () => {}))), ).rejects.toThrow(serialRule); From 618564f7b4a95d9b514a6d1b23294958f640339b Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Fri, 20 Nov 2026 18:24:21 +0530 Subject: [PATCH 5/6] docs(test): say fail is refused around a serial group too --- docs/ja/reference/test.mdx | 6 +++--- docs/reference/test.mdx | 6 +++--- docs/zh/reference/test.mdx | 6 +++--- packages/core/src/types.ts | 4 ++-- plugins/e2e/skills/e2e/references/writing-tests.md | 2 +- skills/e2e/references/writing-tests.md | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/ja/reference/test.mdx b/docs/ja/reference/test.mdx index 85049ad53a..f3d2371355 100644 --- a/docs/ja/reference/test.mdx +++ b/docs/ja/reference/test.mdx @@ -542,7 +542,7 @@ test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app }) #### `fail` -テストの失敗を期待します。[`test.fail`](#test-fail) を参照してください。文字列は理由になります。 A layer with `true` or any string marks, and the innermost reason wins. Not allowed on or inside a serial group. +テストの失敗を期待します。[`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 }) => {}); @@ -1024,8 +1024,8 @@ export interface TestOptions { /** * Expects the test to fail; a string is the reason. A test failure then * 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 or inside a - * serial group. + * 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`. */ diff --git a/docs/reference/test.mdx b/docs/reference/test.mdx index cffec2e904..98664b8539 100644 --- a/docs/reference/test.mdx +++ b/docs/reference/test.mdx @@ -657,7 +657,7 @@ test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app }) Expects the test to fail; see [`test.fail`](#test-fail). A string is the reason. A layer with `true` or any string marks, and the innermost reason -wins. Not allowed on or inside a serial group. +wins. Not allowed on, inside, or around a serial group. ```ts test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); @@ -1231,8 +1231,8 @@ export interface TestOptions { /** * Expects the test to fail; a string is the reason. A test failure then * 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 or inside a - * serial group. + * 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`. */ diff --git a/docs/zh/reference/test.mdx b/docs/zh/reference/test.mdx index 52fa0f853b..fca8663904 100644 --- a/docs/zh/reference/test.mdx +++ b/docs/zh/reference/test.mdx @@ -542,7 +542,7 @@ test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app }) #### `fail` -预期测试失败;参阅 [`test.fail`](#test-fail)。字符串表示原因。 A layer with `true` or any string marks, and the innermost reason wins. Not allowed on or inside a serial group. +预期测试失败;参阅 [`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 }) => {}); @@ -1024,8 +1024,8 @@ export interface TestOptions { /** * Expects the test to fail; a string is the reason. A test failure then * 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 or inside a - * serial group. + * 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`. */ diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 9221b0e9ac..4becb88aa4 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -756,8 +756,8 @@ export interface TestOptions { /** * Expects the test to fail; a string is the reason. A test failure then * 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 or inside a - * serial group. + * 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`. */ diff --git a/plugins/e2e/skills/e2e/references/writing-tests.md b/plugins/e2e/skills/e2e/references/writing-tests.md index 3a011efa02..e33571597d 100644 --- a/plugins/e2e/skills/e2e/references/writing-tests.md +++ b/plugins/e2e/skills/e2e/references/writing-tests.md @@ -154,7 +154,7 @@ or a blocked agent verdict still fails the test. | `retries` | `config.retries` | 0 to 10; a serial group's value applies to its members. | | `tags` | `[]` | Distinct, non-blank, no comma or edge whitespace (`'Login Form'` is fine); union across layers. `--tag smoke` selects, `--tag-mode all` requires every tag. | | `skip` | unset | `true` or a reason string. | -| `fail` | unset | `true` or a reason string: expected to fail, as `test.fail`. On a group, marks every test in it; not on setup tests or on or inside a serial group. | +| `fail` | unset | `true` or a reason string: expected to fail, as `test.fail`. On a group, marks every test in it; not on setup tests or on, inside, or around a serial group. | | `platforms` | unset | Only targets with these platforms, e.g. `['ios']`. | | `requires` | `[]` | Engine capabilities, e.g. `['browser']`; missing ones skip the test at selection rather than failing it with `UNSUPPORTED_CAPABILITY`. | | `session` | unset | Restore state saved by a setup test. | diff --git a/skills/e2e/references/writing-tests.md b/skills/e2e/references/writing-tests.md index 3a011efa02..e33571597d 100644 --- a/skills/e2e/references/writing-tests.md +++ b/skills/e2e/references/writing-tests.md @@ -154,7 +154,7 @@ or a blocked agent verdict still fails the test. | `retries` | `config.retries` | 0 to 10; a serial group's value applies to its members. | | `tags` | `[]` | Distinct, non-blank, no comma or edge whitespace (`'Login Form'` is fine); union across layers. `--tag smoke` selects, `--tag-mode all` requires every tag. | | `skip` | unset | `true` or a reason string. | -| `fail` | unset | `true` or a reason string: expected to fail, as `test.fail`. On a group, marks every test in it; not on setup tests or on or inside a serial group. | +| `fail` | unset | `true` or a reason string: expected to fail, as `test.fail`. On a group, marks every test in it; not on setup tests or on, inside, or around a serial group. | | `platforms` | unset | Only targets with these platforms, e.g. `['ios']`. | | `requires` | `[]` | Engine capabilities, e.g. `['browser']`; missing ones skip the test at selection rather than failing it with `UNSUPPORTED_CAPABILITY`. | | `session` | unset | Restore state saved by a setup test. | From 5a077de8c69a4f8ce55773329e10d1c5a1f54de5 Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Sat, 21 Nov 2026 10:43:56 +0530 Subject: [PATCH 6/6] refactor(test): validate describe options in one pass describe.fail no longer validates twice: the serial check takes the mark into account, and registerDescribe takes api and markFail without defaults. --- packages/e2e/src/collect/registry.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/e2e/src/collect/registry.ts b/packages/e2e/src/collect/registry.ts index 5bd537c50c..5af5b66a0a 100644 --- a/packages/e2e/src/collect/registry.ts +++ b/packages/e2e/src/collect/registry.ts @@ -255,16 +255,13 @@ class Collector { return Object.freeze({ [testCaseBrand]: true as const }); } - registerDescribe(title: string, options: DescribeOptions, body: () => unknown, api = 'describe()', markFail = false): void { + registerDescribe(title: string, given: DescribeOptions, body: () => unknown, api: string, markFail: boolean): void { this.assertOpen(api); const normalizedTitle = this.title(title); if (typeof body !== 'function') throw new CollectionError('describe body must be a function'); - validateDescribeOptions(options, this.currentGroup); - // The caller's own options are checked first: the copy that adds the mark keeps only enumerable keys. - if (markFail) { - options = { ...options, fail: true }; - validateDescribeOptions(options, this.currentGroup); - } + // The caller's own options are checked, not the copy that adds the mark, which keeps only enumerable keys. + validateDescribeOptions(given, this.currentGroup, markFail); + const options = markFail ? { ...given, fail: true } : given; const group: GroupNode = { title: normalizedTitle, options, @@ -540,14 +537,14 @@ function validateFailOption(fail: unknown, label: string): void { } } -function validateDescribeOptions(options: DescribeOptions, parent: GroupNode | undefined): void { +function validateDescribeOptions(options: DescribeOptions, parent: GroupNode | undefined, markFail: boolean): void { validateCommonOptions(options, 'describe options', DESCRIBE_OPTION_KEYS); validateFailOption(options.fail, 'describe options'); if (options.serial === true && insideSerial(parent)) { throw new CollectionError('nested serial groups are collection errors'); } // A serial group's members cannot be marked expected to fail, so neither can the group. - if (options.fail !== undefined && (options.serial === true || insideSerial(parent))) { + if ((markFail || options.fail !== undefined) && (options.serial === true || insideSerial(parent))) { throw new CollectionError('describe option "fail" cannot be set on or inside a serial group, which runs as one unit'); } if (options.serial === true && groupChain(parent).some((group) => expectedFailureOption(group.options.fail) !== undefined)) {