> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# test

> टेस्ट, सेटअप टेस्ट, ग्रुप, हुक, ऑप्शन, और फ़िक्स्चर।

`test` टेस्ट, सेटअप टेस्ट, ग्रुप, और हुक डिक्लेयर करता है। टेस्ट फ़ाइल इंपोर्ट
होते समय डिक्लेरेशन सिंक्रोनस चलते हैं। फ़िक्स्चर जोड़ने के लिए `test.extend` और
रजिस्ट्रेशन या बॉडी के दौरान टेस्ट स्किप करने के लिए `test.skip` इस्तेमाल करें।

```ts title="tests/checkout.e2e.ts"

describe('checkout', { tags: ['billing'] }, () => {
  beforeEach(async ({ app }) => {
    await app.open('/checkout');
  });

  test('pays with a saved card', { retries: 2 }, async ({ screen }) => {
    await screen.getByRole('button', 'Pay').tap();
    await expect(screen.getByText('Payment received')).toBeVisible();
  });
});
```

## रेफ़रेंस

### मेंबर

| मेंबर | रिटर्न |
| --- | --- |
| [`test`](#test) | `TestCase` |
| [`test.skip`](#test-skip) | `TestCase \| void` |
| [`test.fixme`](#test-fixme) | `TestCase \| void` |
| [`test.skipIf`](#test-skipif) | `TestRegistrar` |
| [`test.runIf`](#test-runif) | `TestRegistrar` |
| [`test.each`](#test-each) | `EachRegistrar` |
| [`test.for`](#test-for) | `EachRegistrar` |
| [`test.fail`](#test-fail) | `TestCase \| void` |
| [`test.setTimeout`](#test-settimeout) | `void` |
| [`test.slow`](#test-slow) | `void` |
| [`test.only`](#test-only) | `TestCase` |
| [`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'`।

- `e2e` से इंपोर्ट किया गया प्रति-टेस्ट हुक उन [बिल्ट-इन फ़िक्स्चर](#fixtures) के
  साथ टाइप्ड होता है जो हर इंजन में होते हैं।
- `@e2e-dev/web`, `@e2e-dev/mobile`, और `@e2e-dev/desktop` अपने `browser`,
  `device`, या `desktop` फ़िक्स्चर के साथ टाइप्ड `test`, `describe`, और चारों हुक
  एक्सपोर्ट करते हैं, ताकि टेस्ट फ़ाइल एक ही इंपोर्ट से रजिस्टर कर सके।
- अपने फ़िक्स्चर से एक्सटेंड किए गए `test` के हुक उन्हें `test.beforeEach` के
  ज़रिए देखते हैं।

मॉड्यूल इवैल्यूएशन के बाहर टेस्ट, ग्रुप, या हुक रजिस्टर करने पर
`COLLECTION_ERROR` थ्रो होता है। पूरे डिक्लेरेशन [टाइप](#types) के नीचे हैं।

#### `test`

[ऑप्शन](#options) के साथ या बिना एक टेस्ट रजिस्टर करता है।

```ts

test('app opens', async ({ app, browser }) => {
  await app.open();
  await expect(browser).toHaveURL('/');
});

test('checks out', { tags: ['billing'], retries: 2, timeout: 60_000 }, async ({ app }) => {
  await app.open('/checkout');
});
```

टेस्ट या ग्रुप का टाइटल NFC नॉर्मलाइज़ेशन के बाद 1 से 512 UTF-8 बाइट का होता है,
और उसमें NUL कैरेक्टर नहीं हो सकता।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | एक फ़ाइल के दो टेस्ट का टाइटल पाथ एक जैसा हो: ग्रुप के टाइटल और फिर टेस्ट का अपना टाइटल। |

#### `test.skip`

स्किप किया हुआ टेस्ट रजिस्टर करता है, या चल रहे टेस्ट को स्किप करता है।

```ts
test.skip('exports a PDF', async ({ app }) => {}); // at registration
test.skip(organizations.length < 2, 'a single organization'); // inside a body
test.skip('not on this tenant'); // inside a body, always
```

- स्किप किया गया टेस्ट डिफ़ॉल्ट रूप से एग्ज़िट कोड पर असर नहीं डालता।
- कलेक्शन के समय ऑप्शन से स्किप करने के लिए [`skip`](#skip) ऑप्शन इस्तेमाल करें।
- रजिस्ट्रेशन पर यह `TestCase` लौटाता है; बॉडी के अंदर `void`।

रनटाइम पर पता चलने वाली कंडीशन (जैसे डिसेबल्ड फ़ीचर फ़्लैग) के लिए टेस्ट के
अंदर `test.skip(condition, reason)` कॉल करें:

```ts
test('switches organizations', { session: 'admin' }, async ({ app, agent }) => {
  const organizations = await listOrganizations();
  test.skip(organizations.length < 2, 'the demo tenant has a single organization');
  await app.open('/backend');
  await agent.act(`switch to the organization "${organizations[1].name}"`);
});
```

- कंडीशन सही होने पर यह कॉल थ्रो करती है, Playwright की तरह। इसके बाद का कुछ भी
  नहीं चलता।
- इससे पहले कोई फ़ेलियर न हो तो टेस्ट `reason` के साथ `skipped` रिपोर्ट होता है,
  बिना रीट्राई के।
- इससे पहले चले स्टेप रिपोर्ट में वैसे ही बने रहते हैं।
- कॉल से पहले फ़ेल हुआ `expect.soft` तब भी अटेम्प्ट को फ़ेल करता है, Playwright
  की तरह। अटेम्प्ट `failed` होता है, सॉफ़्ट फ़ेलियर उसका एरर बनते हैं और स्किप
  कारण उसके `skip` में रहता है। यह किसी भी फ़ेलियर की तरह रीट्राई होता है।
- हुक और फ़िक्स्चर तब भी अपना टियरडाउन चलाते हैं।
- जब कंडीशन कोई प्रीकंडीशन हो, तो इसे किसी भी स्टेप से पहले कॉल करें।
- फ़ेल अटेम्प्ट के बाद रीट्राई पर स्किप होने से टेस्ट `skipped` रहता है। CLI इसे
  इसके मूल एरर के साथ `Skipped After Failure` में दिखाता है। ऐसे मामले में रन को
  एग्ज़िट कोड 1 से फ़ेल करने के लिए [`failOnSkippedFailure: true`](https://e2e.com/docs/hi/reference/config)
  सेट करें। डिफ़ॉल्ट `false` है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `INVALID_ARGUMENT` | सेटअप टेस्ट में सही कंडीशन या बिना कंडीशन के कॉल। सेटअप टेस्ट स्किप नहीं हो सकता क्योंकि बाकी टेस्ट उसके सेशन पर निर्भर हैं। |
| `COLLECTION_ERROR` | टेस्ट बॉडी के बाहर कंडीशनल रूप। |
| `COLLECTION_ERROR` | सीरियल ग्रुप के अंदर रजिस्ट्रेशन रूप। इसकी जगह सीरियल `describe` पर [`skip`](#skip) सेट करें। |

#### `test.fixme`

fixme मार्क किया हुआ स्किप टेस्ट रजिस्टर करता है, या चल रहे टेस्ट को fixme के
रूप में स्किप करता है।

```ts
test.fixme('exports a PDF', async ({ app }) => {}); // at registration
test.fixme(platform === 'android', 'crashes on Android'); // inside a body
test.fixme(); // inside a body, always
```

- यह [`test.skip`](#test-skip) वाले ही तीन रूप लेता है, और इसके बॉडी रूप पर वही
  नियम लागू होते हैं।
- टेस्ट `skipped` रिपोर्ट होता है, और `report.json` में `skip.cause` `fixme`
  होता है (जहाँ `test.skip` `explicit` रिपोर्ट करता है)। कारण `fixme` होता है,
  या बॉडी के अंदर गैर-खाली कारण देने पर `fixme: <reason>`। list रिपोर्टर इसे
  `[fixme: crashes on Android]` दिखाता है।
- रजिस्ट्रेशन रूप कोई टेस्ट ऑप्शन नहीं लेता।
- रजिस्ट्रेशन पर यह `TestCase` लौटाता है; बॉडी के अंदर `void`।

| क्या थ्रो होता है | कब |
| --- | --- |
| `INVALID_ARGUMENT` | सेटअप टेस्ट में सही कंडीशन या बिना कंडीशन के कॉल। सेटअप टेस्ट स्किप नहीं हो सकता क्योंकि बाकी टेस्ट उसके सेशन पर निर्भर हैं। |
| `COLLECTION_ERROR` | टेस्ट बॉडी के बाहर कंडीशनल रूप। कलेक्शन पर `test.fixme(title, fn)` इस्तेमाल करें। |
| `COLLECTION_ERROR` | सीरियल ग्रुप के अंदर रजिस्ट्रेशन रूप। इसकी जगह सीरियल `describe` पर [`skip`](#skip) सेट करें। |

#### `test.skipIf`

एक फ़ंक्शन लौटाता है जो `test(title, fn)` की तरह एक टेस्ट रजिस्टर करता है, और
कंडीशन ट्रूदी होने पर उसे स्किप करता है।

```ts
test.skipIf(process.platform === 'win32')('watches files', async ({ app }) => {});
test.skipIf(process.env.CI)('opens the system dialog', async ({ app }) => {});
```

- फ़ाइल कलेक्ट होते समय कॉल पर कंडीशन एक बार पढ़ी जाती है। उस वक्त पता रहने वाली
  वैल्यू इस्तेमाल करें, जैसे `process.platform` या एनवायरनमेंट वेरिएबल। रनटाइम पर
  पता चलने वाली कंडीशन के लिए बॉडी के अंदर [`test.skip(condition, reason)`](#test-skip)
  कॉल करें।
- Vitest की तरह कोई भी ट्रूदी वैल्यू स्किप करती है।
- स्किप हुआ टेस्ट `test(title, { skip: true }, fn)` जैसा ही है: उसकी बॉडी कभी
  नहीं चलती, और उसके बाकी ऑप्शन बने रहते हैं।
- [`skip`](#skip) ऑप्शन कंडीशन चाहे जो हो टेस्ट को स्किप करता है, और उसकी कारण
  स्ट्रिंग रिपोर्ट होती है।
- सीरियल ग्रुप के बाहर, फ़ॉल्सी कंडीशन टेस्ट को सामान्य `test` की तरह रजिस्टर
  करती है।
- यह [`test`](#test) वाले दोनों रूप लेता है और एक्सटेंड किए गए `test` पर भी वही
  फ़िक्स्चर रखता है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | कंडीशन चाहे जो हो, सीरियल ग्रुप के अंदर कॉल। इसकी जगह सीरियल `describe` पर [`skip`](#skip) सेट करें। |
| `COLLECTION_ERROR` | कंडीशन एक Promise हो (यह टाइप एरर भी है)। कॉल से पहले उसे await करें। |

#### `test.runIf`

एक फ़ंक्शन लौटाता है जो `test(title, fn)` की तरह एक टेस्ट रजिस्टर करता है, और
कंडीशन फ़ॉल्सी होने पर उसे स्किप करता है।

```ts
test.runIf(process.platform === 'linux')('reads inotify events', async ({ app }) => {});
```

`test.runIf(condition)` ठीक `test.skipIf(!condition)` है।
[`test.skipIf`](#test-skipif) की हर बात यहाँ लागू होती है।

#### `test.each`

एक फ़ंक्शन लौटाता है जो `test(title, fn)` की तरह हर रो के लिए रो के क्रम में एक
टेस्ट रजिस्टर करता है। अलग-अलग डेटा के साथ एक ही स्टेप चलाने के लिए इसे इस्तेमाल
करें।

```ts
test.each([{ user: 'Ada' }, { user: 'Grace' }])('signs in as $user', async ({ user }, { app }) => {
  await app.open();
  // ...
});

test.each([
  ['standard', '5.00'],
  ['express', '15.00'],
])('ships %s for %s', async (speed, price, { screen }) => {});
```

- बॉडी को पहले रो और आखिर में फ़िक्स्चर मिलते हैं। जब हर रो ऐरे हो, तो हर रो
  स्प्रेड होती है, इसलिए `[speed, price]` `(speed, price, fixtures)` के रूप में
  मिलता है। जब कोई भी रो ऐरे न हो, तो Vitest और Jest की तरह हर रो पूरी मिलती है,
  `(row, fixtures)`।
- बॉडी रो के बाद वाले पैरामीटर को डीस्ट्रक्चर करके अपने [फ़िक्स्चर](#fixtures) के
  नाम देती है, और e2e सिर्फ़ उन्हीं को सेट अप करता है। जो बॉडी कोई फ़िक्स्चर न ले
  वह पैरामीटर छोड़ सकती है।
- टाइटल रो से फ़ॉर्मेट होता है:

  | टाइटल में | क्या बनता है |
  | --- | --- |
  | `$name`, `$name.path` | ऑब्जेक्ट रो की वह key। स्ट्रिंग जैसी लिखी है वैसी दिखती है, कोई भी दूसरी वैल्यू Node के `inspect` जैसी। |
  | `%s` | अगला आइटम, उसी तरह दिखाया हुआ। |
  | `%o` | अगला आइटम Node के `inspect` जैसा, इसलिए स्ट्रिंग कोट्स में होती है। |
  | `%d` | अगला आइटम नंबर के रूप में (`Number(item)`), सिवाय `BigInt` अपना `n` सफ़िक्स रखता है और `Symbol` `NaN` दिखता है। |
  | `%i`, `%f` | अगला आइटम इंटीजर या फ़्लोट के रूप में, `parseInt` / `parseFloat` की तरह: `'42px'` `42` बनता है। `%i` में `BigInt` अपना `n` सफ़िक्स रखता है। |
  | `%j` | अगला आइटम JSON के रूप में। सर्कुलर वैल्यू `[Circular]` दिखती है; फ़ंक्शन, `Symbol`, या `undefined` `undefined` दिखते हैं। |
  | `%#`, `%$` | 0 से शुरू होने वाला रो इंडेक्स, और 1 से शुरू होने वाला रो नंबर। |
  | `%%` | एक प्रतिशत चिह्न। |

  आइटम ऐरे रो के क्रम में आइटम होते हैं; कोई दूसरी रो खुद एक आइटम होती है। जिस
  प्लेसहोल्डर के लिए आइटम न बचे, या नॉन-ऑब्जेक्ट रो पर `$name`, वह जैसा लिखा है
  वैसा ही रहता है। स्ट्रिंग के अलावा हर वैल्यू एक ही लाइन में दिखती है; स्ट्रिंग
  जैसी लिखी है वैसी दिखती है, लाइन ब्रेक समेत। `Error` बिना स्टैक के अपने नाम और
  मैसेज के रूप में दिखता है।
- टाइटल टेस्ट id का हिस्सा होता है। रो जोड़ने या खिसकाने पर `%#` और `%$` बदल
  जाते हैं, इसलिए स्थिर id के लिए `$name` या वैल्यू प्लेसहोल्डर को तरजीह दें।
- टाइटल कुछ जगहों पर Vitest से अलग हैं: `$0` और `$1` ऐरे रो नहीं पढ़ते, `$name`
  ऐरे रो के पहले आइटम से नहीं पढ़ा जाता, `%s` ऑब्जेक्ट को उसके अपने `toString`
  से नहीं बल्कि `inspect` से दिखाता है (`URL` अपने href के रूप में नहीं दिखता),
  `%O` और `%c` प्लेसहोल्डर नहीं हैं, और टेम्पलेट लिटरल के रूप में लिखी टेबल नहीं
  पढ़ी जाती। बॉडी भी अलग है: Vitest की `test.each` बॉडी को सिर्फ़ रो मिलती है,
  जबकि यहाँ उसके बाद फ़िक्स्चर आते हैं।
- हर रो एक अलग टेस्ट है, अपनी id, रिपोर्ट एंट्री, और रीट्राई के साथ। ऑप्शन हर
  रो पर लागू होते हैं, इसलिए [`skip`](#skip) या [`tags`](#tags) ऑप्शन सबको स्किप
  या टैग करता है।
- यह [`test`](#test) वाले दोनों रूप लेता है और एक्सटेंड किए गए `test` पर भी वही
  फ़िक्स्चर रखता है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | रो ऐरे न हों, ऐरे खाली हो, या रो टेम्पलेट लिटरल टेबल हों। |
| `COLLECTION_ERROR` | दो रो फ़ॉर्मेट होकर एक ही टाइटल बना दें। टाइटल में ऐसा प्लेसहोल्डर रखें जो रो को अलग पहचाने। |
| `COLLECTION_ERROR` | कोई `%j` आइटम साइकल के अलावा किसी कारण से JSON न बन सके, जैसे `BigInt`। मैसेज उस रो का नाम बताता है। |
| `COLLECTION_ERROR` | बॉडी पूरे फ़िक्स्चर एक साथ ले (`async (row, fixtures) => {}`) या रेस्ट पैरामीटर में ले (`async (...args) => {}`), या कोई और [फ़िक्स्चर नेमिंग नियम](#fixtures) तोड़े। |

#### `test.for`

[`test.each`](#test-each) जैसा ही, सिवाय इसके कि ऐरे रो स्प्रेड नहीं होती: बॉडी
हमेशा `(row, fixtures)` लेती है। टाइटल उसी तरह फ़ॉर्मेट होते हैं।

```ts
test.for([
  ['standard', '5.00'],
  ['express', '15.00'],
])('ships %s for %s', async ([speed, price], { screen }) => {});
```

#### `test.fail`

ऐसा टेस्ट रजिस्टर करता है जिसके फ़ेल होने की उम्मीद है, या चल रहे टेस्ट को ऐसे
मार्क करता है।

```ts
test.fail('shows the cart badge', async ({ app, screen }) => {}); // at registration
test.fail(platform === 'web', 'tap on a display: contents element'); // inside a body
test.fail('known gap'); // inside a body, always
test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); // by option
```

पूरे ग्रुप के हर टेस्ट को मार्क करने के लिए [`describe.fail`](#describe-fail)
इस्तेमाल करें।

- कॉल के बाद बॉडी चलती रहती है। `beforeEach` हुक भी टेस्ट को मार्क कर सकता है।
- फ़ेल हुआ असर्शन, एक्शन, थ्रो हुआ एरर, या टाइमआउट टेस्ट को `passed` बना देता
  है। रिपोर्ट में कारण और एरर बने रहते हैं।
- पास होने पर टेस्ट `UNEXPECTED_PASS` के साथ `failed` होता है। कारण ठीक होने पर
  मार्क हटा दें।
- इन्फ़्रास्ट्रक्चर एरर, इंटरप्ट, फ़ेल हुआ `beforeAll` या `afterAll`, और
  `INVALID_ARGUMENT` जैसा API का गलत इस्तेमाल तब भी टेस्ट को फ़ेल करते हैं।
- उम्मीद के मुताबिक फ़ेलियर रीट्राई नहीं होता। उम्मीद से उलट पास रीट्राई होता है।
- स्किप इस मार्क पर भारी पड़ता है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `INVALID_ARGUMENT` | सेटअप टेस्ट, सीरियल ग्रुप के मेंबर, `afterEach` हुक, या फ़िक्स्चर टियरडाउन में सही कंडीशन। |
| `COLLECTION_ERROR` | टेस्ट बॉडी के बाहर कंडीशनल रूप, या सीरियल ग्रुप के अंदर `fail` ऑप्शन। |

#### `test.setTimeout`

चल रहे टेस्ट की बॉडी या `beforeEach` हुक से उसका टाइमआउट बदलता है, या
`beforeAll` हुक के अंदर से उस हुक का अपना टाइमआउट बदलता है।

```ts
test('imports a large file', async ({ app }) => {
  test.setTimeout(180_000);
  await app.open('/import');
});
```

- नया टाइमआउट [`timeout`](#timeout) ऑप्शन की तरह अटेम्प्ट की शुरुआत से गिना जाता
  है, और इस अटेम्प्ट के लिए उसकी जगह लेता है। रीट्राई फिर से ऑप्शन से शुरू होता
  है।
- पहले खर्च हो चुके समय से छोटा टाइमआउट देने पर टेस्ट तुरंत टाइमआउट हो जाता है।
- `beforeAll` हुक में यह उस हुक के टाइमआउट (कॉन्फ़िग `timeout`, हुक की शुरुआत से
  गिना हुआ) की जगह लेता है। टेस्ट अपना खुद का टाइमआउट बनाए रखते हैं।
- `afterEach` और `afterAll` हुक और फ़िक्स्चर टियरडाउन `cleanupTimeout` पर चलते
  हैं, इसलिए वे इसे नहीं बदल सकते।
- [`host.openSession`](https://e2e.com/docs/hi/reference/runner#host-opensession) से खुला सेशन कोई e2e
  टेस्ट नहीं चलाता, इसलिए वह भी इसे नहीं बदल सकता। `host.openSession` को
  `timeout` पास करें।
- बिना टाइमआउट के लिए `0` नहीं है। इसकी जगह कोई बड़ी वैल्यू पास करें।

| क्या थ्रो होता है | कब |
| --- | --- |
| `INVALID_ARGUMENT` | ऐसा टाइमआउट जो मिलीसेकंड का पॉज़िटिव सेफ़ इंटीजर न हो, 2147483647 से बड़ा हो, या `afterEach`/`afterAll` हुक, फ़िक्स्चर टियरडाउन, या होस्टेड सेशन से कॉल हो; या टेस्ट या हुक खत्म होने के बाद छूटे कोड से कॉल हो। |
| `COLLECTION_ERROR` | चल रहे टेस्ट या हुक के बाहर कॉल। वहाँ `timeout` ऑप्शन इस्तेमाल करें। |

#### `test.slow`

चल रहे टेस्ट का टाइमआउट तिगुना करता है, जैसे Playwright का `test.slow()` करता
है। इसे टेस्ट बॉडी या `beforeEach` हुक से कॉल करें, या उस हुक का टाइमआउट तिगुना
करने के लिए `beforeAll` हुक से।

```ts
test('imports a large file', async ({ app }) => {
  test.slow();
  await app.open('/import');
});
test('renders the report', async ({ platform }) => {
  test.slow(platform === 'ios', 'the simulator renders slowly');
});
```

- यह लागू टाइमआउट को तिगुना करता है और [`test.setTimeout`](#test-settimeout) की
  तरह अटेम्प्ट की शुरुआत से गिना जाता है (उसी के नियमों पर चलते हुए)।
  `test.setTimeout(10_000)` के बाद यह 30 सेकंड देता है, अधिकतम 2147483647
  मिलीसेकंड तक।
- Playwright की तरह यह अटेम्प्ट को एक ही बार धीमा करता है: बॉडी या `beforeEach`
  हुक में दूसरी कॉल कुछ नहीं करती। बाद का `test.setTimeout` तब भी टाइमआउट बदल
  सकता है।
- फ़ॉल्स कंडीशन पर यह कुछ नहीं करता। कारण पढ़ने वाले के लिए है और रिपोर्ट नहीं
  होता।
- रीट्राई फिर से [`timeout`](#timeout) ऑप्शन से शुरू होता है।
- `test.slow(title, fn)` नहीं है। बॉडी में सबसे पहले `test.slow()` कॉल करें, या
  `timeout` पास करें।

| क्या थ्रो होता है | कब |
| --- | --- |
| `INVALID_ARGUMENT` | `afterEach`/`afterAll` हुक, फ़िक्स्चर टियरडाउन, या होस्टेड सेशन से कॉल; या टेस्ट या हुक खत्म होने के बाद छूटे कोड से कॉल। |
| `COLLECTION_ERROR` | चल रहे टेस्ट या हुक के बाहर कॉल (फ़ॉल्स कंडीशन के साथ भी), या `test.slow(title, fn)`। वहाँ `timeout` ऑप्शन इस्तेमाल करें। |

#### `test.only`

एक फ़ोकस्ड लोकल टेस्ट रजिस्टर करता है।

```ts
test.only('pays', async ({ app }) => {
  await app.open('/checkout');
});
```

बाकी टेस्ट `filtered` रिपोर्ट होते हैं। फ़ोकस्ड टेस्ट वाला CI रन `ONLY_IN_CI` से
फ़ेल होता है।

#### `test.setup`

एक सेटअप टेस्ट रजिस्टर करता है जो सेव किए जाने वाले सेशन डिक्लेयर करता है, और
उसे हर एक को ठीक एक बार सेव करना होता है।

```ts

test.setup('authenticate', { sessions: ['member'] }, async ({ app, screen, session }) => {
  await app.open('/login');
  await screen.getByLabel('Email').fill(credentials.user('member').username);
  await screen.getByLabel('Password').fill(credentials.user('member').password);
  await screen.getByRole('button', 'Sign in').tap();
  await session.save('member');
});
```

- `test.setup` टॉप-लेवल पर होना चाहिए, `describe` के अंदर नहीं।
- [`sessions`](#sessions) ऑप्शन नाम डिक्लेयर करता है।
- कोई टेस्ट [`session`](#session) ऑप्शन से सेव किया हुआ सेशन इस्तेमाल करता है।
- सेटअप बॉडी को एक अतिरिक्त फ़िक्स्चर `session` मिलता है:

```ts
export interface SetupSession {
  /** Saves state under a setup-declared name. */
  save(name: string): Promise<void>;
}
```

| क्या थ्रो होता है | कब |
| --- | --- |
| `SESSION_CONTRACT` | रनटाइम पर कोई डिक्लेयर्ड सेशन सेव न हुआ हो, या दो बार सेव हो गया हो। |

#### `test.extend`

ज़्यादा फ़िक्स्चर के साथ टाइप्ड नया `test` लौटाता है। जिस पर इसे कॉल किया गया वह
नहीं बदलता।

```ts

export const test = base.extend<{ device: Device }>(); // types only
```

- बिना आर्ग्युमेंट के, `extend` सिर्फ़ टाइप निखारता है: यह वही रनटाइम `test`
  लौटाता है, इंजन के दिए बिल्ट-इन फ़िक्स्चर के साथ टाइप्ड। वे रनटाइम पर तब भी
  टारगेट के इंजन से ही रिज़ॉल्व होते हैं। इससे बिना ग्लोबल `declare module`
  ऑगमेंटेशन के डिवाइस, डेस्कटॉप, या वेब सरफ़ेस टाइप हो जाता है।
- डेफ़िनिशन के साथ यह आपके खुद के फ़िक्स्चर जोड़ता है।
  [आपके अपने फ़िक्स्चर](#your-own-fixtures) देखें।
- पहला टाइप आर्ग्युमेंट टेस्ट फ़िक्स्चर टाइप करता है। दूसरा
  [वर्कर फ़िक्स्चर](#worker-fixtures) टाइप करता है, जिन्हें `beforeAll` और
  `afterAll` भी देखते हैं। `@e2e-dev/mobile` वहीं `device`, `app`, और `screen`
  टाइप करता है।

#### `describe`

ऑप्शन के साथ या बिना टेस्ट का एक ग्रुप डिक्लेयर करता है।

```ts

describe('checkout', { tags: ['smoke'], serial: true }, () => {
  test('adds an item', async ({ screen }) => {});
  test('pays', async ({ screen }) => {});
});
```

- ग्रुप `only` को छोड़कर वे सभी [ऑप्शन](#options) लेता है जो टेस्ट लेता है, साथ
  में [`serial`](#serial)।
- बॉडी सिंक्रोनस होती है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | `async` बॉडी। यह टाइप एरर भी है। |
| `COLLECTION_ERROR` | बॉडी के अंदर `test.setup`। |

#### `describe.fail`

ऐसा ग्रुप डिक्लेयर करता है जिसके सभी टेस्ट के फ़ेल होने की उम्मीद है, ठीक
`describe` पर `fail: true` जैसा। कारण देने के लिए [`fail`](#fail) ऑप्शन
इस्तेमाल करें।

```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
```

- हर टेस्ट [`test.fail`](#test-fail) की तरह अलग से परखा जाता है: फ़ेलियर उसे पास
  करता है, और पास उसे `UNEXPECTED_PASS` से फ़ेल करता है।
- टेस्ट या अंदरूनी ग्रुप का `fail` कारण बाहरी ग्रुप पर भारी पड़ता है। टेस्ट या
  अंदरूनी ग्रुप पर `fail: false` उसे अनमार्क नहीं करता।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | ग्रुप सीरियल हो या सीरियल ग्रुप के अंदर हो, या उसके अंदर कोई सीरियल ग्रुप हो। |
| `COLLECTION_ERROR` | `describe.fail` पर `fail` ऑप्शन। यह टाइप एरर भी है। |

### हुक

| हुक | कब चलता है |
| --- | --- |
| [`beforeEach`](#beforeeach) | हर टेस्ट अटेम्प्ट से पहले |
| [`afterEach`](#aftereach) | हर टेस्ट अटेम्प्ट के बाद |
| [`beforeAll`](#beforeall) | हर सूट इंस्टेंस में एक बार |
| [`afterAll`](#afterall) | स्कोप के आखिरी टेस्ट के बाद |

हुक का क्रम फ़ाइल की जगह से नहीं बल्कि स्कोप नेस्टिंग से तय होता है, इसलिए टेस्ट
के बाद डिक्लेयर हुआ हुक भी उस पर लागू होता है।

#### `beforeEach`

टेस्ट-अटेम्प्ट सेटअप हुक रजिस्टर करता है।

```ts
test.beforeEach(async ({ app }) => {
  await app.open('/');
});
```

- सबसे बाहरी ग्रुप पहले चलता है, फिर एक ग्रुप के अंदर डिक्लेरेशन के क्रम में।
- `beforeEach` और बॉडी एक ही टेस्ट टाइमआउट शेयर करते हैं।
- इसे टेस्ट फ़िक्स्चर मिलते हैं। जिन फ़िक्स्चर का यह नाम लेता है वे हर उस टेस्ट के
  लिए सेट अप होते हैं जिस पर यह लागू है। [आपके अपने फ़िक्स्चर](#your-own-fixtures)
  देखें।

#### `afterEach`

टेस्ट-अटेम्प्ट टियरडाउन हुक रजिस्टर करता है।

```ts
test.afterEach(async ({ app }) => {
  await app.screenshot('after');
});
```

- सबसे अंदरूनी ग्रुप पहले चलता है, उल्टे डिक्लेरेशन क्रम में, फ़ेलियर या टाइमआउट
  के बाद भी।
- हर `afterEach` हुक को काम करते फ़िक्स्चर के साथ अपना `cleanupTimeout` बजट मिलता
  है, ताकि बॉडी टाइमआउट होने के बाद भी टियरडाउन ऐप चला सके।
- इसे टेस्ट फ़िक्स्चर मिलते हैं। जिन फ़िक्स्चर का यह नाम लेता है वे पहले
  `beforeEach` से पहले टेस्ट टाइमआउट पर सेट अप होते हैं, हुक शुरू होने पर कभी नहीं।
- जिस फ़िक्स्चर का सेटअप फ़ेल हो गया, उसका नाम लेने वाला हुक स्किप हो जाता है।

#### `beforeAll`

सूट-इंस्टेंस सेटअप हुक रजिस्टर करता है। यह स्कोप में पहली एंट्री पर हर सूट
इंस्टेंस में एक बार चलता है।

```ts
test.beforeAll(async ({ database, device }) => {
  await database.seed();
  await device.setPermission('camera', 'deny'); // a mobile target
});
```

हर रीट्राई, सीरियल ग्रुप, और सेटअप टेस्ट के लिए मॉड्यूल दोबारा इंपोर्ट होता है,
इसलिए `beforeAll` हर एक में फिर चलता है।

इसे सिर्फ़ [वर्कर फ़िक्स्चर](#worker-fixtures) मिलते हैं:

- वे [बिल्ट-इन फ़िक्स्चर](#fixtures) जिनका स्कोप टारगेट पर वर्कर है: `platform`,
  और मोबाइल टारगेट पर `device`, `app`, और `screen`।
- उस `test` के वर्कर फ़िक्स्चर जिससे इसे रजिस्टर किया गया। जिनका यह नाम लेता है
  वे सेट अप होते हैं, और वे भी जो `auto: true` के साथ डिक्लेयर हैं।

ब्राउज़र टारगेट पर `browser`, `app`, और `screen` टेस्ट फ़िक्स्चर हैं। UI सेटअप
`beforeEach` में रखें।

मोबाइल टारगेट पर:

- टेस्ट जिन `beforeAll` हुक में प्रवेश करता है, वे अपने एक छोटे इंजन अटेम्प्ट में
  चलते हैं जो कुछ लॉन्च नहीं करता। टेस्ट जिन स्कोप से बाहर निकलता है उनके
  `afterAll` हुक भी ऐसे ही चलते हैं।
- अटेम्प्ट पहले उस हुक के लिए खुलता है जो `device`, `app`, या `screen` का नाम
  ले, या ऐसे वर्कर फ़िक्स्चर का जो इनमें से किसी का नाम ले। जो हुक किसी का नाम न
  लें वे कोई अटेम्प्ट नहीं खोलते।
- सीरियल ग्रुप में, या `e2e mcp` सेशन के चलाए टेस्ट में, हुक पहले से खुले अटेम्प्ट
  पर चलते हैं।
- जब वह अटेम्प्ट न खुल सके या रन इंटरप्ट हो गया हो, तब भी हुक चलते हैं। तब
  `device`, `app`, या `screen` पढ़ने पर कारण के साथ थ्रो होता है। फ़ेल ओपन
  `launch` फ़ेज़ में एक रन एरर होता है।

सूट हुक के स्टेप किसी टेस्ट के रिकॉर्ड में नहीं जाते। फ़ेलियर हुक के स्कोप का नाम
बताता है।

हर `beforeAll` हुक कॉन्फ़िग `timeout` पर चलता है। इसके अंदर
[`test.setTimeout`](#test-settimeout) या [`test.slow`](#test-slow) उस हुक का
टाइमआउट बदलता है, और उसके बाद हुक की इंजन कॉल बदले हुए टाइमआउट पर चलती हैं। हुक
जिन वर्कर फ़िक्स्चर का नाम लेता है वे उसकी बॉडी चलने से पहले सेट अप होते हैं,
इसलिए वे कॉन्फ़िग `timeout` रखते हैं।

| क्या थ्रो होता है | कब |
| --- | --- |
| `HOOK_FAILED` | हुक थ्रो करे। सूट के टेस्ट `hook-failed` कारण के साथ स्किप हो जाते हैं। सीरियल ग्रुप के अंदर यह बाकी हर मेंबर को स्किप करके बिना रीट्राई ग्रुप को फ़ेल कर देता है। |
| `COLLECTION_ERROR` | हुक किसी टेस्ट फ़िक्स्चर का नाम ले। मैसेज उसका नाम और हुक की लाइन बताता है, और कोई टेस्ट नहीं चलता। |

#### `afterAll`

सूट-इंस्टेंस टियरडाउन हुक रजिस्टर करता है। रेल्म में स्कोप का आखिरी टेस्ट खत्म
होते ही यह चलता है।

```ts
afterAll(async () => {
  await resetDatabase();
});
```

फ़ेलियर से रद्द हुआ रेल्म हर उस स्कोप का `afterAll` चलाता है जिसका `beforeAll`
शुरू हुआ था। इसे [`beforeAll`](#beforeall) वाले ही फ़िक्स्चर मिलते हैं और खत्म
होने के लिए `cleanupTimeout` मिलता है। थ्रो होने पर `beforeAll` की तरह
`HOOK_FAILED` आता है।

#### ब्लॉक्ड इवेंट लूप

जो टेस्ट अपने वर्कर का इवेंट लूप ब्लॉक कर दे (फ़िक्स्चर, `beforeEach`, बॉडी, या
`afterEach` में `while (true) {}`), वह उस वर्कर के सारे टाइमर रोक देता है, इसलिए
वर्कर उसे टाइमआउट नहीं कर सकता।

- जब टेस्ट टाइमआउट के बाद `cleanupTimeout` (कम से कम 5 s) तक वर्कर जवाब न दे,
  तो रनर उसे किल कर देता है।
- वह अटेम्प्ट उससे पहले के अटेम्प्ट के बाद बिना आर्टिफ़ैक्ट के `TEST_TIMEOUT` के
  साथ `timed-out` रिपोर्ट होता है, और रीट्राई नहीं होता।
- उसकी फ़ाइल का बाकी हिस्सा नए वर्कर पर चलता है। सीरियल ग्रुप में उसके बाद के
  मेंबर स्किप हो जाते हैं।
- ब्लॉक करने वाला `beforeAll` या `afterAll` तब भी रन को लटका देता है।

<Note>
जिस वर्कर से टेस्ट शुरू होते वक्त डीबगर जुड़ा हो (एडिटर का ऑटो-अटैच, या
`NODE_OPTIONS=--inspect=0`), उसे इस तरह कभी किल नहीं किया जाता ताकि ब्रेकपॉइंट
रुका रह सके। इनलाइन कॉन्फ़िग या इन-मेमोरी टेस्ट वाला प्रोग्रामैटिक रन रनर की
अपनी प्रोसेस में चलता है और किल करने के लिए कोई वर्कर नहीं होता: ब्लॉक्ड इवेंट
लूप उसे लटका देता है।
</Note>

### ऑप्शन

| ऑप्शन | टाइप | डिफ़ॉल्ट |
| --- | --- | --- |
| [`timeout`](#timeout) | `number` | `config.timeout` |
| [`retries`](#retries) | `number` | `config.retries` |
| [`tags`](#tags) | `readonly string[]` | - |
| [`skip`](#skip) | `boolean \| string` | - |
| [`fail`](#fail) | `boolean \| string` | - |
| [`only`](#only) | `boolean` | - |
| [`platforms`](#platforms) | `readonly string[]` | - |
| [`session`](#session) | `string` | - |
| [`agentContext`](#agentcontext) | `string` | - |
| [`agent`](#agent) | `string \| readonly string[]` | रन के एजेंट |
| [`trace`](#trace) | `RecordingMode` | रन का |
| [`video`](#video) | `RecordingMode` | रन का |
| [`serial`](#serial) | `boolean` | - |
| [`sessions`](#sessions) | `readonly string[]` | ज़रूरी |

`test` `serial` और `sessions` को छोड़कर हर ऑप्शन लेता है। `describe` `only` और
`sessions` को छोड़कर हर ऑप्शन लेता है। `test.setup` को `sessions` चाहिए और वह
`session`, `only`, `skip`, या `fail` नहीं लेता।

रिज़ॉल्यूशन का क्रम: टेस्ट, सबसे करीबी ग्रुप, बाहरी ग्रुप, कॉन्फ़िग, बिल्ट-इन
डिफ़ॉल्ट। [सीरियल ग्रुप](#serial) के अंदर ग्रुप के `retries`, `trace`, और `video`
लागू होते हैं।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | ऐसी ऑप्शन key जिसे कॉल नहीं लेती (`{ timout: 1000 }`)। संभावित टाइपो होने पर एरर सबसे करीबी ज्ञात key का नाम बताता है, वरना वे सारी key जो कॉल लेती है। |

#### `timeout`

मिलीसेकंड में अटेम्प्ट डेडलाइन। सबसे अंदरूनी वैल्यू जीतती है।

```ts
test('imports a large file', { timeout: 300_000 }, async ({ app }) => {}); // default: config.timeout
```

`timeout` पॉज़िटिव सेफ़ इंटीजर होना चाहिए, अधिकतम 2147483647 (लगभग 24 दिन)।

#### `retries`

फ़ेल टेस्ट को कितनी बार रीट्राई किया जाए।

```ts
test('checks out', { retries: 2 }, async ({ app }) => {}); // default: config.retries
```

0 से 10 तक का इंटीजर।

#### `tags`

वे टैग जिन पर `--tag` सिलेक्ट करता है। हर लेयर के टैग जुड़ जाते हैं।

```ts
describe('checkout', { tags: ['billing', 'smoke'] }, () => {});
```

टैग अलग-अलग नाम होते हैं, कोई खाली नहीं, बिना कॉमा और बिना आगे-पीछे के
व्हाइटस्पेस के।

#### `skip`

कलेक्शन पर टेस्ट को स्किप करता है। स्ट्रिंग कारण बनती है। कोई भी ट्रूदी लेयर
स्किप कर देती है। रिपोर्टिंग से पहले स्किप कारण (रनटाइम `test.skip` कारण समेत)
सीक्रेट-रेडैक्ट, सैनिटाइज़, और 8,192 UTF-8 बाइट तक सीमित किए जाते हैं।

```ts
test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app }) => {});
```

#### `fail`

टेस्ट के फ़ेल होने की उम्मीद रखता है; [`test.fail`](#test-fail) देखें। स्ट्रिंग
कारण बनती है। `true` या किसी भी स्ट्रिंग वाली लेयर मार्क कर देती है, और सबसे
अंदरूनी कारण जीतता है। सीरियल ग्रुप पर, उसके अंदर, या उसके बाहर इसकी इजाज़त नहीं
है।

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

#### `only`

लोकल में टेस्ट को फ़ोकस करता है। CI इसे `ONLY_IN_CI` से मना करता है।

```ts
test('pays', { only: true }, async ({ app }) => {});
```

#### `platforms`

वे प्लेटफ़ॉर्म जिन पर टेस्ट चलता है। बाकी टारगेट इसे स्किप करते हैं। सबसे
अंदरूनी वैल्यू जीतती है।

```ts
test('uses Face ID', { platforms: ['ios'] }, async ({ app }) => {});
```

#### `session`

सेटअप टेस्ट का सेव किया हुआ सेशन, जो बॉडी चलने से पहले रीस्टोर होता है।

```ts
test('sees the dashboard', { session: 'member' }, async ({ app }) => {});
```

[`test.setup`](#test-setup) देखें।

#### `agentContext`

एजेंट स्टेप के लिए अतिरिक्त कॉन्टेक्स्ट। लेयर सबसे बाहरी से शुरू होकर जुड़ती हैं।

```ts
describe('pricing', { agentContext: 'Prices are shown in EUR.' }, () => {});
```

#### `agent`

वह कॉन्फ़िगर एजेंट (`agents.<name>`) जिसके साथ यह टेस्ट या ग्रुप रन के एजेंट की
जगह चलता है।

```ts
test('checks out', { agent: ['fast', 'smart'] }, async ({ agent }) => {}); // one result per agent
```

- लिस्ट होने पर टेस्ट हर बताए गए एजेंट के लिए एक बार चलता है, हर एक के अलग नतीजे
  के साथ।
- सबसे अंदरूनी वैल्यू जीतती है। कॉल का अपना `agent` ऑप्शन इस पर भारी पड़ता है।
- `--agent` लिस्ट को दोनों में मौजूद नामों तक सीमित करता है, और उस पिन को कभी
  ओवरराइड नहीं करता जिसका नाम फ़्लैग में न हो।
- सेटअप टेस्ट हर टारगेट पर एक बार चलता है, इसलिए वह ज़्यादा से ज़्यादा एक एजेंट
  पिन करता है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | सिलेक्शन पर, कोई भी टेस्ट चलने से पहले: ऐसा नाम जो `agents` में डिफ़ाइन न हो। |

#### `trace`

टेस्ट ट्रेस पेज रखेगा या नहीं, रन की सेटिंग की जगह।

```ts
test('checkout', { trace: 'retain-on-failure' }, async ({ agent }) => {});
```

- कॉन्फ़िग के `trace` जैसा ही [रिकॉर्डिंग मोड](https://e2e.com/docs/hi/reference/config#recording) लेता
  है: `off`, `on`, `retain-on-failure`, `on-first-retry`, या `on-all-retries`।
- टेस्ट या ग्रुप की अपनी वैल्यू `--trace`, टारगेट, और कॉन्फ़िग पर भारी पड़ती है।
  कुछ भी रिकॉर्ड न करने वाले रन में एक टेस्ट रिकॉर्ड कर सकता है, या सब कुछ रिकॉर्ड
  करने वाले रन में ऑप्ट-आउट कर सकता है।

#### `video`

टेस्ट के कौन-से अटेम्प्ट वीडियो रिकॉर्ड करेंगे, रन की सेटिंग की जगह।

```ts
test('checkout', { video: 'on' }, async ({ agent }) => {
  await agent.act('Buy the first product in the catalog');
});
```

- `trace` और कॉन्फ़िग के `video` वाले ही [रिकॉर्डिंग मोड](https://e2e.com/docs/hi/reference/config#recording)
  लेता है।
- टेस्ट या ग्रुप की अपनी वैल्यू `--video`, टारगेट, और कॉन्फ़िग पर भारी पड़ती है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `UNSUPPORTED_ARTIFACT` | कोई भी टेस्ट शुरू होने से पहले, टेस्ट का नाम बताते हुए: मोड किसी अटेम्प्ट पर रिकॉर्ड करता है और टारगेट का इंजन वीडियो रिकॉर्ड नहीं कर सकता। |

#### `serial`

सिर्फ़ `describe`। ग्रुप को शेयर्ड ऐप स्टेट के साथ एक क्रमबद्ध रीट्राई यूनिट की
तरह चलाता है।

```ts
describe('checkout', { serial: true }, () => {
  test('adds an item', async ({ screen }) => {});
  test('pays', async ({ screen }) => {});
});
```

- ग्रुप सीक्रेट स्टेट भी शेयर करता है: एक मेंबर की रिज़ॉल्व की हुई वैल्यू ग्रुप
  के बाकी अटेम्प्ट में रेडैक्ट रहती है। रीट्राई नए सिरे से शुरू होता है।
- मेंबर सीरियल `describe` या उसके बाहर के ग्रुप का `trace` और `video` लेते हैं।
  ग्रुप हर ग्रुप अटेम्प्ट के लिए एक वीडियो रिकॉर्ड करता है।
- फ़ाइल लोड न होने या सेशन लॉन्च न होने पर ग्रुप अटेम्प्ट शुरू न हो सके, तो पहला
  मेंबर उस एरर से फ़ेल होता है और बाकी `serial-predecessor-failed` कारण से स्किप
  हो जाते हैं। लॉन्च के दौरान रन इंटरप्ट होने पर हर मेंबर स्किप हो जाता है।
- अगर रीट्राई इंटरप्ट हो जाए या अपने मेंबर तक न पहुँचे, तो वे उन्हें चलाने वाले
  आखिरी अटेम्प्ट के फ़ैसले और समय बनाए रखते हैं।
- किसी भी दूसरे टेस्ट की तरह एग्ज़िट कोड एरर की श्रेणी से तय होता है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | कोई मेंबर `retries`, `trace`, `video`, `session`, `platforms`, `skip`, `only`, या नेस्टेड `serial` सेट करे। |
| `COLLECTION_ERROR` | कोई मेंबर `test.skip(title, fn)`, `test.skipIf`, `test.runIf`, या `test.fixme(title, fn)` से रजिस्टर हो। |

#### `sessions`

सिर्फ़ `test.setup`। वे सेशन नाम जिन्हें सेटअप टेस्ट को सेव करना ही है।

```ts
test.setup('authenticate', { sessions: ['member', 'admin'] }, async ({ session }) => {});
```

यूनिक नामों का स्टैटिक, खाली न होने वाला ऐरे। हर नाम `/^[A-Za-z0-9_.-]{1,128}$/`
से मैच होना चाहिए। [`test.setup`](#test-setup) देखें।

### फ़िक्स्चर

बिल्ट-इन फ़िक्स्चर वे हैं जो `test.extend` के बिना `test` में मिलते हैं: हर इंजन
पर छह, और वे जो टारगेट का इंजन जोड़ता है। हर इंजन पर हर एक का अपना स्कोप होता
है।

| बिल्ट-इन फ़िक्स्चर | टाइप | वेब | मोबाइल |
| --- | --- | --- | --- |
| [`agent`](https://e2e.com/docs/hi/reference/agent) | `Agent` | test | test |
| [`app`](https://e2e.com/docs/hi/reference/app) | `App` | test | worker |
| [`screen`](https://e2e.com/docs/hi/reference/screen) | `Screen` | test | worker |
| `platform` | `string` | worker | worker |
| [`request`](https://e2e.com/docs/hi/reference/request) | `APIRequest` | test | test |
| [`session`](#test-setup) | `SetupSession` | test | test |
| [`browser`](https://e2e.com/docs/hi/reference/web) | `Browser` | test | - |
| [`device`](https://e2e.com/docs/hi/reference/mobile#device) | `Device` | - | worker |

स्कोप तय करता है कि कौन-सा कोड किस बिल्ट-इन फ़िक्स्चर को इस्तेमाल कर सकता है:

- टेस्ट फ़िक्स्चर एक टेस्ट अटेम्प्ट का होता है। यह टेस्ट बॉडी, `beforeEach`, और
  `afterEach` को मिलता है।
- वर्कर फ़िक्स्चर टेस्ट से ज़्यादा समय चलता है। यह `beforeAll`, `afterAll`, और
  [वर्कर फ़िक्स्चर](#worker-fixtures) को भी मिलता है।

ब्राउज़र टेस्ट को नया कॉन्टेक्स्ट मिलता है, इसलिए वेब पर `app`, `screen`, और
`browser` टेस्ट फ़िक्स्चर हैं। डिवाइस टेस्ट के बीच अपना स्टेट रखता है, इसलिए
मोबाइल पर `app`, `screen`, और `device` वर्कर फ़िक्स्चर हैं। आपका अपना इंजन इसे
[`isolation`](https://e2e.com/docs/hi/reference/engine#fixture-isolation) से सेट करता है।

`session` सिर्फ़ `test.setup` बॉडी को मिलता है। [`TestFixtures`](#testfixtures)
हर कोर फ़िक्स्चर बताता है। बाकी हर फ़िक्स्चर [आपका अपना](#your-own-fixtures) होता
है।

टेस्ट बॉडी, हुक, और फ़िक्स्चर फ़ंक्शन अपने पहले पैरामीटर को डीस्ट्रक्चर करके
इस्तेमाल होने वाले फ़िक्स्चर के नाम देते हैं: `async ({ app, screen }) => {}`।
e2e फ़ंक्शन के सोर्स से ये नाम पढ़ता है। [`test.each`](#test-each) या
[`test.for`](#test-for) बॉडी रो के बाद वाले पैरामीटर में इनके नाम देती है।

| क्या थ्रो होता है | कब |
| --- | --- |
| `COLLECTION_ERROR` | टारगेट पर चलने वाला टेस्ट या उसका कोई हुक ऐसे फ़िक्स्चर का नाम ले जो टारगेट के पास नहीं है। कोई टेस्ट नहीं चलता। उस टारगेट पर ऐसे टेस्ट स्किप करने के लिए `platforms` या `test.skipIf` डिक्लेयर करें। |
| `COLLECTION_ERROR` | टेस्ट बॉडी, हुक, या फ़िक्स्चर फ़ंक्शन पूरा ऑब्जेक्ट ले (`async (fixtures) => {}`), रेस्ट प्रॉपर्टी (`{ app, ...rest }`), या कंप्यूटेड प्रॉपर्टी ले, या बाउंड फ़ंक्शन (`fn.bind()`) हो जिसके पैरामीटर नहीं पढ़े जा सकते। |

<Note>
बिल्ट-इन फ़िक्स्चर लेज़ी होते हैं। पैरामीटर लिस्ट में डीस्ट्रक्चर करने से वे
बॉडी के पहले स्टेटमेंट से पहले मिल जाते हैं।
[आपके अपने फ़िक्स्चर](#your-own-fixtures) पहले `beforeEach` से पहले सेट अप होते
हैं।
</Note>

#### आपके अपने फ़िक्स्चर

`test.extend(fixtures)` ऐसे रिसोर्स डिफ़ाइन करता है जो उनका नाम लेने वाले हर
टेस्ट से पहले सेट अप होते हैं और बाद में (फ़ेलियर के बाद भी) क्लीन अप होते हैं।
हर फ़िक्स्चर फ़ंक्शन में `await use(value)` से पहले का कोड रिसोर्स सेट अप करता
है। टेस्ट को `value` मिलती है, और `use` के बाद का कोड उसे टियरडाउन करता है। पूरे
सूट वाले गाइड के लिए [फ़िक्स्चर लिखना](https://e2e.com/docs/hi/fixtures) देखें।

```ts

export const test = base.extend<{ workspace: Workspace }>({
  workspace: async ({ browser }, use) => {
    const workspace = await createWorkspace();
    await signIn(browser, workspace);
    await use(workspace); // the hooks and the body run here
    await workspace.cleanup(); // teardown, after the body even when it failed
  },
});

test('renames the workspace', async ({ workspace, screen }) => {
  await screen.getByLabel('Name').fill(`${workspace.name} (renamed)`);
});
```

फ़िक्स्चर ज़रूरत पर सेट अप होता है: उस टेस्ट के लिए जो उसका नाम ले, या ऐसे
फ़िक्स्चर का नाम ले जो उसका नाम लेता हो। फ़ंक्शन पहले पैरामीटर में जिन फ़िक्स्चर
का नाम लेता है, वे उसकी डिपेंडेंसी हैं:

- डेफ़िनिशन उस `test` के फ़िक्स्चर देखती है जिसे वह एक्सटेंड करती है और उसी कॉल
  में उसके बगल में डिक्लेयर फ़िक्स्चर भी (किसी भी क्रम में)। यह बाद के `extend`
  में डिक्लेयर फ़िक्स्चर नहीं देखती।
- जिस डेफ़िनिशन को कोई फ़िक्स्चर नहीं चाहिए वह `({}, use)` लेती है। ESLint का
  `no-empty-pattern` इसे `allowObjectPatternsAsParameters: true` के साथ मानता है।
- `[fn, { auto: true }]` उस `test` के हर टेस्ट के लिए फ़िक्स्चर सेट अप करता है,
  चाहे नाम लिया जाए या नहीं। इसे उस फ़िक्स्चर के लिए इस्तेमाल करें जिसकी टेस्ट को
  ज़रूरत है लेकिन वह उसे कभी पढ़ता नहीं।

हर अटेम्प्ट पर:

1. कुछ भी चलने से पहले तय होता है कि कौन-से फ़िक्स्चर सेट अप होंगे: वे जिनका नाम
   बॉडी और लागू होने वाले हर `beforeEach` और `afterEach` हुक ने लिया, वे जिनका नाम
   उन फ़िक्स्चर ने लिया, और `auto` वाले। जिसका नाम किसी ने न लिया वह नहीं चलता।
2. वे डिक्लेरेशन के क्रम में चलते हैं (हर एक अपने बताए गए फ़िक्स्चर के बाद) जब तक
   हर एक `use` न कॉल करे। सेटअप टेस्ट `timeout` में गिना जाता है। कोई भी
   `beforeEach` हुक चलने से पहले यहाँ का फ़ेलियर `beforeEach` फ़ेज़ में रिपोर्ट
   होता है।
3. `beforeEach` हुक, बॉडी, और फिर `afterEach` हुक उन्हीं फ़िक्स्चर के साथ चलते
   हैं। हर एक को वही मिलते हैं जिनका उसने नाम लिया। फ़िक्स्चर सेट टेस्ट की अपनी
   चेन का होता है: `base` से रजिस्टर टेस्ट के चारों ओर `workspace` का नाम लेने
   वाला हुक `COLLECTION_ERROR` से फ़ेल होता है।
4. आखिरी `afterEach` के बाद टियरडाउन उल्टे क्रम में चलते हैं (बॉडी पास हुई हो या
   नहीं), हर एक अपने `cleanupTimeout` बजट के साथ। वहाँ का एरर पास हो रहे अटेम्प्ट
   को `afterEach` फ़ेज़ में फ़ेल करता है और बॉडी फ़ेलियर के बाद `secondaryErrors`
   में जुड़ता है।

कलेक्शन पर फ़ेल होने वाली गलती कोड की फ़ाइल और लाइन के साथ एक रन एरर बनती है, और
कोई टेस्ट नहीं चलता। जो टेस्ट किसी टारगेट पर नहीं चलता, उसकी उस टारगेट के फ़िक्स्चर
से जाँच नहीं होती।

| गलती | कहाँ फ़ेल होती है |
| --- | --- |
| ऐसी वैल्यू जो फ़ंक्शन या `[fn, { scope, auto }]` जोड़ों का प्लेन ऑब्जेक्ट न हो, `'test'` या `'worker'` के अलावा स्कोप, बूलियन न होने वाला `auto`, `scope` और `auto` के अलावा कोई ऑप्शन, या खाली नाम | इंपोर्ट पर, फ़िक्स्चर का नाम बताते हुए `COLLECTION_ERROR` |
| ऐसा फ़ंक्शन जो पहले पैरामीटर को डीस्ट्रक्चर न करे, उसमें रेस्ट या कंप्यूटेड प्रॉपर्टी ले, या बाउंड फ़ंक्शन हो | इंपोर्ट पर, फ़िक्स्चर का नाम बताते हुए `COLLECTION_ERROR` |
| साइकल में एक-दूसरे का नाम लेने वाले फ़िक्स्चर | इंपोर्ट पर, साइकल का नाम बताते हुए `COLLECTION_ERROR` |
| वहाँ चलने वाले टेस्ट, उसके हुक, या उनके ज़रूरी फ़िक्स्चर में ऐसा नाम जो टारगेट के पास न हो | कलेक्शन पर, `COLLECTION_ERROR` |
| ऐसा `scope` या `auto` जो [एक्सटेंड किए जा रहे फ़िक्स्चर](#extending-a-fixture) से अलग हो | हर इंजन पर एक जैसा होने पर इंपोर्ट पर, वरना कलेक्शन पर, दोनों के नाम बताते हुए `COLLECTION_ERROR` |
| ऐसा फ़िक्स्चर जो बाद के `extend` में डिक्लेयर फ़िक्स्चर का नाम ले | कलेक्शन पर, `COLLECTION_ERROR` |
| `use` कॉल किए बिना लौटने वाली डेफ़िनिशन | अटेम्प्ट में, `beforeEach` में, `TEST_SETUP_FAILED` |
| `use` दो बार कॉल करने वाली डेफ़िनिशन | अटेम्प्ट में, टियरडाउन पर, `TEST_SETUP_FAILED` |
| `use` से पहले थ्रो करने वाली डेफ़िनिशन | अटेम्प्ट में, `beforeEach` में, उस एरर के साथ। उस फ़िक्स्चर का नाम लेने वाला `afterEach` हुक स्किप हो जाता है। |
| `use` के बाद थ्रो करने वाली डेफ़िनिशन | अटेम्प्ट में, `afterEach` में, उस एरर के साथ |

<Note>
टेस्ट `timeout` पर पहुँचने वाली बॉडी या हुक को बीच में छोड़ा जाता है, कैंसल नहीं
किया जाता, इसलिए टियरडाउन तब भी शुरू हो जाता है जब वह शायद अभी चल रहा हो। इस तरह
छूटा हुआ सेटअप अगर बाद में `use` तक पहुँचे तो तुरंत रिज़ॉल्व हो जाता है। उसका
टियरडाउन रन से अलग होकर चलता है, ताकि जो उसने लिया था वह तब भी रिलीज़ हो जाए।
छूटे हुए सेटअप या हुक के खत्म होने के बाद आगे के फ़िक्स्चर, हुक, और टेस्ट बॉडी
शुरू नहीं होते।
</Note>

#### वर्कर फ़िक्स्चर

वर्कर फ़िक्स्चर का हर वर्कर और टारगेट के लिए एक इंस्टेंस होता है। इसे
`[fn, { scope: 'worker' }]` के रूप में डिक्लेयर करें और `extend` के दूसरे टाइप
आर्ग्युमेंट से टाइप करें:

```ts
export const test = base.extend<{}, { database: Database }>({
  database: [async ({}, use) => {
    const database = await startDatabase();
    await use(database);
    await database.stop();
  }, { scope: 'worker' }],
});
```

- सेटअप पहली बार तब चलता है जब कोई टेस्ट या सूट हुक उसका नाम ले (या ऐसे फ़िक्स्चर
  का जो उसका नाम ले), उस टेस्ट या हुक के टाइमआउट के अंदर। फ़ेल सेटअप उस टेस्ट या
  हुक को फ़ेल करता है, और अगला वाला फ़िक्स्चर को फिर सेट अप करता है।
- `[fn, { scope: 'worker', auto: true }]` इसे इसके `test` से रजिस्टर पहले टेस्ट
  या सूट हुक के लिए सेट अप करता है, चाहे नाम लिया जाए या नहीं।
- टियरडाउन वर्कर खत्म होने पर, इंजन डिस्पोज़ होने से पहले चलता है (जो सबसे बाद
  में सेट अप हुआ वह पहले)। हर टियरडाउन को `cleanupTimeout` मिलता है। थ्रो करने
  वाला टियरडाउन `cleanup` फ़ेज़ में रन एरर बनता है।
- यह सिर्फ़ वर्कर फ़िक्स्चर देखता है: टारगेट पर वर्कर स्कोप वाले
  [बिल्ट-इन फ़िक्स्चर](#fixtures), जिस `test` को यह एक्सटेंड करता है उसके वर्कर
  फ़िक्स्चर, और इसके बगल में डिक्लेयर हुए वर्कर फ़िक्स्चर। टेस्ट फ़िक्स्चर का नाम
  लेने पर `COLLECTION_ERROR` आता है।
- मोबाइल टारगेट पर इसके `device`, `app`, और `screen` उस टेस्ट या हुक में काम करते
  हैं जो इन्हें कॉल करते समय चल रहा हो। इसका टियरडाउन तब भी डिवाइस चला सकता है:
  इनमें से किसी का नाम लेने पर यह एक छोटे इंजन अटेम्प्ट में चलता है, और न लेने पर
  बिना अटेम्प्ट के।
- वर्कर हर डेफ़िनिशन के लिए एक इंस्टेंस रखता है। फ़ेल टेस्ट के बाद और हर सीरियल
  ग्रुप और सेटअप टेस्ट के लिए टेस्ट फ़ाइल दोबारा इंपोर्ट होती है, इसलिए फ़ाइल में
  डिक्लेयर वर्कर फ़िक्स्चर को हर बार नया इंस्टेंस मिलता है, और पुराना वर्कर खत्म
  होने तक सेट अप रहता है। वर्कर फ़िक्स्चर को ऐसे मॉड्यूल में डिक्लेयर करें जिसे
  फ़ाइल इंपोर्ट करे।
- बिना टाइप आर्ग्युमेंट वाला `extend({ ... })` सिर्फ़ टेस्ट फ़िक्स्चर इनफ़र करता
  है।

#### फ़िक्स्चर एक्सटेंड करना

`test` में पहले से मौजूद फ़िक्स्चर के नाम वाली डेफ़िनिशन उस फ़िक्स्चर को एक्सटेंड
करती है। यह कोई [बिल्ट-इन फ़िक्स्चर](#fixtures) या पहले के `extend` का फ़िक्स्चर
हो सकता है।

```ts
export const test = base.extend({
  app: async ({ app }, use) => {
    await app.open('/dashboard');
    await use(app); // tests, hooks, and other fixtures get this value
  },
});
```

- फ़ंक्शन के अंदर उसका अपना नाम वही फ़िक्स्चर है जिसे वह एक्सटेंड कर रहा है:
  बिल्ट-इन, या उस नाम का पिछला फ़िक्स्चर। जो फ़ंक्शन खुद का नाम न ले वह फ़िक्स्चर
  को पूरी तरह बदल देता है।
- उस फ़िक्स्चर का नाम लेने वाले टेस्ट, हुक, और बाकी फ़िक्स्चर को `use` में पास की
  गई वैल्यू मिलती है। बिल्ट-इन फ़िक्स्चर के साथ रनर जो करता है वह नहीं बदलता।
- यह तभी सेट अप होता है जब एक्सटेंड किया जाने वाला फ़िक्स्चर होता: ज़रूरत पर
  उसका नाम लेने वाले कोड के लिए, या `auto` फ़िक्स्चर एक्सटेंड करने पर हर टेस्ट के
  लिए। ऑप्शन में दिया `auto` एक्सटेंड किए जाने वाले फ़िक्स्चर के `auto` से मेल
  खाना चाहिए।
- यह टारगेट पर एक्सटेंड किए जाने वाले फ़िक्स्चर का स्कोप बनाए रखता है, जैसा
  [बिल्ट-इन फ़िक्स्चर](#fixtures) टेबल में दिया है। `device` वर्कर फ़िक्स्चर है,
  इसलिए उसका ओवरराइड हर वर्कर में एक बार चलता है और `beforeAll` को मिलता है।
  ऑप्शन में दिया `scope` वही होना चाहिए।
- यह टाइप बनाए रखता है। इसे बिना टाइप आर्ग्युमेंट के डिफ़ाइन करें: `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. */
  (title: string, fn: TestFn<Fixtures>): TestCase;
  /** Registers one configured test synchronously during module evaluation. */
  (title: string, options: TestOptions, fn: TestFn<Fixtures>): TestCase;
}

/**
 * The two call forms of `test` for `test.each` and `test.for`: one test per
 * row, each titled from the row. `Args` are the body's arguments.
 */
export interface EachRegistrar<Args extends readonly unknown[]> {
  /** Registers one test per row synchronously during module evaluation. */
  (title: string, fn: EachFn<Args>): readonly TestCase[];
  /** Registers one configured test per row synchronously during module evaluation. */
  (title: string, options: TestOptions, fn: EachFn<Args>): readonly TestCase[];
}

export interface TestAPI<Fixtures = TestFixtures, Worker = WorkerFixtures> extends TestRegistrar<Fixtures & Worker> {
  /** Registers one skipped test. */
  skip(title: string, fn: TestFn<Fixtures & Worker>): TestCase;
  /**
   * Inside a running test: skips it when `condition` is true (or always,
   * with no condition) by throwing, so nothing after the call runs. The
   * attempt is reported `skipped` with `reason`; steps that already ran stay
   * in the report without deciding the status, and teardown still runs. A
   * setup test cannot skip: its sessions are owed.
   * Outside a test body this form is `COLLECTION_ERROR`; use the `skip`
   * option to skip at collection.
   */
  skip(condition: boolean, reason?: string): void;
  skip(reason?: string): void;
  /** Registers one skipped test marked fixme, reported with the skip cause and reason `fixme`. */
  fixme(title: string, fn: TestFn<Fixtures & Worker>): TestCase;
  /**
   * Inside a running test: skips it as fixme when `condition` is true (or
   * always, with no condition), as `test.skip` does. The skip cause is
   * `fixme`, and the reason `fixme`, or `fixme: <reason>` when `reason` is not
   * blank. A setup test cannot skip. Outside a test body this form is
   * `COLLECTION_ERROR`; use `test.fixme(title, fn)` to mark a test fixme at
   * collection.
   */
  fixme(condition: boolean, reason?: string): void;
  fixme(reason?: string): void;
  /**
   * Returns a function that registers one test, like `test(title, fn)`:
   * skipped when `condition` is truthy, as if it had the `skip` option. The
   * condition is read once, at this call, so it can only depend on what is
   * known while the file is collected (`process.platform`, `process.env.CI`):
   *
   *   test.skipIf(process.platform === 'win32')('file watcher', async () => {});
   *
   * A `skip` option skips the test whatever the condition. A serial group
   * rejects the call: set `skip` on the serial `describe` instead. A Promise
   * condition also fails the call: await it first.
   */
  skipIf<Condition>(condition: SynchronousCondition<Condition>): TestRegistrar<Fixtures & Worker>;
  /**
   * Returns a function that registers one test, like `test(title, fn)`:
   * skipped when `condition` is falsy, `test.skipIf(!condition)`.
   */
  runIf<Condition>(condition: SynchronousCondition<Condition>): TestRegistrar<Fixtures & Worker>;
  /**
   * Returns a function that registers one test per row, like `test(title,
   * fn)`, in row order. The title is formatted from the row: `$name` and
   * `$name.path` read an object row, and `%s`, `%d`, `%i`, `%f`, `%j`, `%o`
   * take an array row's items in order (any other row is the one item). `%#`
   * is the row index, `%$` the row number, `%%` a percent sign. When every
   * row is an array, each row is spread into the body's arguments; otherwise
   * every row is the first one. The fixtures come last:
   *
   *   test.each([{ user: 'Ada' }, { user: 'Grace' }])('signs in as $user', async ({ user }, { app }) => {});
   *   test.each([[1, 2, 3]])('%i + %i = %i', async (a, b, sum, { app }) => {});
   *
   * Rows must be a non-empty array. Two rows that format to the same title
   * fail as duplicate titles. As in a test body, destructure the fixtures
   * (`{ app }`): e2e sets up only the ones named there.
   */
  each<Row extends readonly unknown[] | [unknown]>(rows: readonly Row[]): EachRegistrar<[...Row, Fixtures & Worker]>;
  each<Row>(rows: readonly Row[]): EachRegistrar<EachArgs<Row, Fixtures & Worker>>;
  /**
   * `test.each` that never spreads: the body takes `(row, fixtures)` for
   * every row, an array row included. Titles format as in `test.each`.
   */
  for<Row extends readonly unknown[] | [unknown]>(rows: readonly Row[]): EachRegistrar<[Row, Fixtures & Worker]>;
  for<Row>(rows: readonly Row[]): EachRegistrar<[Row, Fixtures & Worker]>;
  /** Registers one test that is expected to fail. */
  fail(title: string, fn: TestFn<Fixtures & Worker>): TestCase;
  /**
   * Inside a running test: marks it expected to fail when `condition` is
   * true (or always, with no condition). The body keeps running. A test
   * failure then passes the test, keeping the error and `reason` in the
   * report; a pass fails it with `UNEXPECTED_PASS`. Infrastructure failures
   * and interrupts are not covered. A setup test or a serial group member
   * cannot be marked. Outside a test body this form is `COLLECTION_ERROR`;
   * use `test.fail(title, fn)` or the `fail` option to mark at collection.
   */
  fail(condition: boolean, reason?: string): void;
  fail(reason?: string): void;
  /** Registers one focused local test. CI rejects focused tests. */
  only(title: string, fn: TestFn<Fixtures & Worker>): TestCase;
  /** Registers one setup test with statically declared session outputs. */
  setup(title: string, options: SetupOptions, fn: SetupFn<Fixtures & Worker>): TestCase;
  /**
   * Returns the same runtime `test`, typed with an engine's contributed
   * fixtures. A pure type refinement, the fixtures still resolve from the
   * target's engine at runtime, so a project types its device/desktop/web
   * surface without a global `declare module` augmentation:
   *
   *   export const test = base.extend<{ device: Device }>();
   */
  extend<Extra = {}, ExtraWorker = {}>(): TestAPI<Fixtures & Extra, Worker & ExtraWorker>;
  /**
   * Returns a new `test` whose registrations extend fixtures it already
   * has, built-in ones included. Inside the function the fixture's own name
   * is the fixture it extends; the value it hands to `use` is what tests,
   * hooks, and other fixtures receive under that name. It keeps the type and
   * the scope of the fixture it extends:
   *
   *   export const test = base.extend({
   *     app: async ({ app }, use) => {
   *       await app.open('/dashboard');
   *       await use(app);
   *     },
   *   });
   */
  extend(overrides: FixtureOverrides<Fixtures & Worker, Worker>): TestAPI<Fixtures, Worker>;
  /**
   * Returns a new `test` whose registrations carry these fixture
   * definitions on top of the ones it already had. Each attempt sets up the
   * ones its body and its `beforeEach` and `afterEach` hooks name, and the
   * ones those fixtures name, in declaration order with each after the
   * fixtures it names; it runs the hooks and the body with them, and tears
   * them down in reverse order after `afterEach`. A fixture nothing names is
   * not set up:
   *
   *   export const test = base.extend<{ workspace: Workspace }>({
   *     workspace: async ({ browser }, use) => {
   *       const workspace = await createWorkspace();
   *       await use(workspace);
   *       await workspace.cleanup();
   *     },
   *   });
   *
   * A worker fixture (the second type argument, `[fn, { scope: 'worker' }]`)
   * is set up once per worker and target, the first time a test or suite
   * hook of the chain names it, and torn down when the worker ends:
   *
   *   export const test = base.extend<{}, { database: Database }>({
   *     database: [async ({}, use) => {
   *       const database = await startDatabase();
   *       await use(database);
   *       await database.stop();
   *     }, { scope: 'worker' }],
   *   });
   *
   * `auto: true` sets a fixture up whether or not anything names it: for
   * every test (`[fn, { auto: true }]`), or once per worker
   * (`[fn, { scope: 'worker', auto: true }]`). A suite hook sets up the auto
   * worker fixtures of its chain, never a test fixture.
   */
  extend<Extra = {}, ExtraWorker = {}>(
    fixtures: FixtureDefinitions<Fixtures & Worker, Extra, Worker, ExtraWorker>,
  ): TestAPI<Fixtures & Extra, Worker & ExtraWorker>;
  /** 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. */
  afterEach(fn: TestHookFn<Fixtures & Worker>): void;
  /** Registers a suite setup hook, run once per describe between attempts, with the worker fixtures. */
  beforeAll(fn: TestHookFn<Worker>): void;
  /** Registers a suite teardown hook, run once per describe between attempts, with the worker fixtures. */
  afterAll(fn: TestHookFn<Worker>): void;
}

export const test: TestAPI;
export const describe: TestAPI['describe'];
export const beforeEach: TestAPI['beforeEach'];
export const afterEach: TestAPI['afterEach'];
export const beforeAll: TestAPI['beforeAll'];
export const afterAll: TestAPI['afterAll'];
```

### `TestOptions`

```ts
export interface TestOptions {
  /** Attempt deadline in milliseconds; defaults to `config.timeout`. Innermost wins. */
  timeout?: number;
  /** Retries, 0 through 10; defaults to `config.retries`. Inside a serial group the group's value applies. */
  retries?: number;
  /** Tags for `--tag`: distinct names, none blank, with no comma and no leading or trailing whitespace; every layer's tags are unioned. */
  tags?: readonly string[];
  /** Skips the test; a string is the reason. Any truthy layer skips. */
  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`. 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`. */
  only?: boolean;
  /** Platforms the test runs on; other targets skip it. Innermost wins. */
  platforms?: readonly string[];
  /** Session a setup test saved, restored before the body runs. */
  session?: string;
  /** Extra context for agent steps; layers are concatenated outermost first. */
  agentContext?: string;
  /**
   * The configured agent (`agents.<name>`) this test or group runs with, in
   * place of the run's agents. A list runs the test once per agent named, as
   * one result each. Innermost wins; a call's own `agent` option wins over
   * it. `--agent` narrows a list to the names both name and never overrides
   * a pin the flag does not name.
   */
  agent?: string | readonly string[];
  /**
   * Which of the test's attempts keep a trace, in place of the run's: the
   * same modes as the config's `trace`. Innermost wins, over `--trace` too;
   * inside a serial group the group's value applies, since the group runs as
   * one unit.
   */
  trace?: RecordingMode;
  /**
   * Which of the test's attempts record a video, in place of the run's:
   * the same modes as the config's `video`. Innermost wins, over `--video`
   * too; inside a serial group the group's value applies, since the group
   * records as one unit. A mode set here is required of the target's engine.
   */
  video?: RecordingMode;
}

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;
}

export interface SetupOptions extends Omit<TestOptions, 'session' | 'only' | 'skip' | 'fail' | 'agent'> {
  /** Session names this setup test MUST save. */
  sessions: readonly string[];
  /** A setup test runs once per target, so it pins at most one agent. */
  agent?: string;
}
```

### `TestFixtures`

```ts
export interface TestFixtures {
  /** Agent steps. Acquiring the built-in agent without a configured model is `MODEL_UNAVAILABLE`. */
  readonly agent: Agent;
  /** App lifecycle: open, restart, clear state, back, screenshot, recording. */
  readonly app: App;
  /** Semantic queries and the actions on their matches. */
  readonly screen: Screen;
  /** The target's platform label: `web`, `ios`, `android`, or an engine's own string. */
  readonly platform: string;
  /** HTTP calls, each one a step; a path resolves against the app URL. */
  readonly request: APIRequest;
}

export interface SetupFixtures extends TestFixtures {
  /** Saves the sessions the setup test declared. */
  readonly session: SetupSession;
}

/**
 * How long one fixture instance lives. `test`, the default, is one instance
 * per test attempt that names it, shared by its `beforeEach` hooks, its
 * body, and its `afterEach` hooks. `worker` is one instance per worker and
 * target, set up the first time a test or suite hook names it and torn down
 * when the worker ends.
 */
export type FixtureScope = 'test' | 'worker';

/**
 * The fixtures that outlive a test: what `beforeAll`, `afterAll`, and a
 * worker-scoped `test.extend()` fixture receive. An engine whose state
 * outlives an attempt (a device keeps permissions and installed apps) adds
 * its own fixtures, `app`, and `screen` here; on an engine that gives each
 * attempt a fresh surface (a browser context) they are test fixtures.
 */
export interface WorkerFixtures {
  /** The target's platform label: `web`, `ios`, `android`, or an engine's own string. */
  readonly platform: string;
}

/** @deprecated `beforeAll` and `afterAll` receive the worker fixtures: use `WorkerFixtures`. */
export type SuiteFixtures = WorkerFixtures;
```

### `FixtureDefinitions`

```ts
/**
 * Defines one fixture: everything before `await use(value)` is its setup,
 * everything after is its teardown. The fixtures it destructures in its
 * first parameter are the ones it depends on, set up before it; one that
 * needs none writes `async ({}, use) => {}`. The body, its hooks, and the
 * fixtures that name it run while `use` is pending; it resolves once they
 * are done, whether or not the body failed.
 */
export type FixtureFn<Fixtures, Value> = (
  fixtures: Fixtures,
  use: (value: Value) => Promise<void>,
) => Promise<void>;

/**
 * A test fixture: its function, or the function and its options. With
 * `auto: true` it is set up for every test of its chain, whether or not
 * anything names it.
 */
export type TestFixtureDefinition<Fixtures, Value> =
  | FixtureFn<Fixtures, Value>
  | readonly [FixtureFn<Fixtures, Value>, { readonly scope?: 'test'; readonly auto?: boolean }];
/**
 * A worker fixture: its function and `{ scope: 'worker' }`. It sees worker
 * fixtures only. With `auto: true` it is set up once per worker, before the
 * first test or suite hook of its chain, whether or not anything names it.
 */
export type WorkerFixtureDefinition<Worker, Value> = readonly [
  FixtureFn<Worker, Value>,
  { readonly scope: 'worker'; readonly auto?: boolean },
];
/**
 * One definition per fixture `test.extend()` adds: `Extra` holds the test
 * fixtures, `ExtraWorker` the worker fixtures. A definition sees the fixtures
 * of the `test` it extends and the ones declared beside it, in any order: it
 * is set up after the ones it names. A test fixture sees every fixture a
 * test sees; a worker fixture sees worker fixtures only, since it outlives
 * every test fixture.
 *
 * A name the base already has is not a new fixture, so declaring it in
 * `Extra` or `ExtraWorker` is a type error. Defined beside them, it extends
 * that fixture, a built-in one included (`FixtureOverrides`): inside its
 * function its own name is the fixture it extends, and it keeps that
 * fixture's type and scope:
 *
 *   base.extend({ app: async ({ app }, use) => { await app.open('/'); await use(app); } })
 */
export type FixtureDefinitions<Base, Extra, Worker = {}, ExtraWorker = {}> = {
  readonly [K in keyof Extra]: K extends keyof Base
    ? never
    : TestFixtureDefinition<Base & NoInfer<Extra> & NoInfer<ExtraWorker>, Extra[K]>;
} & {
  // Not inferred: an `extend({ ... })` without type arguments infers its test
  // fixtures from the definitions, as before worker fixtures; a worker
  // fixture is declared through the second type argument.
  readonly [K in keyof NoInfer<ExtraWorker>]: K extends keyof Base | keyof Extra
    ? never
    : WorkerFixtureDefinition<Worker & NoInfer<ExtraWorker>, NoInfer<ExtraWorker>[K]>;
} & FixtureOverrides<Base & NoInfer<Extra> & NoInfer<ExtraWorker>, Worker & NoInfer<ExtraWorker>, Base, Worker>;
/**
 * Fixtures that extend ones the base already has, each optional. `Sees` and
 * `WorkerSees` are what an override's function receives: the base's
 * fixtures, and the ones declared beside it.
 */
export type FixtureOverrides<Sees, WorkerSees, Base = Sees, Worker = WorkerSees> = {
  readonly [K in keyof Base]?: FixtureOverride<Base, Worker, K, Sees, WorkerSees>;
};
/**
 * A fixture that extends `K`, one the base already has: it hands over the
 * same type and keeps the scope, so the override of a worker fixture
 * receives worker fixtures (`WorkerSees`) only.
 */
export type FixtureOverride<Base, Worker, K extends keyof Base, Sees, WorkerSees> = K extends keyof Worker
  ? FixtureFn<WorkerSees, Base[K]> | WorkerFixtureDefinition<WorkerSees, Base[K]>
  : TestFixtureDefinition<Sees, Base[K]>;
```

### फ़ंक्शन टाइप

```ts
/**
 * A test body. It names the fixtures it uses by destructuring its first
 * parameter (`async ({ app, screen }) => {}`), and the runner sets up only
 * those; a body that takes the whole object (`async (fixtures) => {}`) or a
 * rest property is a `COLLECTION_ERROR`. The same holds for a hook and for
 * the first parameter of a `test.extend()` fixture.
 */
export type TestFn<Fixtures = TestFixtures> = (fixtures: Fixtures) => void | Promise<void>;

/** A setup test body; `session.save` is the extra fixture. */
export type SetupFn<Fixtures = TestFixtures> = (
  fixtures: Fixtures & SetupFixtures,
) => void | Promise<void>;

/** A hook body: `beforeEach` and `afterEach` get the test's fixtures, `beforeAll` and `afterAll` its worker fixtures. */
export type TestHookFn<Fixtures = TestFixtures> = (fixtures: Fixtures) => void | Promise<void>;

/** @deprecated use `TestHookFn<WorkerFixtures>`. */
export type SuiteHookFn = TestHookFn<WorkerFixtures>;

/** A `describe` body. An async body is a type error. */
export type SynchronousBody<Result> = Extract<Result, PromiseLike<unknown>> extends never
  ? () => Result
  : never;

/**
 * The `test.each` body arguments for the rows' type: array rows spread, then
 * the fixtures. Rows that are not all arrays are passed whole. Not
 * distributive, so a mixed table is decided once, as at run time. An
 * `unknown` row may be either at run time, so only the fixtures, last, are known.
 */
export type EachArgs<Row, Fixtures> = [Row] extends [readonly unknown[]]
  ? [...Row, Fixtures]
  : unknown extends Row
    ? [...unknown[], Fixtures]
    : [Row, Fixtures];

/** A `test.each` or `test.for` body: the row's arguments, then the fixtures. */
export type EachFn<Args extends readonly unknown[]> = (...args: Args) => void | Promise<void>;

/** A `test.skipIf` or `test.runIf` condition. A Promise is a type error. */
export type SynchronousCondition<Condition> = Extract<Condition, PromiseLike<unknown>> extends never
  ? Condition
  : never;

/** Opaque handle of a registered test. */
export interface TestCase {
  readonly [testCaseBrand]: true;
}
```
