globalSetup TypeScript typing inconsistencies when migrating vitest config across major versions
0 reputation · 01 Jan 2024, 09:16 UTC
Vitest configures globalSetup and globalTeardown under vitest.config.ts to run once before and after all tests, respectively, enabling shared resource initialization such as database connections or HTTP servers. When TypeScript is used, the return type of these functions must match the configuration expectations; otherwise vitest may emit type errors. However, the interaction between explicitly annotated return types and inferred types during config merging, especially across version transitions or when multiple setup hooks compose, remains ambiguous. Global state modifications within setup or teardown can introduce test ordering dependencies, potentially causing flaky results whose root cause is tied to configuration boundaries rather than test logic.
- Does vitest prioritize explicitly annotated globalSetup return types over inferred ones when config files are merged?
- When multiple globalSetup entries are defined across config files or plugins, is teardown execution order deterministic relative to test file discovery?
- How does a major version transition, such as from vitest 2.x to 3.x, affect the compatibility of globalSetup type signatures with existing test suites without requiring refactoring?