@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
package/docs/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @reasonabletech/config-vitest Documentation
|
|
2
|
+
|
|
3
|
+
Reference documentation for shared Vitest configuration in the core-utils monorepo.
|
|
4
|
+
|
|
5
|
+
## Start Here
|
|
6
|
+
|
|
7
|
+
- [Usage Guide](./guides/usage-guide.md)
|
|
8
|
+
|
|
9
|
+
## API Reference
|
|
10
|
+
|
|
11
|
+
- [API Reference](./api/api-reference.md) — Factory functions, options, and preset configs
|
|
12
|
+
- [Base Configuration](./api/base-config.md) — Detailed base config reference
|
|
13
|
+
|
|
14
|
+
## Quick Example
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// vitest.config.mts
|
|
18
|
+
import { createVitestConfig } from "@reasonabletech/config-vitest";
|
|
19
|
+
|
|
20
|
+
export default createVitestConfig(import.meta.dirname);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Monorepo Context
|
|
24
|
+
|
|
25
|
+
- [Package README](../README.md)
|
|
26
|
+
- [Architecture](../../../docs/architecture.md) — How packages relate
|
|
27
|
+
- [Tooling](../../../docs/tooling.md) — Turbo, Changesets, Vitest details
|
|
28
|
+
- [Contributing](../../../CONTRIBUTING.md)
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
# config-vitest API Reference
|
|
2
|
+
|
|
3
|
+
## Package Exports
|
|
4
|
+
|
|
5
|
+
### Main Entry Point (`@reasonabletech/config-vitest`)
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import {
|
|
9
|
+
createVitestConfig,
|
|
10
|
+
createLongRunningTestConfig,
|
|
11
|
+
createReactConfig,
|
|
12
|
+
createReactConfigWithPlugins,
|
|
13
|
+
baseConfig,
|
|
14
|
+
} from "@reasonabletech/config-vitest";
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
VitestConfig,
|
|
18
|
+
DeepReadonly,
|
|
19
|
+
} from "@reasonabletech/config-vitest";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Node Entry Point (`@reasonabletech/config-vitest/node`)
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createNodeConfig, nodeConfig } from "@reasonabletech/config-vitest/node";
|
|
26
|
+
|
|
27
|
+
import type { VitestConfig } from "@reasonabletech/config-vitest/node";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### React Entry Point (`@reasonabletech/config-vitest/react`)
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import {
|
|
34
|
+
createReactConfig,
|
|
35
|
+
createReactConfigWithPlugins,
|
|
36
|
+
reactConfig,
|
|
37
|
+
} from "@reasonabletech/config-vitest/react";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Factory Functions
|
|
43
|
+
|
|
44
|
+
### `createVitestConfig()`
|
|
45
|
+
|
|
46
|
+
Creates a base Vitest configuration with sensible defaults, auto-detection of setup files, and workspace alias support.
|
|
47
|
+
|
|
48
|
+
**Signatures:**
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
// With project directory for automatic aliasing
|
|
52
|
+
function createVitestConfig(
|
|
53
|
+
projectDir: string,
|
|
54
|
+
customConfig?: VitestConfig
|
|
55
|
+
): ReturnType<typeof defineConfig>;
|
|
56
|
+
|
|
57
|
+
// With config object only
|
|
58
|
+
function createVitestConfig(
|
|
59
|
+
config?: VitestConfig
|
|
60
|
+
): ReturnType<typeof defineConfig>;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Parameters:**
|
|
64
|
+
|
|
65
|
+
| Parameter | Type | Description |
|
|
66
|
+
| -------------- | --------------- | ------------------------------------------------------------------------------------------ |
|
|
67
|
+
| `projectDir` | `string` | Absolute path to project root (use `import.meta.dirname`). Enables self-package aliasing. |
|
|
68
|
+
| `customConfig` | `VitestConfig` | Additional configuration to merge |
|
|
69
|
+
|
|
70
|
+
**Returns:** Vite/Vitest config object
|
|
71
|
+
|
|
72
|
+
**Auto-Detection Features:**
|
|
73
|
+
|
|
74
|
+
- **Setup files:** Detects `vitest.setup.ts` or `tests/setup.ts`
|
|
75
|
+
- **Include patterns:** Defaults to `tests/**/*.test.{ts,tsx,js,jsx}`
|
|
76
|
+
- **Self-package alias:** Maps package name to `src/` directory
|
|
77
|
+
- **@ alias:** Maps `@` to `src/` directory
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### `createLongRunningTestConfig()`
|
|
82
|
+
|
|
83
|
+
Creates a configuration with extended timeouts for integration tests or slow test suites.
|
|
84
|
+
|
|
85
|
+
**Signatures:**
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
function createLongRunningTestConfig(
|
|
89
|
+
projectDir: string,
|
|
90
|
+
customConfig?: VitestConfig
|
|
91
|
+
): ReturnType<typeof defineConfig>;
|
|
92
|
+
|
|
93
|
+
function createLongRunningTestConfig(
|
|
94
|
+
config?: VitestConfig
|
|
95
|
+
): ReturnType<typeof defineConfig>;
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Extended Timeouts:**
|
|
99
|
+
|
|
100
|
+
| Setting | Default | Long-Running |
|
|
101
|
+
| ------------- | ------- | ------------ |
|
|
102
|
+
| `testTimeout` | 10,000ms | 30,000ms |
|
|
103
|
+
| `hookTimeout` | 10,000ms | 30,000ms |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### `createNodeConfig()`
|
|
108
|
+
|
|
109
|
+
Creates a Vitest configuration optimized for Node.js environments.
|
|
110
|
+
|
|
111
|
+
**Signatures:**
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
function createNodeConfig(
|
|
115
|
+
projectDir: string,
|
|
116
|
+
customConfig?: VitestConfig
|
|
117
|
+
): ReturnType<typeof defineConfig>;
|
|
118
|
+
|
|
119
|
+
function createNodeConfig(
|
|
120
|
+
config?: VitestConfig
|
|
121
|
+
): ReturnType<typeof defineConfig>;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Node-Specific Settings:**
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
{
|
|
128
|
+
test: {
|
|
129
|
+
environment: "node",
|
|
130
|
+
include: ["tests/**/*.test.ts"],
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### `createReactConfig()`
|
|
138
|
+
|
|
139
|
+
Creates a Vitest configuration for React component testing with jsdom and the React plugin.
|
|
140
|
+
|
|
141
|
+
**Signatures:**
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
function createReactConfig(
|
|
145
|
+
projectDir: string,
|
|
146
|
+
customConfig?: VitestConfig
|
|
147
|
+
): ReturnType<typeof defineConfig>;
|
|
148
|
+
|
|
149
|
+
function createReactConfig(
|
|
150
|
+
config?: VitestConfig
|
|
151
|
+
): ReturnType<typeof defineConfig>;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Includes:**
|
|
155
|
+
|
|
156
|
+
- `@vitejs/plugin-react` for JSX/TSX support
|
|
157
|
+
- jsdom environment
|
|
158
|
+
- React deduplication for singleton enforcement
|
|
159
|
+
- Extended coverage exclusions for React patterns
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
### `createReactConfigWithPlugins()`
|
|
164
|
+
|
|
165
|
+
Creates a React Vitest configuration with custom Vite plugins.
|
|
166
|
+
|
|
167
|
+
**Signature:**
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
function createReactConfigWithPlugins(
|
|
171
|
+
plugins: readonly PluginOption[],
|
|
172
|
+
projectDir: string,
|
|
173
|
+
customConfig?: VitestConfig
|
|
174
|
+
): ReturnType<typeof defineConfig>;
|
|
175
|
+
|
|
176
|
+
function createReactConfigWithPlugins(
|
|
177
|
+
plugins: readonly PluginOption[],
|
|
178
|
+
config?: VitestConfig
|
|
179
|
+
): ReturnType<typeof defineConfig>;
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Parameters:**
|
|
183
|
+
|
|
184
|
+
| Parameter | Type | Description |
|
|
185
|
+
| -------------- | ----------------------- | ------------------------------ |
|
|
186
|
+
| `plugins` | `readonly PluginOption[]` | Array of Vite plugins to include |
|
|
187
|
+
| `projectDir` | `string` | Absolute path to project root |
|
|
188
|
+
| `customConfig` | `VitestConfig` | Additional configuration |
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Configuration Types
|
|
193
|
+
|
|
194
|
+
### `VitestConfig`
|
|
195
|
+
|
|
196
|
+
Immutable configuration object for Vitest.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
type VitestConfig = DeepReadonly<{
|
|
200
|
+
test?: InlineConfig;
|
|
201
|
+
resolve?: {
|
|
202
|
+
conditions?: string[];
|
|
203
|
+
alias?: Record<string, string>;
|
|
204
|
+
[key: string]: unknown;
|
|
205
|
+
};
|
|
206
|
+
[key: string]: unknown;
|
|
207
|
+
}>;
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### `DeepReadonly<T>`
|
|
211
|
+
|
|
212
|
+
Utility type that recursively makes all properties readonly.
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
type DeepReadonly<T> = {
|
|
216
|
+
readonly [P in keyof T]: T[P] extends ReadonlyArray<infer U>
|
|
217
|
+
? ReadonlyArray<DeepReadonly<U>>
|
|
218
|
+
: T[P] extends Array<infer U>
|
|
219
|
+
? ReadonlyArray<DeepReadonly<U>>
|
|
220
|
+
: T[P] extends object
|
|
221
|
+
? DeepReadonly<T[P]>
|
|
222
|
+
: T[P];
|
|
223
|
+
};
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Preset Configurations
|
|
229
|
+
|
|
230
|
+
### `baseConfig`
|
|
231
|
+
|
|
232
|
+
Base configuration applied to all environments.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
const baseConfig = {
|
|
236
|
+
test: {
|
|
237
|
+
testTimeout: 10000,
|
|
238
|
+
hookTimeout: 10000,
|
|
239
|
+
coverage: {
|
|
240
|
+
provider: "v8",
|
|
241
|
+
reporter: ["text", "html", "lcov", "json"],
|
|
242
|
+
reportsDirectory: "./generated/test-coverage",
|
|
243
|
+
exclude: [
|
|
244
|
+
"**/node_modules/**",
|
|
245
|
+
"**/dist/**",
|
|
246
|
+
"**/tests/**",
|
|
247
|
+
"**/*.d.ts",
|
|
248
|
+
"**/*.config.{js,ts,mjs,mts}",
|
|
249
|
+
"**/coverage/**",
|
|
250
|
+
"**/examples/**",
|
|
251
|
+
"**/src/index.ts",
|
|
252
|
+
"**/src/*/index.ts",
|
|
253
|
+
"**/src/types/**",
|
|
254
|
+
"tsup.config.ts",
|
|
255
|
+
"vitest.config.mts",
|
|
256
|
+
"tailwind.config.mjs",
|
|
257
|
+
"**/vitest.setup.ts",
|
|
258
|
+
],
|
|
259
|
+
thresholds: {
|
|
260
|
+
lines: 100,
|
|
261
|
+
functions: 100,
|
|
262
|
+
branches: 100,
|
|
263
|
+
statements: 100,
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Note:** Coverage thresholds default to 100%. Set `VITEST_COVERAGE_THRESHOLDS_DISABLED=true` to disable.
|
|
271
|
+
|
|
272
|
+
### `nodeConfig`
|
|
273
|
+
|
|
274
|
+
Node.js-specific defaults (from `@reasonabletech/config-vitest/node`).
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
const nodeConfig = {
|
|
278
|
+
test: {
|
|
279
|
+
environment: "node",
|
|
280
|
+
include: ["tests/**/*.test.ts"],
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### `reactConfig`
|
|
286
|
+
|
|
287
|
+
React-specific defaults (from `@reasonabletech/config-vitest/react`).
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
const reactConfig = {
|
|
291
|
+
test: {
|
|
292
|
+
environment: "jsdom",
|
|
293
|
+
exclude: ["**/node_modules/**", "**/dist/**"],
|
|
294
|
+
silent: false,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Default Options Reference
|
|
302
|
+
|
|
303
|
+
### Base Configuration Defaults
|
|
304
|
+
|
|
305
|
+
| Option | Default Value |
|
|
306
|
+
| --------------------------- | -------------------------------------- |
|
|
307
|
+
| `test.testTimeout` | `10000` (10 seconds) |
|
|
308
|
+
| `test.hookTimeout` | `10000` (10 seconds) |
|
|
309
|
+
| `test.coverage.provider` | `"v8"` |
|
|
310
|
+
| `test.coverage.thresholds` | `100%` for all metrics |
|
|
311
|
+
|
|
312
|
+
### Resolve Conditions
|
|
313
|
+
|
|
314
|
+
The configuration adds `"source"` to resolve conditions, allowing Vitest to resolve workspace dependencies directly to TypeScript source without requiring a prior build.
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
resolve: {
|
|
318
|
+
conditions: ["source", ...defaultClientConditions],
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### SSR Configuration
|
|
323
|
+
|
|
324
|
+
For proper SSR test resolution:
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
ssr: {
|
|
328
|
+
resolve: {
|
|
329
|
+
conditions: ["source", ...defaultServerConditions],
|
|
330
|
+
externalConditions: ["source"],
|
|
331
|
+
},
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## Usage Examples
|
|
338
|
+
|
|
339
|
+
### Basic Node.js Package
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
// vitest.config.mts
|
|
343
|
+
import { createVitestConfig } from "@reasonabletech/config-vitest";
|
|
344
|
+
|
|
345
|
+
export default createVitestConfig(import.meta.dirname);
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Node.js with Custom Settings
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
// vitest.config.mts
|
|
352
|
+
import { createNodeConfig } from "@reasonabletech/config-vitest/node";
|
|
353
|
+
|
|
354
|
+
export default createNodeConfig(import.meta.dirname, {
|
|
355
|
+
test: {
|
|
356
|
+
testTimeout: 30000,
|
|
357
|
+
coverage: {
|
|
358
|
+
thresholds: {
|
|
359
|
+
lines: 80,
|
|
360
|
+
functions: 80,
|
|
361
|
+
branches: 80,
|
|
362
|
+
statements: 80,
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### React Component Library
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
// vitest.config.mts
|
|
373
|
+
import { createReactConfig } from "@reasonabletech/config-vitest";
|
|
374
|
+
|
|
375
|
+
export default createReactConfig(import.meta.dirname);
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### React with Custom Plugins
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
// vitest.config.mts
|
|
382
|
+
import { createReactConfigWithPlugins } from "@reasonabletech/config-vitest";
|
|
383
|
+
import react from "@vitejs/plugin-react";
|
|
384
|
+
import svgr from "vite-plugin-svgr";
|
|
385
|
+
|
|
386
|
+
export default createReactConfigWithPlugins(
|
|
387
|
+
[react(), svgr()],
|
|
388
|
+
import.meta.dirname,
|
|
389
|
+
);
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Long-Running Integration Tests
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
// vitest.config.mts
|
|
396
|
+
import { createLongRunningTestConfig } from "@reasonabletech/config-vitest";
|
|
397
|
+
|
|
398
|
+
export default createLongRunningTestConfig(import.meta.dirname, {
|
|
399
|
+
test: {
|
|
400
|
+
include: ["tests/integration/**/*.test.ts"],
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Custom Coverage Thresholds
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
// vitest.config.mts
|
|
409
|
+
import { createVitestConfig } from "@reasonabletech/config-vitest";
|
|
410
|
+
|
|
411
|
+
export default createVitestConfig(import.meta.dirname, {
|
|
412
|
+
test: {
|
|
413
|
+
coverage: {
|
|
414
|
+
thresholds: {
|
|
415
|
+
lines: 80,
|
|
416
|
+
functions: 80,
|
|
417
|
+
branches: 80,
|
|
418
|
+
statements: 80,
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### Custom Aliases
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
// vitest.config.mts
|
|
429
|
+
import { createVitestConfig } from "@reasonabletech/config-vitest";
|
|
430
|
+
|
|
431
|
+
export default createVitestConfig(import.meta.dirname, {
|
|
432
|
+
resolve: {
|
|
433
|
+
alias: {
|
|
434
|
+
"@components": `${import.meta.dirname}/src/components`,
|
|
435
|
+
"@utils": `${import.meta.dirname}/src/utils`,
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Without Project Directory
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
// vitest.config.mts
|
|
445
|
+
import { createVitestConfig } from "@reasonabletech/config-vitest";
|
|
446
|
+
|
|
447
|
+
export default createVitestConfig({
|
|
448
|
+
test: {
|
|
449
|
+
include: ["src/**/*.test.ts"],
|
|
450
|
+
setupFiles: ["./test-setup.ts"],
|
|
451
|
+
},
|
|
452
|
+
});
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
## Environment Variables
|
|
458
|
+
|
|
459
|
+
| Variable | Effect |
|
|
460
|
+
| ------------------------------------ | ----------------------------------------- |
|
|
461
|
+
| `VITEST_COVERAGE_THRESHOLDS_DISABLED` | When `"true"`, sets all thresholds to 0% |
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## Related Documentation
|
|
466
|
+
|
|
467
|
+
- [Base Configuration](./base-config.md) — Detailed base config reference
|
|
468
|
+
- [Usage Guide](../guides/usage-guide.md) — Setup and patterns
|
|
469
|
+
- [Package README](../../README.md) — Quick start
|