Skip to content

Commit 6c452f8

Browse files
authored
Merge branch 'main' into pretty-format-shadow-root
2 parents 30b29fd + 25fd32b commit 6c452f8

File tree

172 files changed

+3218
-2416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+3218
-2416
lines changed

.github/copilot-instructions.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# copilot-instructions.md
2+
3+
This file provides guidance to Copilot Agent when working with code in this repository.
4+
5+
## Codebase Overview
6+
7+
Vitest is a next-generation testing framework powered by Vite. This is a monorepo using pnpm workspaces.
8+
9+
## Essential references
10+
11+
- Agent-specific guide: See [AGENTS.md](../AGENTS.md)

AGENTS.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Vitest AI Agent Guide
2+
3+
This document provides comprehensive information for AI agents working on the Vitest codebase.
4+
5+
## Project Overview
6+
7+
Vitest is a next-generation testing framework powered by Vite. This is a monorepo using pnpm workspaces with the following key characteristics:
8+
9+
- **Language**: TypeScript/JavaScript (ESM-first)
10+
- **Package Manager**: pnpm (required)
11+
- **Node Version**: ^18.0.0 || >=20.0.0
12+
- **Build System**: Vite + Rollup
13+
- **Monorepo Structure**: 15+ packages in `packages/` directory
14+
15+
## Setup and Development
16+
17+
### Initial Setup
18+
1. Run `pnpm install` to install dependencies
19+
2. Run `pnpm build` to build all packages
20+
3. Install Playwright browsers when working with browser features: `npx playwright install --with-deps`
21+
22+
### Key Scripts
23+
- `pnpm build` - Build all packages
24+
- `pnpm dev` - Watch mode for development
25+
- `pnpm lint` - Run ESLint
26+
- `pnpm lint:fix` - Fix linting issues automatically
27+
- `pnpm typecheck` - Run TypeScript type checking
28+
29+
## Testing
30+
31+
### Running Tests
32+
- **All tests**: `CI=true pnpm test:ci`
33+
- **Examples**: `CI=true pnpm test:examples`
34+
- **Specific test suite**: `CI=true cd test/<test-folder> && pnpm test <test-file>`
35+
- **Core directory test**: `CI=true pnpm test <test-file>` (for `test/core`)
36+
- **Browser tests**: `CI=true pnpm test:browser:playwright` or `CI=true pnpm test:browser:webdriverio`
37+
38+
### Testing Utilities
39+
- **`runInlineTests`** from `test/test-utils/index.ts` - You must use this for complex file system setups (>1 file)
40+
- **`runVitest`** from `test/test-utils/index.ts` - You can use this to run Vitest programmatically
41+
- **No mocking policy** - You must never mock anything in tests
42+
43+
## Project Structure
44+
45+
### Core Packages (`packages/`)
46+
- `vitest` - Main testing framework
47+
- `vite-node` - Vite SSR runtime
48+
- `browser` - Browser testing support
49+
- `ui` - Web UI for test results
50+
- `runner` - Test runner core
51+
- `expect` - Assertion library
52+
- `spy` - Mocking and spying utilities
53+
- `snapshot` - Snapshot testing
54+
- `coverage-v8` / `coverage-istanbul` - Code coverage
55+
- `utils` - Shared utilities
56+
- `mocker` - Module mocking
57+
58+
### Test Organization (`test/`)
59+
- `test/core` - Core functionality tests
60+
- `test/browser` - Browser-specific tests
61+
- Various test suites organized by feature
62+
63+
### Important Directories
64+
- `docs/` - Documentation (Vite-powered)
65+
- `examples/` - Example projects and integrations
66+
- `scripts/` - Build and development scripts
67+
- `.github/` - GitHub Actions workflows
68+
- `patches/` - Package patches via pnpm
69+
70+
## Code Style and Conventions
71+
72+
### Formatting and Linting
73+
- **Always run** `pnpm lint:fix` after making changes
74+
- Fix non-auto-fixable errors manually
75+
76+
### TypeScript
77+
- Strict TypeScript configuration
78+
- Use `pnpm typecheck` to verify types
79+
- Configuration files: `tsconfig.base.json`, `tsconfig.build.json`, `tsconfig.check.json`
80+
81+
### Code Quality
82+
- ESM-first approach
83+
- Follow existing patterns in the codebase
84+
- Use utilities from `@vitest/utils/*` when available. Never import from `@vitest/utils` main entry point directly.
85+
86+
## Common Workflows
87+
88+
### Adding New Features
89+
1. Identify the appropriate package in `packages/`
90+
2. Follow existing code patterns
91+
3. Add tests using testing utilities
92+
4. Run `pnpm build && pnpm typecheck && pnpm lint:fix`
93+
5. Add tests with relevant test suites
94+
95+
### Debugging
96+
- Use VS Code: `⇧⌘B` (Shift+Cmd+B) or `Ctrl+Shift+B` for dev tasks
97+
- Check `scripts/` directory for specialized development tools
98+
99+
### Documentation
100+
- Main docs in `docs/` directory
101+
- Built with `pnpm docs:build`
102+
- Local dev server: `pnpm docs`
103+
104+
## Dependencies and Tools
105+
106+
### Key Dependencies
107+
- **Vite** - Build tool and dev server
108+
- **Rollup** - Bundler
109+
- **ESLint** - Linting
110+
- **TypeScript** - Type checking
111+
- **Playwright** - Browser testing
112+
- **Chai/Expect** - Assertions
113+
- **Tinypool** - Worker threading
114+
- **Tinybench** - Benchmarking
115+
116+
### Development Tools
117+
- **tsx** - TypeScript execution
118+
- **ni/nr** - Package manager abstraction
119+
- **bumpp** - Version bumping
120+
- **changelogithub** - Changelog generation
121+
122+
## Browser Testing
123+
- Two modes: Playwright and WebDriverIO
124+
- Separate test commands for each
125+
- Component testing supported (Vue, React, Svelte, Lit, Marko)
126+
127+
## Performance Considerations
128+
- This is a performance-critical testing framework
129+
- Pay attention to import costs and bundle size
130+
- Use lazy loading where appropriate
131+
- Consider worker thread implications
132+
133+
## Troubleshooting
134+
135+
### Common Issues
136+
- Ensure pnpm is used (not npm/yarn)
137+
- Build before running tests
138+
- Check Node.js version compatibility
139+
- Playwright browsers must be installed for browser tests
140+
141+
### Getting Help
142+
- Check existing issues and documentation
143+
- Review CONTRIBUTING.md for detailed guidelines
144+
- Follow patterns in existing code

