vitest.setup.ts
944 bytes
| 1 | // Global Vitest setup — runs before every test file. |
|---|---|
| 2 | // |
| 3 | // - Pins VITE_API_BASE_URL so services that import httpClient at module load |
| 4 | // have a stable URL for MSW to match against. |
| 5 | // - Registers the i18n plugin globally so any mounted component can call |
| 6 | // useI18n() without the test having to wire it up. |
| 7 | // - Clears localStorage between tests so the auth store starts from a clean slate. |
| 8 | |
| 9 | import { beforeEach } from 'vitest' |
| 10 | import { config } from '@vue/test-utils' |
| 11 | |
| 12 | // Stub env var before any module reads `import.meta.env.VITE_API_BASE_URL`. |
| 13 | // Vitest evaluates setupFiles before test file imports, so this is early enough. |
| 14 | ;(import.meta.env as Record<string, string>).VITE_API_BASE_URL = 'http://test.local/api/v1/' |
| 15 | |
| 16 | // Lazy-import i18n so the env stub above wins for any module it transitively pulls in. |
| 17 | const { default: i18n } = await import('@/i18n') |
| 18 | config.global.plugins = [i18n] |
| 19 | |
| 20 | beforeEach(() => { |
| 21 | localStorage.clear() |
| 22 | }) |
| 23 | |