| 1 | import { defineConfig } from 'vitest/config'
|
| 2 | import tsconfigPaths from 'vite-tsconfig-paths'
|
| 3 |
|
| 4 | // Both projects import source through the same `@app/*` alias the app uses
|
| 5 | const appPaths = () => tsconfigPaths({ projects: ['./tsconfig.test.json'] })
|
| 6 |
|
| 7 | export default defineConfig({
|
| 8 | test: {
|
| 9 | // Every database test file truncates and repopulates the same database, so
|
| 10 | // they must not overlap. This has to live at the root: a project's own
|
| 11 | // `fileParallelism` is not honored, and the default (parallel) corrupts the
|
| 12 | // shared database across files.
|
| 13 | fileParallelism: false,
|
| 14 |
|
| 15 | // Report-only: there is no threshold and CI does not gate on it. The point
|
| 16 | // is a visible unit-versus-integration ratio, not a build-breaking number.
|
| 17 | coverage: {
|
| 18 | provider: 'v8',
|
| 19 | reporter: ['text', 'html'],
|
| 20 | include: ['src/**/*.ts'],
|
| 21 | exclude: ['src/**/*.d.ts'],
|
| 22 | },
|
| 23 |
|
| 24 | projects: [
|
| 25 | // Pure tests: a single function, no HTTP, no database. No global mocks,
|
| 26 | // so files need no running stack. The token module reads its secret at
|
| 27 | // import time and this project runs without dotenv, so the env carries it.
|
| 28 | {
|
| 29 | plugins: [appPaths()],
|
| 30 | test: {
|
| 31 | name: 'unit',
|
| 32 | environment: 'node',
|
| 33 | include: ['tests/**/*.unit.test.ts'],
|
| 34 | testTimeout: 15_000,
|
| 35 | env: { JWT_SECRET: 'unit-test-secret' },
|
| 36 | },
|
| 37 | },
|
| 38 |
|
| 39 | // Integration and job tests: real app and database. Excludes the unit
|
| 40 | // files so none runs twice.
|
| 41 | {
|
| 42 | plugins: [appPaths()],
|
| 43 | test: {
|
| 44 | name: 'db',
|
| 45 | environment: 'node',
|
| 46 | include: ['tests/**/*.test.ts'],
|
| 47 | exclude: ['**/node_modules/**', 'tests/**/*.unit.test.ts'],
|
| 48 | setupFiles: ['./tests/setup.ts'],
|
| 49 | testTimeout: 15_000,
|
| 50 | typecheck: {
|
| 51 | tsconfig: './tsconfig.test.json',
|
| 52 | },
|
| 53 | },
|
| 54 | },
|
| 55 | ],
|
| 56 | },
|
| 57 | })
|