eletrotupi / tcc/ api/vitest.config.tsaaca724b6020e9a1b82acb9cc3bb90f81951dc21
1.7 KB | 53 lines Raw
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
    // Report-only: there is no threshold and CI does not gate on it. The point
10
    // is a visible unit-versus-integration ratio, not a build-breaking number.
11
    coverage: {
12
      provider: 'v8',
13
      reporter: ['text', 'html'],
14
      include: ['src/**/*.ts'],
15
      exclude: ['src/**/*.d.ts'],
16
    },
17
    projects: [
18
      // Pure tests: a single function, no HTTP, no database. No global mocks,
19
      // so files run in parallel and need no running stack. The token module
20
      // reads its secret at import time and this project runs without dotenv,
21
      // so the env carries it.
22
      {
23
        plugins: [appPaths()],
24
        test: {
25
          name: 'unit',
26
          environment: 'node',
27
          include: ['tests/**/*.unit.test.ts'],
28
          fileParallelism: true,
29
          testTimeout: 15_000,
30
          env: { JWT_SECRET: 'unit-test-secret' },
31
        },
32
      },
33

34
      // Integration and job tests: real app and database, serial because every
35
      // file shares one database. Excludes the unit files so none runs twice.
36
      {
37
        plugins: [appPaths()],
38
        test: {
39
          name: 'db',
40
          environment: 'node',
41
          include: ['tests/**/*.test.ts'],
42
          exclude: ['**/node_modules/**', 'tests/**/*.unit.test.ts'],
43
          setupFiles: ['./tests/setup.ts'],
44
          fileParallelism: false,
45
          testTimeout: 15_000,
46
          typecheck: {
47
            tsconfig: './tsconfig.test.json',
48
          },
49
        },
50
      },
51
    ],
52
  },
53
})