Co-locating test files next to their TypeScript source files is argued to be superior to a centralized tests folder. Key benefits include instant test discovery in file explorers, tests automatically moving with source files during refactors, visual coverage gaps without needing a coverage tool, shorter and more stable import paths, and clearer code ownership in large teams. For integration and E2E tests that span multiple modules, a dedicated top-level directory is still recommended. Both Vitest and Jest support co-located test discovery out of the box with no extra configuration.
Table of contents
ContentsThe Problem with a Centralized Tests FolderCo-location: Tests Right Next to the CodeBenefitsWhat About Integration and E2E Tests?Setting Up Co-locationSort: