-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
54 lines (49 loc) · 1.6 KB
/
Copy pathvitest.config.ts
File metadata and controls
54 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { defineConfig } from 'vitest/config'
import path from 'path'
const alias = {
'@': path.resolve(__dirname, '.'),
// `server-only` is a build-time guard whose real entry point always throws;
// Next.js swaps it out during bundling, Vitest cannot. Without this stub any
// test that transitively imports a server-only module fails at import time.
'server-only': path.resolve(__dirname, 'tests/stubs/server-only.ts'),
}
const unitProject = {
resolve: { alias },
test: {
name: 'unit',
globals: true,
environment: 'node' as const,
include: ['**/*.test.ts'],
// `.claude/worktrees/*` are ephemeral agent checkouts whose `@/*` imports
// resolve back to this root: never part of the suite.
exclude: ['**/node_modules/**', '**/*.pg.test.ts', '**/.claude/**'],
},
}
const pgRealProject = {
resolve: { alias },
test: {
name: 'pg-real',
globals: true,
environment: 'node' as const,
include: ['**/*.pg.test.ts'],
exclude: ['**/node_modules/**', '**/.claude/**'],
setupFiles: ['tests/pg/setup.ts'],
// One-connection-at-a-time to avoid cross-file DB contention.
fileParallelism: false,
testTimeout: 15000,
},
}
// Only register the pg-real project when DATABASE_URL is set. Local devs
// running a bare `vitest run` would otherwise hit the schema sanity check
// against a non-existent DB. `npm run test:pg` is the opt-in entry point.
const projects = process.env.DATABASE_URL
? [unitProject, pgRealProject]
: [unitProject]
export default defineConfig({
resolve: { alias },
test: {
globals: true,
environment: 'node',
projects,
},
})