> For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt.

# sequence


[Added in v0.12.6](https://github.com/web-infra-dev/rstest/releases/tag/v0.12.6)

- **Type:** `{ hooks?: 'stack' | 'list' }`
- **Default:** `{ hooks: 'stack' }`

Configure the execution order of Rstest lifecycle hooks.

## sequence.hooks

- **Type:** `'stack' | 'list'`
- **Default:** `'stack'`

Controls the order of hooks within each suite:

- `'stack'`: `beforeAll` and `beforeEach` run in declaration order; `afterAll` and `afterEach` run in reverse declaration order.
- `'list'`: all four hooks run in declaration order. Use this when migrating from Jest if cleanup depends on hook registration order, such as unmounting components before resetting stores.

For nested suites, `beforeEach` still runs from parent to child, and `afterEach` still runs from child to parent.

Cleanup functions returned by `beforeEach` run after all `afterEach` hooks; those returned by `beforeAll` run after the suite's `afterAll` hooks. They also follow this option: `'stack'` runs them in reverse order of their corresponding setup hooks, while `'list'` runs them in the same order. For nested `beforeEach` hooks, this includes cleanup from both parent and child suites.

v0.12.6 fixes an inconsistency where returned cleanup functions ran in setup order while `afterEach` and `afterAll` ran in reverse order. Returned cleanup functions now also run in reverse setup order by default. This changes their execution order compared with earlier versions.

This option does not change fixture teardown, `onTestFinished`, or `onTestFailed`.

```ts title="rstest.config.ts"
import { defineConfig } from '@rstest/core';

export default defineConfig({
  sequence: {
    hooks: 'list',
  },
});
```
