skillshop 2.0.0 → 2.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 +217 -104
- package/agents-content/000_communication-writing.block.md +11 -0
- package/agents-content/001_external-actions.block.md +9 -0
- package/agents-content/AGENTS.md +11 -0
- package/package.json +6 -3
- package/skills-content/architecture-scanner/SKILL.md +274 -0
- package/skills-content/architecture-scanner/files.json +10 -0
- package/skills-content/architecture-scanner/scan.sh +823 -0
- package/skills-content/change-review/SKILL.md +76 -0
- package/skills-content/change-review/agents/openai.yaml +4 -0
- package/skills-content/changelog/SKILL.md +99 -0
- package/skills-content/changeset/changeset.md +80 -0
- package/skills-content/code-buddy/SKILL.md +136 -0
- package/skills-content/design-system-catalog/SKILL.md +106 -0
- package/skills-content/design-system-catalog/extract-components.mjs +441 -0
- package/skills-content/design-system-catalog/generate-catalog.sh +255 -0
- package/skills-content/flare/SKILL.md +96 -0
- package/skills-content/grilling/SKILL.md +31 -0
- package/skills-content/install-sigmap/SKILL.md +97 -0
- package/skills-content/one-shot/SKILL.md +51 -0
- package/skills-content/release/SKILL.md +128 -0
- package/skills-content/shadow-clone/SKILL.md +228 -0
- package/skills-content/shadow-clone/extract-signatures.mjs +202 -0
- package/skills-content/shadow-clone/scan-repo.mjs +343 -0
- package/skills-content/ship/SKILL.md +95 -0
- package/skills-content/shots/SKILL.md +89 -0
- package/skills-content/shots/agents/openai.yaml +4 -0
- package/skills-content/skillshop/SKILL.md +104 -0
- package/skills-content/skillz/SKILL.md +15 -0
- package/skills-content/transcript-clean/SKILL.md +55 -0
- package/skills-content/transcript-edit/SKILL.md +80 -0
- package/skills-content/vitest/GENERATION.md +5 -0
- package/skills-content/vitest/SKILL.md +52 -0
- package/skills-content/vitest/references/advanced-environments.md +264 -0
- package/skills-content/vitest/references/advanced-projects.md +300 -0
- package/skills-content/vitest/references/advanced-type-testing.md +237 -0
- package/skills-content/vitest/references/advanced-vi.md +249 -0
- package/skills-content/vitest/references/core-cli.md +166 -0
- package/skills-content/vitest/references/core-config.md +174 -0
- package/skills-content/vitest/references/core-describe.md +193 -0
- package/skills-content/vitest/references/core-expect.md +219 -0
- package/skills-content/vitest/references/core-hooks.md +244 -0
- package/skills-content/vitest/references/core-test-api.md +233 -0
- package/skills-content/vitest/references/features-concurrency.md +250 -0
- package/skills-content/vitest/references/features-context.md +238 -0
- package/skills-content/vitest/references/features-coverage.md +207 -0
- package/skills-content/vitest/references/features-filtering.md +211 -0
- package/skills-content/vitest/references/features-mocking.md +265 -0
- package/skills-content/vitest/references/features-snapshots.md +207 -0
- package/skills-content/workleaf/SKILL.md +77 -0
- package/skills-content/worklog/SKILL.md +145 -0
- package/skills-content/worklog/references/summary-format.md +114 -0
- package/skills-content/worktree/SKILL.md +71 -0
- package/src/agents-instructions.js +219 -0
- package/src/cli.js +87 -23
- package/src/import.js +12 -7
- package/src/index.js +1 -0
- package/src/legacy-agents-content.js +36 -0
- package/src/legacy-cli.js +1234 -0
- package/src/library.js +9 -0
- package/src/specifier.js +11 -0
- package/src/user-install.js +48 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vi-utilities
|
|
3
|
+
description: vi helper for mocking, timers, utilities
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Vi Utilities
|
|
7
|
+
|
|
8
|
+
The `vi` helper provides mocking and utility functions.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { vi } from 'vitest'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Mock Functions
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// Create mock
|
|
18
|
+
const fn = vi.fn()
|
|
19
|
+
const fnWithImpl = vi.fn((x) => x * 2)
|
|
20
|
+
|
|
21
|
+
// Check if mock
|
|
22
|
+
vi.isMockFunction(fn) // true
|
|
23
|
+
|
|
24
|
+
// Mock methods
|
|
25
|
+
fn.mockReturnValue(42)
|
|
26
|
+
fn.mockReturnValueOnce(1)
|
|
27
|
+
fn.mockResolvedValue(data)
|
|
28
|
+
fn.mockRejectedValue(error)
|
|
29
|
+
fn.mockImplementation(() => 'result')
|
|
30
|
+
fn.mockImplementationOnce(() => 'once')
|
|
31
|
+
|
|
32
|
+
// Clear/reset
|
|
33
|
+
fn.mockClear() // Clear call history
|
|
34
|
+
fn.mockReset() // Clear history + implementation
|
|
35
|
+
fn.mockRestore() // Restore original (for spies)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Spying
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const obj = { method: () => 'original' }
|
|
42
|
+
|
|
43
|
+
const spy = vi.spyOn(obj, 'method')
|
|
44
|
+
obj.method()
|
|
45
|
+
|
|
46
|
+
expect(spy).toHaveBeenCalled()
|
|
47
|
+
|
|
48
|
+
// Mock implementation
|
|
49
|
+
spy.mockReturnValue('mocked')
|
|
50
|
+
|
|
51
|
+
// Spy on getter/setter
|
|
52
|
+
vi.spyOn(obj, 'prop', 'get').mockReturnValue('value')
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Module Mocking
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// Hoisted to top of file
|
|
59
|
+
vi.mock('./module', () => ({
|
|
60
|
+
fn: vi.fn(),
|
|
61
|
+
}))
|
|
62
|
+
|
|
63
|
+
// Partial mock
|
|
64
|
+
vi.mock('./module', async (importOriginal) => ({
|
|
65
|
+
...(await importOriginal()),
|
|
66
|
+
specificFn: vi.fn(),
|
|
67
|
+
}))
|
|
68
|
+
|
|
69
|
+
// Spy mode - keep implementation
|
|
70
|
+
vi.mock('./module', { spy: true })
|
|
71
|
+
|
|
72
|
+
// Import actual module inside mock
|
|
73
|
+
const actual = await vi.importActual('./module')
|
|
74
|
+
|
|
75
|
+
// Import as mock
|
|
76
|
+
const mocked = await vi.importMock('./module')
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Dynamic Mocking
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
// Not hoisted - use with dynamic imports
|
|
83
|
+
vi.doMock('./config', () => ({ key: 'value' }))
|
|
84
|
+
const config = await import('./config')
|
|
85
|
+
|
|
86
|
+
// Unmock
|
|
87
|
+
vi.doUnmock('./config')
|
|
88
|
+
vi.unmock('./module') // Hoisted
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Reset Modules
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// Clear module cache
|
|
95
|
+
vi.resetModules()
|
|
96
|
+
|
|
97
|
+
// Wait for dynamic imports
|
|
98
|
+
await vi.dynamicImportSettled()
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Fake Timers
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
vi.useFakeTimers()
|
|
105
|
+
|
|
106
|
+
setTimeout(() => console.log('done'), 1000)
|
|
107
|
+
|
|
108
|
+
// Advance time
|
|
109
|
+
vi.advanceTimersByTime(1000)
|
|
110
|
+
vi.advanceTimersByTimeAsync(1000) // For async callbacks
|
|
111
|
+
vi.advanceTimersToNextTimer()
|
|
112
|
+
vi.advanceTimersToNextFrame() // requestAnimationFrame
|
|
113
|
+
|
|
114
|
+
// Run all timers
|
|
115
|
+
vi.runAllTimers()
|
|
116
|
+
vi.runAllTimersAsync()
|
|
117
|
+
vi.runOnlyPendingTimers()
|
|
118
|
+
|
|
119
|
+
// Clear timers
|
|
120
|
+
vi.clearAllTimers()
|
|
121
|
+
|
|
122
|
+
// Check state
|
|
123
|
+
vi.getTimerCount()
|
|
124
|
+
vi.isFakeTimers()
|
|
125
|
+
|
|
126
|
+
// Restore
|
|
127
|
+
vi.useRealTimers()
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Mock Date/Time
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
vi.setSystemTime(new Date('2024-01-01'))
|
|
134
|
+
expect(new Date().getFullYear()).toBe(2024)
|
|
135
|
+
|
|
136
|
+
vi.getMockedSystemTime() // Get mocked date
|
|
137
|
+
vi.getRealSystemTime() // Get real time (ms)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Global/Env Mocking
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
// Stub global
|
|
144
|
+
vi.stubGlobal('fetch', vi.fn())
|
|
145
|
+
vi.unstubAllGlobals()
|
|
146
|
+
|
|
147
|
+
// Stub environment
|
|
148
|
+
vi.stubEnv('API_KEY', 'test')
|
|
149
|
+
vi.stubEnv('NODE_ENV', 'test')
|
|
150
|
+
vi.unstubAllEnvs()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Hoisted Code
|
|
154
|
+
|
|
155
|
+
Run code before imports:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
const mock = vi.hoisted(() => vi.fn())
|
|
159
|
+
|
|
160
|
+
vi.mock('./module', () => ({
|
|
161
|
+
fn: mock, // Can reference hoisted variable
|
|
162
|
+
}))
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Waiting Utilities
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
// Wait for callback to succeed
|
|
169
|
+
await vi.waitFor(async () => {
|
|
170
|
+
const el = document.querySelector('.loaded')
|
|
171
|
+
expect(el).toBeTruthy()
|
|
172
|
+
}, { timeout: 5000, interval: 100 })
|
|
173
|
+
|
|
174
|
+
// Wait for truthy value
|
|
175
|
+
const element = await vi.waitUntil(
|
|
176
|
+
() => document.querySelector('.loaded'),
|
|
177
|
+
{ timeout: 5000 }
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Mock Object
|
|
182
|
+
|
|
183
|
+
Mock all methods of an object:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
const original = {
|
|
187
|
+
method: () => 'real',
|
|
188
|
+
nested: { fn: () => 'nested' },
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const mocked = vi.mockObject(original)
|
|
192
|
+
mocked.method() // undefined (mocked)
|
|
193
|
+
mocked.method.mockReturnValue('mocked')
|
|
194
|
+
|
|
195
|
+
// Spy mode
|
|
196
|
+
const spied = vi.mockObject(original, { spy: true })
|
|
197
|
+
spied.method() // 'real'
|
|
198
|
+
expect(spied.method).toHaveBeenCalled()
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Test Configuration
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
vi.setConfig({
|
|
205
|
+
testTimeout: 10_000,
|
|
206
|
+
hookTimeout: 10_000,
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
vi.resetConfig()
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Global Mock Management
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
vi.clearAllMocks() // Clear all mock call history
|
|
216
|
+
vi.resetAllMocks() // Reset + clear implementation
|
|
217
|
+
vi.restoreAllMocks() // Restore originals (spies)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## vi.mocked Type Helper
|
|
221
|
+
|
|
222
|
+
TypeScript helper for mocked values:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
import { myFn } from './module'
|
|
226
|
+
vi.mock('./module')
|
|
227
|
+
|
|
228
|
+
// Type as mock
|
|
229
|
+
vi.mocked(myFn).mockReturnValue('typed')
|
|
230
|
+
|
|
231
|
+
// Deep mocking
|
|
232
|
+
vi.mocked(myModule, { deep: true })
|
|
233
|
+
|
|
234
|
+
// Partial mock typing
|
|
235
|
+
vi.mocked(fn, { partial: true }).mockResolvedValue({ ok: true })
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Key Points
|
|
239
|
+
|
|
240
|
+
- `vi.mock` is hoisted - use `vi.doMock` for dynamic mocking
|
|
241
|
+
- `vi.hoisted` lets you reference variables in mock factories
|
|
242
|
+
- Use `vi.spyOn` to spy on existing methods
|
|
243
|
+
- Fake timers require explicit setup and teardown
|
|
244
|
+
- `vi.waitFor` retries until assertion passes
|
|
245
|
+
|
|
246
|
+
<!--
|
|
247
|
+
Source references:
|
|
248
|
+
- https://vitest.dev/api/vi.html
|
|
249
|
+
-->
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vitest-cli
|
|
3
|
+
description: Command line interface commands and options
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Command Line Interface
|
|
7
|
+
|
|
8
|
+
## Commands
|
|
9
|
+
|
|
10
|
+
### `vitest`
|
|
11
|
+
|
|
12
|
+
Start Vitest in watch mode (dev) or run mode (CI):
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
vitest # Watch mode in dev, run mode in CI
|
|
16
|
+
vitest foobar # Run tests containing "foobar" in path
|
|
17
|
+
vitest basic/foo.test.ts:10 # Run specific test by file and line number
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### `vitest run`
|
|
21
|
+
|
|
22
|
+
Run tests once without watch mode:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
vitest run
|
|
26
|
+
vitest run --coverage
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### `vitest watch`
|
|
30
|
+
|
|
31
|
+
Explicitly start watch mode:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
vitest watch
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### `vitest related`
|
|
38
|
+
|
|
39
|
+
Run tests that import specific files (useful with lint-staged):
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
vitest related src/index.ts src/utils.ts --run
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### `vitest bench`
|
|
46
|
+
|
|
47
|
+
Run only benchmark tests:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
vitest bench
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### `vitest list`
|
|
54
|
+
|
|
55
|
+
List all matching tests without running them:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
vitest list # List test names
|
|
59
|
+
vitest list --json # Output as JSON
|
|
60
|
+
vitest list --filesOnly # List only test files
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `vitest init`
|
|
64
|
+
|
|
65
|
+
Initialize project setup:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
vitest init browser # Set up browser testing
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Common Options
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Configuration
|
|
75
|
+
--config <path> # Path to config file
|
|
76
|
+
--project <name> # Run specific project
|
|
77
|
+
|
|
78
|
+
# Filtering
|
|
79
|
+
--testNamePattern, -t # Run tests matching pattern
|
|
80
|
+
--changed # Run tests for changed files
|
|
81
|
+
--changed HEAD~1 # Tests for last commit changes
|
|
82
|
+
|
|
83
|
+
# Reporters
|
|
84
|
+
--reporter <name> # default, verbose, dot, json, html
|
|
85
|
+
--reporter=html --outputFile=report.html
|
|
86
|
+
|
|
87
|
+
# Coverage
|
|
88
|
+
--coverage # Enable coverage
|
|
89
|
+
--coverage.provider v8 # Use v8 provider
|
|
90
|
+
--coverage.reporter text,html
|
|
91
|
+
|
|
92
|
+
# Execution
|
|
93
|
+
--shard <index>/<count> # Split tests across machines
|
|
94
|
+
--bail <n> # Stop after n failures
|
|
95
|
+
--retry <n> # Retry failed tests n times
|
|
96
|
+
--sequence.shuffle # Randomize test order
|
|
97
|
+
|
|
98
|
+
# Watch mode
|
|
99
|
+
--no-watch # Disable watch mode
|
|
100
|
+
--standalone # Start without running tests
|
|
101
|
+
|
|
102
|
+
# Environment
|
|
103
|
+
--environment <env> # jsdom, happy-dom, node
|
|
104
|
+
--globals # Enable global APIs
|
|
105
|
+
|
|
106
|
+
# Debugging
|
|
107
|
+
--inspect # Enable Node inspector
|
|
108
|
+
--inspect-brk # Break on start
|
|
109
|
+
|
|
110
|
+
# Output
|
|
111
|
+
--silent # Suppress console output
|
|
112
|
+
--no-color # Disable colors
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Package.json Scripts
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"scripts": {
|
|
120
|
+
"test": "vitest",
|
|
121
|
+
"test:run": "vitest run",
|
|
122
|
+
"test:ui": "vitest --ui",
|
|
123
|
+
"coverage": "vitest run --coverage"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Sharding for CI
|
|
129
|
+
|
|
130
|
+
Split tests across multiple machines:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Machine 1
|
|
134
|
+
vitest run --shard=1/3 --reporter=blob
|
|
135
|
+
|
|
136
|
+
# Machine 2
|
|
137
|
+
vitest run --shard=2/3 --reporter=blob
|
|
138
|
+
|
|
139
|
+
# Machine 3
|
|
140
|
+
vitest run --shard=3/3 --reporter=blob
|
|
141
|
+
|
|
142
|
+
# Merge reports
|
|
143
|
+
vitest --merge-reports --reporter=junit
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Watch Mode Keyboard Shortcuts
|
|
147
|
+
|
|
148
|
+
In watch mode, press:
|
|
149
|
+
- `a` - Run all tests
|
|
150
|
+
- `f` - Run only failed tests
|
|
151
|
+
- `u` - Update snapshots
|
|
152
|
+
- `p` - Filter by filename pattern
|
|
153
|
+
- `t` - Filter by test name pattern
|
|
154
|
+
- `q` - Quit
|
|
155
|
+
|
|
156
|
+
## Key Points
|
|
157
|
+
|
|
158
|
+
- Watch mode is default in dev, run mode in CI (when `process.env.CI` is set)
|
|
159
|
+
- Use `--run` flag to ensure single run (important for lint-staged)
|
|
160
|
+
- Both camelCase (`--testTimeout`) and kebab-case (`--test-timeout`) work
|
|
161
|
+
- Boolean options can be negated with `--no-` prefix
|
|
162
|
+
|
|
163
|
+
<!--
|
|
164
|
+
Source references:
|
|
165
|
+
- https://vitest.dev/guide/cli.html
|
|
166
|
+
-->
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vitest-configuration
|
|
3
|
+
description: Configure Vitest with vite.config.ts or vitest.config.ts
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Configuration
|
|
7
|
+
|
|
8
|
+
Vitest reads configuration from `vitest.config.ts` or `vite.config.ts`. It shares the same config format as Vite.
|
|
9
|
+
|
|
10
|
+
## Basic Setup
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
// vitest.config.ts
|
|
14
|
+
import { defineConfig } from 'vitest/config'
|
|
15
|
+
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
test: {
|
|
18
|
+
// test options
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Using with Existing Vite Config
|
|
24
|
+
|
|
25
|
+
Add Vitest types reference and use the `test` property:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// vite.config.ts
|
|
29
|
+
/// <reference types="vitest/config" />
|
|
30
|
+
import { defineConfig } from 'vite'
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
test: {
|
|
34
|
+
globals: true,
|
|
35
|
+
environment: 'jsdom',
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Merging Configs
|
|
41
|
+
|
|
42
|
+
If you have separate config files, use `mergeConfig`:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// vitest.config.ts
|
|
46
|
+
import { defineConfig, mergeConfig } from 'vitest/config'
|
|
47
|
+
import viteConfig from './vite.config'
|
|
48
|
+
|
|
49
|
+
export default mergeConfig(viteConfig, defineConfig({
|
|
50
|
+
test: {
|
|
51
|
+
environment: 'jsdom',
|
|
52
|
+
},
|
|
53
|
+
}))
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Common Options
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
defineConfig({
|
|
60
|
+
test: {
|
|
61
|
+
// Enable global APIs (describe, it, expect) without imports
|
|
62
|
+
globals: true,
|
|
63
|
+
|
|
64
|
+
// Test environment: 'node', 'jsdom', 'happy-dom'
|
|
65
|
+
environment: 'node',
|
|
66
|
+
|
|
67
|
+
// Setup files to run before each test file
|
|
68
|
+
setupFiles: ['./tests/setup.ts'],
|
|
69
|
+
|
|
70
|
+
// Include patterns for test files
|
|
71
|
+
include: ['**/*.{test,spec}.{js,ts,jsx,tsx}'],
|
|
72
|
+
|
|
73
|
+
// Exclude patterns
|
|
74
|
+
exclude: ['**/node_modules/**', '**/dist/**'],
|
|
75
|
+
|
|
76
|
+
// Test timeout in ms
|
|
77
|
+
testTimeout: 5000,
|
|
78
|
+
|
|
79
|
+
// Hook timeout in ms
|
|
80
|
+
hookTimeout: 10000,
|
|
81
|
+
|
|
82
|
+
// Enable watch mode by default
|
|
83
|
+
watch: true,
|
|
84
|
+
|
|
85
|
+
// Coverage configuration
|
|
86
|
+
coverage: {
|
|
87
|
+
provider: 'v8', // or 'istanbul'
|
|
88
|
+
reporter: ['text', 'html'],
|
|
89
|
+
include: ['src/**/*.ts'],
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
// Run tests in isolation (each file in separate process)
|
|
93
|
+
isolate: true,
|
|
94
|
+
|
|
95
|
+
// Pool for running tests: 'threads', 'forks', 'vmThreads'
|
|
96
|
+
pool: 'threads',
|
|
97
|
+
|
|
98
|
+
// Number of threads/processes
|
|
99
|
+
poolOptions: {
|
|
100
|
+
threads: {
|
|
101
|
+
maxThreads: 4,
|
|
102
|
+
minThreads: 1,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
// Automatically clear mocks between tests
|
|
107
|
+
clearMocks: true,
|
|
108
|
+
|
|
109
|
+
// Restore mocks between tests
|
|
110
|
+
restoreMocks: true,
|
|
111
|
+
|
|
112
|
+
// Retry failed tests
|
|
113
|
+
retry: 0,
|
|
114
|
+
|
|
115
|
+
// Stop after first failure
|
|
116
|
+
bail: 0,
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Conditional Configuration
|
|
122
|
+
|
|
123
|
+
Use `mode` or `process.env.VITEST` for test-specific config:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
export default defineConfig(({ mode }) => ({
|
|
127
|
+
plugins: mode === 'test' ? [] : [myPlugin()],
|
|
128
|
+
test: {
|
|
129
|
+
// test options
|
|
130
|
+
},
|
|
131
|
+
}))
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Projects (Monorepos)
|
|
135
|
+
|
|
136
|
+
Run different configurations in the same Vitest process:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
defineConfig({
|
|
140
|
+
test: {
|
|
141
|
+
projects: [
|
|
142
|
+
'packages/*',
|
|
143
|
+
{
|
|
144
|
+
test: {
|
|
145
|
+
name: 'unit',
|
|
146
|
+
include: ['tests/unit/**/*.test.ts'],
|
|
147
|
+
environment: 'node',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
test: {
|
|
152
|
+
name: 'integration',
|
|
153
|
+
include: ['tests/integration/**/*.test.ts'],
|
|
154
|
+
environment: 'jsdom',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Key Points
|
|
163
|
+
|
|
164
|
+
- Vitest uses Vite's transformation pipeline - same `resolve.alias`, plugins work
|
|
165
|
+
- `vitest.config.ts` takes priority over `vite.config.ts`
|
|
166
|
+
- Use `--config` flag to specify a custom config path
|
|
167
|
+
- `process.env.VITEST` is set to `true` when running tests
|
|
168
|
+
- Test config uses `test` property, rest is Vite config
|
|
169
|
+
|
|
170
|
+
<!--
|
|
171
|
+
Source references:
|
|
172
|
+
- https://vitest.dev/guide/#configuring-vitest
|
|
173
|
+
- https://vitest.dev/config/
|
|
174
|
+
-->
|