globalSetup
- Type:
string | string[] - Default:
undefined
The globalSetup option in Rstest allows you to run setup and teardown code that executes once before all tests and after all tests complete. This is useful for:
- Starting and stopping databases
- Initializing test services
- Cleaning up resources after test runs
rstest.config.ts
Global setup file formats
You can write global setup files in two formats:
Named functions (recommended)
Default function returning teardown
Note
Global setup is running in a different global context, so your tests don't have access to variables defined here.
Multiple global setup files
When using multiple global setup files:
- Setup functions execute sequentially in the order provided
- Teardown functions execute in reverse order (LIFO - Last In, First Out)
- If any setup fails, the entire test run fails
Differences from setupFiles
Example: database setup
rstest.config.ts