CLAUDE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Codebase Overview
6+
7+
Vitest is a next-generation testing framework powered by Vite. This is a monorepo using pnpm workspaces.
8+
9+
## Essential references
10+
11+
- Agent-specific guide: See [AGENTS.md](AGENTS.md)

docs/advanced/reporters.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class MyReporter implements Reporter {
9393
6. `JUnitReporter`
9494
7. `TapFlatReporter`
9595
8. `HangingProcessReporter`
96+
9. `TreeReporter`
9697

9798
### Base Abstract reporters:
9899

docs/config/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ TypeError: createAsyncThunk is not a function
328328
TypeError: default is not a function
329329
```
330330

331-
By default, Vitest assumes you are using a bundler to bypass this and will not fail, but you can disable this behaviour manually, if you code is not processed.
331+
By default, Vitest assumes you are using a bundler to bypass this and will not fail, but you can disable this behaviour manually, if your code is not processed.
332332

333333
#### deps.moduleDirectories
334334

docs/guide/cli-generated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Hide logs for skipped tests
8989
- **CLI:** `--reporter <name>`
9090
- **Config:** [reporters](/config/#reporters)
9191

92-
Specify reporters (default, blob, verbose, dot, json, tap, tap-flat, junit, hanging-process, github-actions)
92+
Specify reporters (default, blob, verbose, dot, json, tap, tap-flat, junit, tree, hanging-process, github-actions)
9393

9494
### outputFile
9595

docs/guide/migration.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,6 @@ outline: deep
77

88
## Migrating to Vitest 4.0 {#vitest-4}
99

10-
### Removed `reporters: 'basic'`
11-
12-
Basic reporter is removed as it is equal to:
13-
14-
```ts
15-
export default defineConfig({
16-
test: {
17-
reporters: [
18-
['default', { summary: false }]
19-
]
20-
}
21-
})
22-
```
23-
2410
### V8 Code Coverage Major Changes
2511

2612
Vitest's V8 code coverage provider is now using more accurate coverage result remapping logic.
@@ -291,6 +277,32 @@ exports[`custom element with shadow root 1`] = `
291277
</div>
292278
</body>"
293279
`
280+
281+
### Reporter Updates
282+
283+
Reporter APIs `onCollected`, `onSpecsCollected`, `onPathsCollected`, `onTaskUpdate` and `onFinished` were removed. See [`Reporters API`](/advanced/api/reporters) for new alternatives. The new APIs were introduced in Vitest `v3.0.0`.
284+
285+
The `basic` reporter was removed as it is equal to:
286+
287+
```ts
288+
export default defineConfig({
289+
test: {
290+
reporters: [
291+
['default', { summary: false }]
292+
]
293+
}
294+
})
295+
```
296+
297+
The [`verbose`](/guide/reporters#verbose-reporter) reporter now prints test cases as a flat list. To revert to the previous behaviour, use `--reporter=tree`:
298+
299+
```ts
300+
export default defineConfig({
301+
test: {
302+
reporters: ['verbose'], // [!code --]
303+
reporters: ['tree'], // [!code ++]
304+
}
305+
})
294306
```
295307

296308
### Deprecated APIs are Removed
@@ -299,7 +311,6 @@ Vitest 4.0 removes some deprecated APIs, including:
299311

300312
- `poolMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
301313
- `environmentMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
302-
- Reporter APIs `onCollected`, `onSpecsCollected`, `onPathsCollected`, `onTaskUpdate` and `onFinished`. See [`Reporters API`](/advanced/api/reporters) for new alternatives. These APIs were introduced in Vitest `v3.0.0`.
303314
- `deps.external`, `deps.inline`, `deps.fallbackCJS` config options. Use `server.deps.external`, `server.deps.inline`, or `server.deps.fallbackCJS` instead.
304315
- `browser.testerScripts` config option. Use [`browser.testerHtmlPath`](/guide/browser/config#browser-testerhtmlpath) instead.
305316
- `minWorkers` config option. Only `maxWorkers` has any effect on how tests are running, so we are removing this public option.

docs/guide/projects.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,54 @@ export default defineConfig({
4242
})
4343
```
4444

45-
Vitest will treat every folder in `packages` as a separate project even if it doesn't have a config file inside. If this glob pattern matches _any file_, it will be considered a Vitest config even if it doesn't have a `vitest` in its name or has an obscure file extension.
45+
Vitest will treat every folder in `packages` as a separate project even if it doesn't have a config file inside. If the glob pattern matches a file, it will validate that the name starts with `vitest.config`/`vite.config` or matches `(vite|vitest).*.config.*` pattern to ensure it's a Vitest configuration file. For example, these config files are valid:
46+
47+
- `vitest.config.ts`
48+
- `vite.config.js`
49+
- `vitest.unit.config.ts`
50+
- `vite.e2e.config.js`
51+
- `vitest.config.unit.js`
52+
- `vite.config.e2e.js`
53+
54+
To exclude folders and files, you can use the negation pattern:
55+
56+
```ts [vitest.config.ts]
57+
import { defineConfig } from 'vitest/config'
58+
59+
export default defineConfig({
60+
test: {
61+
// include all folders inside "packages" except "excluded"
62+
projects: [
63+
'packages/*',
64+
'!packages/excluded'
65+
],
66+
},
67+
})
68+
```
69+
70+
If you have a nested structure where some folders need to be projects, but other folders have their own subfolders, you have to use brackets to avoid matching the parent folder:
71+
72+
```ts [vitest.config.ts]
73+
import { defineConfig } from 'vitest/config'
74+
75+
// For example, this will create projects:
76+
// packages/a
77+
// packages/b
78+
// packages/business/c
79+
// packages/business/d
80+
// Notice that "packages/business" is not a project itself
81+
82+
export default defineConfig({
83+
test: {
84+
projects: [
85+
// matches every folder inside "packages" except "business"
86+
'packages/!(business)',
87+
// matches every folder inside "packages/business"
88+
'packages/business/*',
89+
],
90+
},
91+
})
92+
```
4693

4794
::: warning
4895
Vitest does not treat the root `vitest.config` file as a project unless it is explicitly specified in the configuration. Consequently, the root configuration will only influence global options such as `reporters` and `coverage`. Note that Vitest will always run certain plugin hooks, like `apply`, `config`, `configResolved` or `configureServer`, specified in the root config file. Vitest also uses the same plugins to execute global setups and custom coverage provider.

docs/guide/reporters.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,27 @@ Final output after tests have finished:
141141
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
142142
```
143143

144+
If there is only one test file running, Vitest will output the full test tree of that file, simillar to the [`tree`](#tree-reporter) reporter. The default reporter will also print the test tree if there is at least one failed test in the file.
145+
146+
```bash
147+
✓ __tests__/file1.test.ts (2) 725ms
148+
✓ first test file (2) 725ms
149+
✓ 2 + 2 should equal 4
150+
✓ 4 - 2 should equal 2
151+
152+
Test Files 1 passed (1)
153+
Tests 2 passed (2)
154+
Start at 12:34:32
155+
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
156+
```
157+
144158
### Verbose Reporter
145159

146-
Verbose reporter is same as `default` reporter, but it also displays each individual test after the suite has finished. It also displays currently running tests that are taking longer than [`slowTestThreshold`](/config/#slowtestthreshold). Similar to `default` reporter, you can disable the summary by configuring the reporter.
160+
The verbose reporter prints every test case once it is finished. It does not report suites or files separately. If `--includeTaskLocation` is enabled, it will also include the location of each test in the output. Similar to `default` reporter, you can disable the summary by configuring the reporter.
161+
162+
In addition to this, the `verbose` reporter prints test error messages right away. The full test error is reported when the test run is finished.
163+
164+
This is the only terminal reporter that reports [annotations](/guide/test-annotations) when the test doesn't fail.
147165

148166
:::code-group
149167
```bash [CLI]
@@ -161,6 +179,54 @@ export default defineConfig({
161179
```
162180
:::
163181

182+
Example output:
183+
184+
```bash
185+
✓ __tests__/file1.test.ts > first test file > 2 + 2 should equal 4 1ms
186+
✓ __tests__/file1.test.ts > first test file > 4 - 2 should equal 2 1ms
187+
✓ __tests__/file2.test.ts > second test file > 1 + 1 should equal 2 1ms
188+
✓ __tests__/file2.test.ts > second test file > 2 - 1 should equal 1 1ms
189+
190+
Test Files 2 passed (2)
191+
Tests 4 passed (4)
192+
Start at 12:34:32
193+
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
194+
```
195+
196+
An example with `--includeTaskLocation`:
197+
198+
```bash
199+
✓ __tests__/file1.test.ts:2:1 > first test file > 2 + 2 should equal 4 1ms
200+
✓ __tests__/file1.test.ts:3:1 > first test file > 4 - 2 should equal 2 1ms
201+
✓ __tests__/file2.test.ts:2:1 > second test file > 1 + 1 should equal 2 1ms
202+
✓ __tests__/file2.test.ts:3:1 > second test file > 2 - 1 should equal 1 1ms
203+
204+
Test Files 2 passed (2)
205+
Tests 4 passed (4)
206+
Start at 12:34:32
207+
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
208+
```
209+
210+
### Tree Reporter
211+
212+
The tree reporter is same as `default` reporter, but it also displays each individual test after the suite has finished. Similar to `default` reporter, you can disable the summary by configuring the reporter.
213+
214+
:::code-group
215+
```bash [CLI]
216+
npx vitest --reporter=tree
217+
```
218+
219+
```ts [vitest.config.ts]
220+
export default defineConfig({
221+
test: {
222+
reporters: [
223+
['tree', { summary: false }]
224+
]
225+
},
226+
})
227+
```
228+
:::
229+
164230
Example output for tests in progress with default `slowTestThreshold: 300`:
165231

166232
```bash

0 commit comments

Comments
 (0)