@reasonabletech/config-vitest 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -0
- package/dist/src/global-setup.d.ts +15 -0
- package/dist/src/global-setup.d.ts.map +1 -0
- package/dist/src/index.d.ts +63 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +352 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/node.d.ts +29 -0
- package/dist/src/node.d.ts.map +1 -0
- package/dist/src/node.js +209 -0
- package/dist/src/node.js.map +1 -0
- package/dist/src/react.d.ts +46 -0
- package/dist/src/react.d.ts.map +1 -0
- package/dist/src/react.js +225 -0
- package/dist/src/react.js.map +1 -0
- package/dist/src/workspace.d.ts +29 -0
- package/dist/src/workspace.d.ts.map +1 -0
- package/dist/src/workspace.js +33 -0
- package/dist/src/workspace.js.map +1 -0
- package/docs/README.md +28 -0
- package/docs/api/api-reference.md +469 -0
- package/docs/api/base-config.md +542 -0
- package/docs/guides/migration.md +47 -0
- package/docs/guides/usage-guide.md +81 -0
- package/package.json +100 -0
- package/src/global-setup.ts +58 -0
- package/src/index.ts +280 -0
- package/src/node.ts +74 -0
- package/src/react.ts +241 -0
- package/src/workspace.ts +62 -0
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
# Base Configuration API Reference
|
|
2
|
+
|
|
3
|
+
The base Vitest configuration provides common settings for all testing environments in the the ecosystem.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Basic Usage
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// vitest.config.ts
|
|
11
|
+
import { baseConfig } from "@reasonabletech/config-vitest";
|
|
12
|
+
|
|
13
|
+
export default baseConfig;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Extended Configuration
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
// vitest.config.ts
|
|
20
|
+
import { defineConfig } from "vitest/config";
|
|
21
|
+
import { baseConfig } from "@reasonabletech/config-vitest";
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
...baseConfig,
|
|
25
|
+
test: {
|
|
26
|
+
...baseConfig.test,
|
|
27
|
+
// Override or extend settings
|
|
28
|
+
timeout: 30000,
|
|
29
|
+
globals: true,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Configuration Options
|
|
35
|
+
|
|
36
|
+
### Test Settings
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
interface TestConfig {
|
|
40
|
+
// Test discovery
|
|
41
|
+
include: string[];
|
|
42
|
+
exclude: string[];
|
|
43
|
+
|
|
44
|
+
// Test execution
|
|
45
|
+
timeout: number;
|
|
46
|
+
hookTimeout: number;
|
|
47
|
+
testTimeout: number;
|
|
48
|
+
|
|
49
|
+
// Environment
|
|
50
|
+
environment: "node" | "jsdom" | "happy-dom";
|
|
51
|
+
globals: boolean;
|
|
52
|
+
|
|
53
|
+
// Coverage
|
|
54
|
+
coverage: CoverageConfig;
|
|
55
|
+
|
|
56
|
+
// Reporters
|
|
57
|
+
reporter: string[];
|
|
58
|
+
outputFile: Record<string, string>;
|
|
59
|
+
|
|
60
|
+
// Setup
|
|
61
|
+
setupFiles: string[];
|
|
62
|
+
globalSetup: string[];
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Default Values
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const defaultConfig = {
|
|
70
|
+
test: {
|
|
71
|
+
// Test discovery
|
|
72
|
+
include: [
|
|
73
|
+
"**/*.test.{ts,tsx,js,jsx}",
|
|
74
|
+
"**/__tests__/**/*.{ts,tsx,js,jsx}",
|
|
75
|
+
"**/tests/**/*.{ts,tsx,js,jsx}",
|
|
76
|
+
],
|
|
77
|
+
exclude: [
|
|
78
|
+
"**/node_modules/**",
|
|
79
|
+
"**/dist/**",
|
|
80
|
+
"**/build/**",
|
|
81
|
+
"**/.next/**",
|
|
82
|
+
"**/.nuxt/**",
|
|
83
|
+
"**/.vercel/**",
|
|
84
|
+
],
|
|
85
|
+
|
|
86
|
+
// Test execution
|
|
87
|
+
timeout: 10000,
|
|
88
|
+
hookTimeout: 10000,
|
|
89
|
+
testTimeout: 5000,
|
|
90
|
+
|
|
91
|
+
// Environment
|
|
92
|
+
environment: "node",
|
|
93
|
+
globals: false,
|
|
94
|
+
|
|
95
|
+
// Coverage
|
|
96
|
+
coverage: {
|
|
97
|
+
provider: "v8",
|
|
98
|
+
reporter: ["text", "json", "html"],
|
|
99
|
+
exclude: [
|
|
100
|
+
"**/node_modules/**",
|
|
101
|
+
"**/dist/**",
|
|
102
|
+
"**/*.config.*",
|
|
103
|
+
"**/*.test.*",
|
|
104
|
+
"**/coverage/**",
|
|
105
|
+
],
|
|
106
|
+
thresholds: {
|
|
107
|
+
global: {
|
|
108
|
+
branches: 80,
|
|
109
|
+
functions: 80,
|
|
110
|
+
lines: 80,
|
|
111
|
+
statements: 80,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
// Reporters
|
|
117
|
+
reporter: ["default", "json", "html"],
|
|
118
|
+
outputFile: {
|
|
119
|
+
json: "./coverage/results.json",
|
|
120
|
+
html: "./coverage/index.html",
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
// Setup
|
|
124
|
+
setupFiles: ["./vitest.setup.ts"],
|
|
125
|
+
globalSetup: ["./tests/global-setup.ts"],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Environment Configuration
|
|
131
|
+
|
|
132
|
+
### Node Environment
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const nodeConfig = {
|
|
136
|
+
test: {
|
|
137
|
+
environment: "node",
|
|
138
|
+
// Node-specific settings
|
|
139
|
+
pool: "forks",
|
|
140
|
+
poolOptions: {
|
|
141
|
+
forks: {
|
|
142
|
+
singleFork: true,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Browser Environment
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
const browserConfig = {
|
|
153
|
+
test: {
|
|
154
|
+
environment: "jsdom",
|
|
155
|
+
// Browser-specific settings
|
|
156
|
+
setupFiles: ["./tests/setup-jsdom.ts"],
|
|
157
|
+
environmentOptions: {
|
|
158
|
+
jsdom: {
|
|
159
|
+
resources: "usable",
|
|
160
|
+
url: "http://localhost:3000",
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Coverage Configuration
|
|
168
|
+
|
|
169
|
+
### Default Coverage
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const coverageConfig = {
|
|
173
|
+
coverage: {
|
|
174
|
+
provider: "v8",
|
|
175
|
+
reporter: ["text", "json", "html", "lcov"],
|
|
176
|
+
reportsDirectory: "./coverage",
|
|
177
|
+
exclude: [
|
|
178
|
+
"**/node_modules/**",
|
|
179
|
+
"**/dist/**",
|
|
180
|
+
"**/*.config.*",
|
|
181
|
+
"**/*.test.*",
|
|
182
|
+
"**/coverage/**",
|
|
183
|
+
"**/.next/**",
|
|
184
|
+
"**/build/**",
|
|
185
|
+
],
|
|
186
|
+
thresholds: {
|
|
187
|
+
global: {
|
|
188
|
+
branches: 80,
|
|
189
|
+
functions: 80,
|
|
190
|
+
lines: 80,
|
|
191
|
+
statements: 80,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
skipFull: true,
|
|
195
|
+
clean: true,
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Custom Coverage
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
const customCoverageConfig = {
|
|
204
|
+
coverage: {
|
|
205
|
+
provider: "istanbul",
|
|
206
|
+
reporter: ["text", "cobertura"],
|
|
207
|
+
reportsDirectory: "./reports/coverage",
|
|
208
|
+
thresholds: {
|
|
209
|
+
global: {
|
|
210
|
+
branches: 90,
|
|
211
|
+
functions: 90,
|
|
212
|
+
lines: 90,
|
|
213
|
+
statements: 90,
|
|
214
|
+
},
|
|
215
|
+
"./src/core/**": {
|
|
216
|
+
branches: 95,
|
|
217
|
+
functions: 95,
|
|
218
|
+
lines: 95,
|
|
219
|
+
statements: 95,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Reporter Configuration
|
|
227
|
+
|
|
228
|
+
### Default Reporters
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const reporterConfig = {
|
|
232
|
+
reporter: ["default", "json", "html"],
|
|
233
|
+
outputFile: {
|
|
234
|
+
json: "./test-results.json",
|
|
235
|
+
html: "./test-results.html",
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Custom Reporters
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const customReporterConfig = {
|
|
244
|
+
reporter: [
|
|
245
|
+
"default",
|
|
246
|
+
"json",
|
|
247
|
+
"junit",
|
|
248
|
+
["html", { outputFile: "./reports/test-results.html" }],
|
|
249
|
+
],
|
|
250
|
+
outputFile: {
|
|
251
|
+
json: "./reports/results.json",
|
|
252
|
+
junit: "./reports/junit.xml",
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Setup Files
|
|
258
|
+
|
|
259
|
+
### Test Setup
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
// vitest.setup.ts
|
|
263
|
+
import "./tests/setup.js";
|
|
264
|
+
|
|
265
|
+
// tests/setup.ts
|
|
266
|
+
import { vi } from "vitest";
|
|
267
|
+
import { beforeEach, afterEach } from "vitest";
|
|
268
|
+
|
|
269
|
+
// Global test setup
|
|
270
|
+
beforeEach(() => {
|
|
271
|
+
// Setup before each test
|
|
272
|
+
vi.clearAllMocks();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
afterEach(() => {
|
|
276
|
+
// Cleanup after each test
|
|
277
|
+
vi.resetAllMocks();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Mock global objects
|
|
281
|
+
Object.defineProperty(window, "matchMedia", {
|
|
282
|
+
writable: true,
|
|
283
|
+
value: vi.fn().mockImplementation((query) => ({
|
|
284
|
+
matches: false,
|
|
285
|
+
media: query,
|
|
286
|
+
onchange: null,
|
|
287
|
+
addListener: vi.fn(),
|
|
288
|
+
removeListener: vi.fn(),
|
|
289
|
+
addEventListener: vi.fn(),
|
|
290
|
+
removeEventListener: vi.fn(),
|
|
291
|
+
dispatchEvent: vi.fn(),
|
|
292
|
+
})),
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Global Setup
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
// tests/global-setup.ts
|
|
300
|
+
import { GlobalSetupContext } from "vitest/node";
|
|
301
|
+
|
|
302
|
+
export default function globalSetup({ provide }: GlobalSetupContext) {
|
|
303
|
+
// Global setup logic
|
|
304
|
+
console.log("Running global setup...");
|
|
305
|
+
|
|
306
|
+
// Provide values to tests
|
|
307
|
+
provide("testApiUrl", "http://localhost:3001");
|
|
308
|
+
|
|
309
|
+
// Return cleanup function
|
|
310
|
+
return () => {
|
|
311
|
+
console.log("Running global teardown...");
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## TypeScript Configuration
|
|
317
|
+
|
|
318
|
+
### Type Definitions
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
/// <reference types="vitest" />
|
|
322
|
+
/// <reference types="vite/client" />
|
|
323
|
+
|
|
324
|
+
declare module "vitest" {
|
|
325
|
+
interface TestContext {
|
|
326
|
+
// Custom test context
|
|
327
|
+
testApiUrl: string;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### TypeScript Config
|
|
333
|
+
|
|
334
|
+
```json
|
|
335
|
+
{
|
|
336
|
+
"compilerOptions": {
|
|
337
|
+
"types": ["vitest/globals", "vitest/importMeta"]
|
|
338
|
+
},
|
|
339
|
+
"include": ["src/**/*", "tests/**/*", "vitest.config.ts"]
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Performance Optimization
|
|
344
|
+
|
|
345
|
+
### Parallel Execution
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
const performanceConfig = {
|
|
349
|
+
test: {
|
|
350
|
+
pool: "threads",
|
|
351
|
+
poolOptions: {
|
|
352
|
+
threads: {
|
|
353
|
+
maxThreads: 4,
|
|
354
|
+
minThreads: 1,
|
|
355
|
+
singleThread: false,
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### File Processing
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
const optimizedConfig = {
|
|
366
|
+
test: {
|
|
367
|
+
// Optimize file processing
|
|
368
|
+
cache: {
|
|
369
|
+
dir: "./node_modules/.vitest",
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
// Optimize test discovery
|
|
373
|
+
passWithNoTests: true,
|
|
374
|
+
|
|
375
|
+
// Optimize coverage
|
|
376
|
+
coverage: {
|
|
377
|
+
skipFull: true,
|
|
378
|
+
clean: true,
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## Debugging Configuration
|
|
385
|
+
|
|
386
|
+
### Debug Mode
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
const debugConfig = {
|
|
390
|
+
test: {
|
|
391
|
+
// Enable debugging
|
|
392
|
+
pool: "forks",
|
|
393
|
+
poolOptions: {
|
|
394
|
+
forks: {
|
|
395
|
+
singleFork: true,
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
// Increase timeouts for debugging
|
|
400
|
+
timeout: 0,
|
|
401
|
+
hookTimeout: 0,
|
|
402
|
+
testTimeout: 0,
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Verbose Output
|
|
408
|
+
|
|
409
|
+
```typescript
|
|
410
|
+
const verboseConfig = {
|
|
411
|
+
test: {
|
|
412
|
+
reporter: ["verbose", "json"],
|
|
413
|
+
logHeapUsage: true,
|
|
414
|
+
silent: false,
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## Common Patterns
|
|
420
|
+
|
|
421
|
+
### Configuration Factory
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
export function createTestConfig(options: TestConfigOptions = {}) {
|
|
425
|
+
return defineConfig({
|
|
426
|
+
...baseConfig,
|
|
427
|
+
test: {
|
|
428
|
+
...baseConfig.test,
|
|
429
|
+
...options,
|
|
430
|
+
coverage: {
|
|
431
|
+
...baseConfig.test.coverage,
|
|
432
|
+
...options.coverage,
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Environment-Specific Config
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
export function createEnvironmentConfig(env: "node" | "jsdom" | "happy-dom") {
|
|
443
|
+
const environmentConfigs = {
|
|
444
|
+
node: nodeConfig,
|
|
445
|
+
jsdom: browserConfig,
|
|
446
|
+
"happy-dom": browserConfig,
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
return defineConfig({
|
|
450
|
+
...baseConfig,
|
|
451
|
+
test: {
|
|
452
|
+
...baseConfig.test,
|
|
453
|
+
...environmentConfigs[env],
|
|
454
|
+
},
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### Testing Utilities
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
export const testUtils = {
|
|
463
|
+
// Create test server
|
|
464
|
+
createTestServer: () => {
|
|
465
|
+
// Test server implementation
|
|
466
|
+
},
|
|
467
|
+
|
|
468
|
+
// Create test database
|
|
469
|
+
createTestDatabase: () => {
|
|
470
|
+
// Test database implementation
|
|
471
|
+
},
|
|
472
|
+
|
|
473
|
+
// Common test fixtures
|
|
474
|
+
fixtures: {
|
|
475
|
+
user: () => ({ id: "1", name: "Test User" }),
|
|
476
|
+
post: () => ({ id: "1", title: "Test Post" }),
|
|
477
|
+
},
|
|
478
|
+
};
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
## Integration Examples
|
|
482
|
+
|
|
483
|
+
### Monorepo Configuration
|
|
484
|
+
|
|
485
|
+
```typescript
|
|
486
|
+
// packages/shared/vitest.config.ts
|
|
487
|
+
import { defineConfig } from "vitest/config";
|
|
488
|
+
import { baseConfig } from "@reasonabletech/config-vitest";
|
|
489
|
+
|
|
490
|
+
export default defineConfig({
|
|
491
|
+
...baseConfig,
|
|
492
|
+
test: {
|
|
493
|
+
...baseConfig.test,
|
|
494
|
+
// Package-specific settings
|
|
495
|
+
environment: "node",
|
|
496
|
+
coverage: {
|
|
497
|
+
...baseConfig.test.coverage,
|
|
498
|
+
include: ["src/**/*"],
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### CI/CD Integration
|
|
505
|
+
|
|
506
|
+
```yaml
|
|
507
|
+
# .github/workflows/test.yml
|
|
508
|
+
name: Test
|
|
509
|
+
on: [push, pull_request]
|
|
510
|
+
|
|
511
|
+
jobs:
|
|
512
|
+
test:
|
|
513
|
+
runs-on: ubuntu-latest
|
|
514
|
+
steps:
|
|
515
|
+
- uses: actions/checkout@v4
|
|
516
|
+
- uses: pnpm/action-setup@v4
|
|
517
|
+
- uses: actions/setup-node@v4
|
|
518
|
+
with:
|
|
519
|
+
node-version: "22"
|
|
520
|
+
cache: "pnpm"
|
|
521
|
+
- run: pnpm install --frozen-lockfile
|
|
522
|
+
- run: pnpm test:coverage
|
|
523
|
+
- uses: codecov/codecov-action@v3
|
|
524
|
+
with:
|
|
525
|
+
file: ./coverage/lcov.info
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
## Best Practices
|
|
529
|
+
|
|
530
|
+
1. **Use consistent configuration** across all packages
|
|
531
|
+
2. **Set appropriate timeouts** for different test types
|
|
532
|
+
3. **Configure coverage thresholds** to maintain quality
|
|
533
|
+
4. **Use setup files** for common test initialization
|
|
534
|
+
5. **Optimize performance** with appropriate pool settings
|
|
535
|
+
6. **Enable debugging** when needed with single-threaded execution
|
|
536
|
+
7. **Use TypeScript** for better configuration validation
|
|
537
|
+
|
|
538
|
+
## See Also
|
|
539
|
+
|
|
540
|
+
- [Node Configuration](./node-config.md) - Node.js specific settings
|
|
541
|
+
- [React Configuration](./react-config.md) - React testing configuration
|
|
542
|
+
- [Testing Strategies](../guides/testing-strategies.md) - Testing best practices
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Migration Guide
|
|
2
|
+
|
|
3
|
+
This guide documents breaking changes and how to migrate between major versions of @reasonabletech/config-vitest.
|
|
4
|
+
|
|
5
|
+
## Current Version
|
|
6
|
+
|
|
7
|
+
The current major version is **0.x** (pre-1.0). The API is stabilizing but may have breaking changes before 1.0.
|
|
8
|
+
|
|
9
|
+
## Future Migration Notes
|
|
10
|
+
|
|
11
|
+
_No breaking changes documented yet. This section will be updated when breaking changes are released._
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Migration Template
|
|
16
|
+
|
|
17
|
+
When documenting a breaking change, use this structure:
|
|
18
|
+
|
|
19
|
+
### Migrating from X.x to Y.0
|
|
20
|
+
|
|
21
|
+
#### Breaking Changes
|
|
22
|
+
|
|
23
|
+
1. **Change description** - Brief explanation of what changed
|
|
24
|
+
|
|
25
|
+
**Before:**
|
|
26
|
+
```typescript
|
|
27
|
+
// Old usage
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**After:**
|
|
31
|
+
```typescript
|
|
32
|
+
// New usage
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. **Another change** - Description
|
|
36
|
+
|
|
37
|
+
#### Deprecations
|
|
38
|
+
|
|
39
|
+
- `oldFunction()` is deprecated in favor of `newFunction()`
|
|
40
|
+
|
|
41
|
+
#### New Features
|
|
42
|
+
|
|
43
|
+
- Feature description
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
_Last updated: [date]_
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @reasonabletech/config-vitest Usage Guide
|
|
2
|
+
|
|
3
|
+
This guide covers canonical usage patterns for Vitest configuration in greenfield packages.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @reasonabletech/config-vitest vitest vite @vitest/coverage-v8
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// vitest.config.mts
|
|
15
|
+
import { createVitestConfig } from "@reasonabletech/config-vitest";
|
|
16
|
+
|
|
17
|
+
export default createVitestConfig(import.meta.dirname);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Factory Selection
|
|
21
|
+
|
|
22
|
+
### Base Projects
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { createVitestConfig } from "@reasonabletech/config-vitest";
|
|
26
|
+
|
|
27
|
+
export default createVitestConfig(import.meta.dirname);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### React Projects
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { createReactConfig } from "@reasonabletech/config-vitest/react";
|
|
34
|
+
|
|
35
|
+
export default createReactConfig(import.meta.dirname);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Node Projects
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createNodeConfig } from "@reasonabletech/config-vitest/node";
|
|
42
|
+
|
|
43
|
+
export default createNodeConfig(import.meta.dirname);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Long-Running Integration Suites
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { createLongRunningTestConfig } from "@reasonabletech/config-vitest";
|
|
50
|
+
|
|
51
|
+
export default createLongRunningTestConfig(import.meta.dirname, {
|
|
52
|
+
test: {
|
|
53
|
+
include: ["tests/integration/**/*.test.ts"],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Coverage Defaults
|
|
59
|
+
|
|
60
|
+
- Provider: `v8`
|
|
61
|
+
- Report directory: `generated/test-coverage`
|
|
62
|
+
- Reporters: `text`, `html`, `lcov`, `json`
|
|
63
|
+
- Thresholds: `100` for lines/functions/branches/statements
|
|
64
|
+
|
|
65
|
+
Set `VITEST_COVERAGE_THRESHOLDS_DISABLED=true` when temporary local diagnostics are needed.
|
|
66
|
+
|
|
67
|
+
## Troubleshooting
|
|
68
|
+
|
|
69
|
+
### Self-imports fail in tests
|
|
70
|
+
|
|
71
|
+
Pass `import.meta.dirname` to the factory. This enables auto aliasing from package name to local `src/`.
|
|
72
|
+
|
|
73
|
+
### Missing setup files
|
|
74
|
+
|
|
75
|
+
The config auto-detects `vitest.setup.ts` and `tests/setup.ts` only when they exist. Create one of these files if you need framework setup hooks.
|
|
76
|
+
|
|
77
|
+
## Related Documentation
|
|
78
|
+
|
|
79
|
+
- [Package Docs Index](../README.md)
|
|
80
|
+
- [Base Config Details](../api/base-config.md)
|
|
81
|
+
- [Package README](../../README.md)
|