-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
320 lines (314 loc) · 11 KB
/
vitest.config.ts
File metadata and controls
320 lines (314 loc) · 11 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import path from "node:path";
import { defineConfig } from "vitest/config";
const PACKAGES = [
"types",
"db",
"crypto",
"sync",
"api-client",
"data",
"queue",
"storage",
"validation",
"rotation-worker",
"email",
"import-core",
"logger",
];
function projectConfig(name: string, root: string) {
return {
test: {
name,
root,
environment: "node",
include: ["src/**/*.{test,spec}.ts"],
exclude: ["**/*.integration.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 5000,
hookTimeout: 10000,
},
};
}
/**
* Integration projects that share an external service (e.g. queue uses a
* single Valkey container) cannot run multiple test files in parallel
* against the same shared infrastructure without state collisions. Listed
* by project name so other integration projects keep their default
* file-level parallelism.
*/
const SHARED_INFRA_INTEGRATION_PROJECTS = new Set<string>(["queue"]);
function integrationProjectConfig(name: string, root: string) {
return {
test: {
name: `${name}-integration`,
root,
environment: "node",
include: ["src/**/*.integration.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 30000,
hookTimeout: 30000,
...(SHARED_INFRA_INTEGRATION_PROJECTS.has(name) ? { fileParallelism: false } : {}),
},
};
}
export default defineConfig({
test: {
projects: [
...PACKAGES.map((name) => projectConfig(name, `packages/${name}`)),
...PACKAGES.map((name) => integrationProjectConfig(name, `packages/${name}`)),
{
test: {
name: "import-sp",
root: "packages/import-sp",
environment: "node",
include: ["src/**/*.{test,spec}.ts"],
exclude: ["**/*.integration.{test,spec}.ts", "**/*.e2e.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 5000,
hookTimeout: 10000,
setupFiles: ["src/__tests__/integration/setup-env.ts"],
},
},
{
test: {
name: "import-sp-integration",
root: "packages/import-sp",
environment: "node",
include: ["src/**/*.integration.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 30000,
hookTimeout: 30000,
setupFiles: ["src/__tests__/integration/setup-env.ts"],
},
},
{
test: {
name: "import-pk",
root: "packages/import-pk",
environment: "node",
include: ["src/**/*.{test,spec}.ts"],
exclude: ["**/*.integration.{test,spec}.ts", "**/*.e2e.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 5000,
hookTimeout: 10000,
},
},
{
test: {
name: "import-pk-integration",
root: "packages/import-pk",
environment: "node",
include: ["src/**/*.integration.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 30000,
hookTimeout: 30000,
},
},
projectConfig("api", "apps/api"),
integrationProjectConfig("api", "apps/api"),
{
test: {
name: "test-utils",
root: "tooling/test-utils",
environment: "node",
include: ["src/**/*.{test,spec}.ts"],
exclude: ["**/*.integration.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 10000,
hookTimeout: 10000,
},
},
{
test: {
name: "scripts",
root: "scripts",
environment: "node",
include: ["**/__tests__/**/*.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 5000,
hookTimeout: 10000,
},
},
{
test: {
name: "eslint-rules",
root: "tooling/eslint-config",
environment: "node",
include: ["rules/**/*.test.js"],
globals: false,
restoreMocks: true,
testTimeout: 5000,
hookTimeout: 10000,
},
},
{
test: {
name: "i18n",
root: "packages/i18n",
environment: "node",
include: ["src/**/*.{test,spec}.{ts,tsx}"],
exclude: ["**/*.integration.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 5000,
hookTimeout: 10000,
},
},
{
resolve: {
alias: {
// react-native uses Flow types and cannot be parsed by rolldown/esbuild
// in a Node/vitest environment. Redirect to a minimal stub so tests
// that transitively import react-native (e.g. via expo-constants) work.
"react-native": path.resolve("apps/mobile/src/__tests__/react-native-mock.ts"),
// Expo native modules — redirect to in-memory mocks so wrapper logic
// (key namespacing, error wrapping, init guards, fallbacks) is testable
// without spinning up a real device or simulator.
"expo-secure-store": path.resolve(
"apps/mobile/src/__tests__/expo-secure-store-mock.ts",
),
"expo-sqlite": path.resolve("apps/mobile/src/__tests__/expo-sqlite-mock.ts"),
"expo-constants": path.resolve("apps/mobile/src/__tests__/expo-constants-mock.ts"),
},
},
test: {
name: "mobile",
root: "apps/mobile",
environment: "node",
include: [
"src/**/*.{test,spec}.{ts,tsx}",
"app/**/*.{test,spec}.{ts,tsx}",
"locales/**/*.{test,spec}.{ts,tsx}",
],
exclude: ["**/*.integration.{test,spec}.ts"],
globals: false,
restoreMocks: true,
testTimeout: 10000,
hookTimeout: 10000,
},
},
],
coverage: {
provider: "v8",
include: ["packages/*/src/**/*.ts", "apps/api/src/**/*.ts", "apps/mobile/src/**/*.{ts,tsx}"],
exclude: [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.integration.test.ts",
"**/*.integration.spec.ts",
"**/__tests__/**",
"**/test/**",
"**/*.d.ts",
"**/index.ts",
// Type-only files: `.types.ts` modules export only TypeScript
// declarations; the SoT manifest is generated from those types and
// contains no executable code worth covering.
"**/*.types.ts",
"**/__sot-manifest__.ts",
// Type-only files (no executable code — validated via expectTypeOf tests).
// Per-entity splits live under packages/types/src/entities/; add new files
// to the entities/ glob, not an individual line.
"packages/types/src/entities/**/*.ts",
"packages/types/src/encryption-primitives.ts",
"packages/types/src/response-unions.ts",
"packages/types/src/pagination.ts",
"packages/types/src/results.ts",
"packages/types/src/i18n.ts",
"packages/types/src/littles-safe-mode.ts",
"packages/types/src/timestamps.ts",
"packages/types/src/utility.ts",
"packages/types/src/analytics.ts",
"packages/types/src/image-source.ts",
"packages/types/src/jobs.ts",
"packages/types/src/logger.ts",
"packages/types/src/pk-bridge.ts",
"packages/types/src/realtime.ts",
"packages/types/src/search.ts",
"packages/types/src/friend-dashboard.ts",
"packages/types/src/friend-export.ts",
"packages/types/src/reports.ts",
"packages/types/src/nomenclature.ts",
"packages/types/src/subscription-events.ts",
"packages/crypto/src/types.ts",
"packages/crypto/src/adapter/interface.ts",
"packages/crypto/src/lifecycle-types.ts",
"packages/crypto/src/key-storage.ts",
"packages/crypto/src/blob-pipeline/blob-encryption-metadata.ts",
"packages/db/src/client/types.ts",
"packages/db/src/helpers/types.ts",
"packages/db/src/views/types.ts",
"packages/i18n/src/types.ts",
// Auto-generated openapi types
"packages/api-client/src/generated/api-types.ts",
// sync: event-map is interface-only
"packages/sync/src/event-bus/event-map.ts",
// Drizzle schema files are declarative — callbacks only run during migration generation
"packages/db/src/schema/**/*.ts",
// DB query helpers are tested via integration tests, not unit tests
"packages/db/src/queries/**/*.ts",
// queue: interface-only files (no executable code)
"packages/queue/src/types.ts",
"packages/queue/src/event-hooks.ts",
"packages/queue/src/heartbeat.ts",
"packages/queue/src/job-queue.ts",
"packages/queue/src/job-worker.ts",
// storage: interface-only files (no executable code)
"packages/storage/src/interface.ts",
// sync: CRDT schema interfaces and adapter interfaces (no executable code)
"packages/sync/src/schemas.ts",
"packages/sync/src/schemas/bucket.ts",
"packages/sync/src/schemas/chat.ts",
"packages/sync/src/schemas/common.ts",
"packages/sync/src/schemas/fronting.ts",
"packages/sync/src/schemas/journal.ts",
"packages/sync/src/schemas/notes.ts",
"packages/sync/src/schemas/privacy-config.ts",
"packages/sync/src/schemas/system-core.ts",
"packages/sync/src/adapters.ts",
"packages/sync/src/adapters/network-adapter.ts",
"packages/sync/src/adapters/offline-queue-adapter.ts",
"packages/sync/src/adapters/storage-adapter.ts",
"packages/sync/src/conflict-persistence.ts",
"packages/sync/src/relay-service.ts",
// rotation-worker: interface-only file
"packages/rotation-worker/src/types.ts",
// email: interface-only and type-only files (no executable code)
"packages/email/src/interface.ts",
"packages/email/src/templates/types.ts",
// mobile: type-only files
"apps/mobile/src/auth/auth-types.ts",
"apps/mobile/src/platform/types.ts",
// api: middleware store interfaces and service type definitions
"apps/api/src/middleware/idempotency-store.ts",
"apps/api/src/middleware/rate-limit-store.ts",
"apps/api/src/services/hierarchy-service-types.ts",
// import-core: test utilities are helpers, not production code
"packages/import-core/src/testing/**/*.ts",
],
reporter: [
"text",
["json-summary", { file: "coverage-summary.json" }],
["json", { file: "coverage-final.json" }],
"lcov",
"html",
],
reportsDirectory: "./coverage",
// packages/db has only integration tests currently; unit coverage
// will be enforced when db schema code (db-2je4) is added
thresholds: {
lines: 89,
functions: 89,
branches: 89,
statements: 89,
},
},
},
});