@vitest-agent/mcp 1.1.0 → 1.3.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 +1 -2
- package/index.d.ts +3 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/server.js +2 -4
- package/tools/run-tests.js +17 -3
- package/patterns/_meta.json +0 -67
- package/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
- package/patterns/known-issues-and-caveats.md +0 -52
- package/patterns/operating-vitest-agent-as-an-agent.md +0 -62
- package/patterns/running-tests-via-mcp.md +0 -103
- package/patterns/silencing-leaking-output-in-tests.md +0 -91
- package/patterns/testing-effect-schema-definitions.md +0 -71
- package/patterns/testing-effect-services-with-mock-layers.md +0 -63
- package/resources/index.js +0 -166
- package/resources/indexes.js +0 -77
- package/resources/manifest-schema.js +0 -46
- package/resources/paths.js +0 -20
- package/resources/patterns.js +0 -22
- package/resources/upstream-docs.js +0 -22
- package/vendor/vitest-docs/ATTRIBUTION.md +0 -5
- package/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
- package/vendor/vitest-docs/api/advanced/metadata.md +0 -68
- package/vendor/vitest-docs/api/advanced/plugin.md +0 -168
- package/vendor/vitest-docs/api/advanced/reporters.md +0 -342
- package/vendor/vitest-docs/api/advanced/runner.md +0 -334
- package/vendor/vitest-docs/api/advanced/test-case.md +0 -302
- package/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
- package/vendor/vitest-docs/api/advanced/test-module.md +0 -140
- package/vendor/vitest-docs/api/advanced/test-project.md +0 -321
- package/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
- package/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
- package/vendor/vitest-docs/api/advanced/vitest.md +0 -684
- package/vendor/vitest-docs/api/assert-type.md +0 -22
- package/vendor/vitest-docs/api/assert.md +0 -1960
- package/vendor/vitest-docs/api/browser/assertions.md +0 -1277
- package/vendor/vitest-docs/api/browser/commands.md +0 -154
- package/vendor/vitest-docs/api/browser/context.md +0 -338
- package/vendor/vitest-docs/api/browser/interactivity.md +0 -681
- package/vendor/vitest-docs/api/browser/locators.md +0 -1171
- package/vendor/vitest-docs/api/browser/react.md +0 -346
- package/vendor/vitest-docs/api/browser/svelte.md +0 -292
- package/vendor/vitest-docs/api/browser/vue.md +0 -222
- package/vendor/vitest-docs/api/describe.md +0 -374
- package/vendor/vitest-docs/api/expect-typeof.md +0 -571
- package/vendor/vitest-docs/api/expect.md +0 -2304
- package/vendor/vitest-docs/api/hooks.md +0 -463
- package/vendor/vitest-docs/api/mock.md +0 -701
- package/vendor/vitest-docs/api/test.md +0 -926
- package/vendor/vitest-docs/api/vi.md +0 -1372
- package/vendor/vitest-docs/config/alias.md +0 -13
- package/vendor/vitest-docs/config/allowonly.md +0 -32
- package/vendor/vitest-docs/config/api.md +0 -27
- package/vendor/vitest-docs/config/attachmentsdir.md +0 -6
- package/vendor/vitest-docs/config/bail.md +0 -9
- package/vendor/vitest-docs/config/benchmark.md +0 -65
- package/vendor/vitest-docs/config/browser/api.md +0 -23
- package/vendor/vitest-docs/config/browser/commands.md +0 -6
- package/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
- package/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
- package/vendor/vitest-docs/config/browser/enabled.md +0 -40
- package/vendor/vitest-docs/config/browser/expect.md +0 -250
- package/vendor/vitest-docs/config/browser/headless.md +0 -7
- package/vendor/vitest-docs/config/browser/instances.md +0 -47
- package/vendor/vitest-docs/config/browser/isolate.md +0 -11
- package/vendor/vitest-docs/config/browser/locators.md +0 -24
- package/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
- package/vendor/vitest-docs/config/browser/playwright.md +0 -214
- package/vendor/vitest-docs/config/browser/preview.md +0 -32
- package/vendor/vitest-docs/config/browser/provider.md +0 -79
- package/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
- package/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
- package/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
- package/vendor/vitest-docs/config/browser/trace.md +0 -43
- package/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
- package/vendor/vitest-docs/config/browser/ui.md +0 -7
- package/vendor/vitest-docs/config/browser/viewport.md +0 -6
- package/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
- package/vendor/vitest-docs/config/cache.md +0 -26
- package/vendor/vitest-docs/config/chaiconfig.md +0 -29
- package/vendor/vitest-docs/config/clearmocks.md +0 -22
- package/vendor/vitest-docs/config/coverage.md +0 -455
- package/vendor/vitest-docs/config/css.md +0 -47
- package/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
- package/vendor/vitest-docs/config/deps.md +0 -127
- package/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
- package/vendor/vitest-docs/config/diff.md +0 -96
- package/vendor/vitest-docs/config/dir.md +0 -7
- package/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
- package/vendor/vitest-docs/config/env.md +0 -5
- package/vendor/vitest-docs/config/environment.md +0 -96
- package/vendor/vitest-docs/config/environmentoptions.md +0 -30
- package/vendor/vitest-docs/config/exclude.md +0 -49
- package/vendor/vitest-docs/config/execargv.md +0 -10
- package/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
- package/vendor/vitest-docs/config/expect.md +0 -38
- package/vendor/vitest-docs/config/experimental.md +0 -510
- package/vendor/vitest-docs/config/faketimers.md +0 -51
- package/vendor/vitest-docs/config/fileparallelism.md +0 -11
- package/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
- package/vendor/vitest-docs/config/globals.md +0 -42
- package/vendor/vitest-docs/config/globalsetup.md +0 -72
- package/vendor/vitest-docs/config/hideskippedtests.md +0 -7
- package/vendor/vitest-docs/config/hooktimeout.md +0 -7
- package/vendor/vitest-docs/config/include-source.md +0 -115
- package/vendor/vitest-docs/config/include.md +0 -71
- package/vendor/vitest-docs/config/includetasklocation.md +0 -17
- package/vendor/vitest-docs/config/index.md +0 -85
- package/vendor/vitest-docs/config/isolate.md +0 -13
- package/vendor/vitest-docs/config/logheapusage.md +0 -7
- package/vendor/vitest-docs/config/maxconcurrency.md +0 -9
- package/vendor/vitest-docs/config/maxworkers.md +0 -49
- package/vendor/vitest-docs/config/mockreset.md +0 -22
- package/vendor/vitest-docs/config/mode.md +0 -7
- package/vendor/vitest-docs/config/name.md +0 -111
- package/vendor/vitest-docs/config/onconsolelog.md +0 -25
- package/vendor/vitest-docs/config/onstacktrace.md +0 -32
- package/vendor/vitest-docs/config/onunhandlederror.md +0 -35
- package/vendor/vitest-docs/config/open.md +0 -7
- package/vendor/vitest-docs/config/outputfile.md +0 -7
- package/vendor/vitest-docs/config/passwithnotests.md +0 -7
- package/vendor/vitest-docs/config/pool.md +0 -45
- package/vendor/vitest-docs/config/printconsoletrace.md +0 -6
- package/vendor/vitest-docs/config/projects.md +0 -6
- package/vendor/vitest-docs/config/provide.md +0 -45
- package/vendor/vitest-docs/config/reporters.md +0 -69
- package/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
- package/vendor/vitest-docs/config/restoremocks.md +0 -22
- package/vendor/vitest-docs/config/retry.md +0 -140
- package/vendor/vitest-docs/config/root.md +0 -6
- package/vendor/vitest-docs/config/runner.md +0 -6
- package/vendor/vitest-docs/config/sequence.md +0 -158
- package/vendor/vitest-docs/config/server.md +0 -68
- package/vendor/vitest-docs/config/setupfiles.md +0 -40
- package/vendor/vitest-docs/config/silent.md +0 -9
- package/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
- package/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
- package/vendor/vitest-docs/config/snapshotformat.md +0 -28
- package/vendor/vitest-docs/config/snapshotserializers.md +0 -6
- package/vendor/vitest-docs/config/stricttags.md +0 -30
- package/vendor/vitest-docs/config/tags.md +0 -141
- package/vendor/vitest-docs/config/teardowntimeout.md +0 -7
- package/vendor/vitest-docs/config/testnamepattern.md +0 -21
- package/vendor/vitest-docs/config/testtimeout.md +0 -7
- package/vendor/vitest-docs/config/typecheck.md +0 -77
- package/vendor/vitest-docs/config/ui.md +0 -15
- package/vendor/vitest-docs/config/unstubenvs.md +0 -20
- package/vendor/vitest-docs/config/unstubglobals.md +0 -20
- package/vendor/vitest-docs/config/update.md +0 -16
- package/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
- package/vendor/vitest-docs/config/watch.md +0 -11
- package/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
- package/vendor/vitest-docs/guide/advanced/index.md +0 -147
- package/vendor/vitest-docs/guide/advanced/pool.md +0 -148
- package/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
- package/vendor/vitest-docs/guide/advanced/tests.md +0 -125
- package/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
- package/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
- package/vendor/vitest-docs/guide/browser/index.md +0 -630
- package/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
- package/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
- package/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
- package/vendor/vitest-docs/guide/cli-generated.md +0 -972
- package/vendor/vitest-docs/guide/cli.md +0 -234
- package/vendor/vitest-docs/guide/common-errors.md +0 -163
- package/vendor/vitest-docs/guide/coverage.md +0 -515
- package/vendor/vitest-docs/guide/debugging.md +0 -127
- package/vendor/vitest-docs/guide/environment.md +0 -101
- package/vendor/vitest-docs/guide/extending-matchers.md +0 -160
- package/vendor/vitest-docs/guide/features.md +0 -310
- package/vendor/vitest-docs/guide/filtering.md +0 -175
- package/vendor/vitest-docs/guide/ide.md +0 -43
- package/vendor/vitest-docs/guide/improving-performance.md +0 -245
- package/vendor/vitest-docs/guide/in-source.md +0 -159
- package/vendor/vitest-docs/guide/index.md +0 -128
- package/vendor/vitest-docs/guide/learn/async.md +0 -147
- package/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
- package/vendor/vitest-docs/guide/learn/matchers.md +0 -277
- package/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
- package/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
- package/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
- package/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
- package/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
- package/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
- package/vendor/vitest-docs/guide/lifecycle.md +0 -379
- package/vendor/vitest-docs/guide/migration.md +0 -863
- package/vendor/vitest-docs/guide/mocking/classes.md +0 -158
- package/vendor/vitest-docs/guide/mocking/dates.md +0 -52
- package/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
- package/vendor/vitest-docs/guide/mocking/functions.md +0 -61
- package/vendor/vitest-docs/guide/mocking/globals.md +0 -20
- package/vendor/vitest-docs/guide/mocking/modules.md +0 -414
- package/vendor/vitest-docs/guide/mocking/requests.md +0 -114
- package/vendor/vitest-docs/guide/mocking/timers.md +0 -48
- package/vendor/vitest-docs/guide/mocking.md +0 -239
- package/vendor/vitest-docs/guide/open-telemetry.md +0 -156
- package/vendor/vitest-docs/guide/parallelism.md +0 -82
- package/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
- package/vendor/vitest-docs/guide/projects.md +0 -291
- package/vendor/vitest-docs/guide/recipes.md +0 -59
- package/vendor/vitest-docs/guide/reporters.md +0 -723
- package/vendor/vitest-docs/guide/snapshot.md +0 -620
- package/vendor/vitest-docs/guide/test-annotations.md +0 -103
- package/vendor/vitest-docs/guide/test-context.md +0 -902
- package/vendor/vitest-docs/guide/test-tags.md +0 -314
- package/vendor/vitest-docs/guide/testing-types.md +0 -149
- package/vendor/vitest-docs/guide/ui.md +0 -160
- package/vendor/vitest-docs/guide/using-plugins.md +0 -5
- package/vendor/vitest-docs/manifest.json +0 -1691
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# Test Filtering
|
|
2
|
-
|
|
3
|
-
As your test suite grows, running every test on every change becomes slow and distracting. If you're fixing a bug in a single module, you don't need to wait for hundreds of unrelated tests to finish. Test filtering lets you narrow down which tests run so you can stay focused on the code you're actively working on.
|
|
4
|
-
|
|
5
|
-
Vitest offers several ways to filter tests: from the command line, inside your test files, and through tags. Each approach is useful in different situations.
|
|
6
|
-
|
|
7
|
-
::: tip Performance Note
|
|
8
|
-
Filters like `-t`, `--tags-filter`, `.only`, and `.skip` are applied *per test file* — Vitest still has to run each test file to discover which tests match. In a large project, this overhead adds up even if only a few tests actually execute.
|
|
9
|
-
|
|
10
|
-
To avoid this, always pass a file path alongside your filter so Vitest only loads the files you care about:
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
vitest utils.test.ts -t "handles empty input"
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Alternatively, you can use the [`--experimental.preParse`](/config/experimental#experimental-preparse) flag, which parses test files to discover test names without fully executing them:
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
vitest --experimental.preParse -t "handles empty input"
|
|
20
|
-
```
|
|
21
|
-
:::
|
|
22
|
-
|
|
23
|
-
## Filtering by File Name
|
|
24
|
-
|
|
25
|
-
The simplest way to run a subset of tests is to pass a filename pattern as a CLI argument. Vitest will only run test files whose path contains the given string:
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
vitest basic
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
This matches any test file with `basic` in its path:
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
basic.test.ts
|
|
35
|
-
basic-foo.test.ts
|
|
36
|
-
basic/foo.test.ts
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
This is useful when you know which file you need to work on and want to skip everything else.
|
|
40
|
-
|
|
41
|
-
## Filtering by Test Name
|
|
42
|
-
|
|
43
|
-
Sometimes the test you care about is buried in a file with many other tests. The `-t` (or `--testNamePattern`) option filters by the test's name rather than the filename. It accepts a regex pattern and matches against the full test name, which includes any `describe` block names:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
vitest -t "handles empty input"
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
You can combine this with a file filter to narrow things down further:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
vitest utils -t "handles empty input"
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
This runs only tests whose name matches `"handles empty input"` inside files matching `utils`.
|
|
56
|
-
|
|
57
|
-
## Filtering by Line Number
|
|
58
|
-
|
|
59
|
-
When you're looking at a specific test in your editor, you often just want to run *that one test*. You can point directly to a line number:
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
vitest basic/foo.test.ts:10
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Vitest will run the test that contains line 10. This requires the full filename (relative or absolute):
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
vitest basic/foo.test.ts:10 # ✅
|
|
69
|
-
vitest ./basic/foo.test.ts:10 # ✅
|
|
70
|
-
vitest /users/project/basic/foo.test.ts:10 # ✅
|
|
71
|
-
vitest foo:10 # ❌ partial name won't work
|
|
72
|
-
vitest ./basic/foo:10 # ❌ missing file extension
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
To run multiple specific tests, separate them with spaces:
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
vitest basic/foo.test.ts:10 basic/foo.test.ts:25 # ✅
|
|
79
|
-
vitest basic/foo.test.ts:10-25 # ❌ ranges are not supported
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Filtering by Tags
|
|
83
|
-
|
|
84
|
-
For larger projects, you may want to categorize tests and run them by category. [Tags](/guide/test-tags) let you label tests and then filter by those labels from the CLI:
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
test('renders a form', { tags: ['frontend'] }, () => {
|
|
88
|
-
// ...
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test('calls an external API', { tags: ['backend'] }, () => {
|
|
92
|
-
// ...
|
|
93
|
-
})
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
vitest --tags-filter=frontend
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
This is particularly helpful in CI pipelines where you might want to run frontend and backend tests in separate jobs, or skip slow integration tests during quick checks.
|
|
101
|
-
|
|
102
|
-
## Focusing on Specific Tests with `.only`
|
|
103
|
-
|
|
104
|
-
When you're debugging a failing test, you want to run just that test without modifying CLI arguments every time. Adding `.only` to a test or suite tells Vitest to skip everything else in the file:
|
|
105
|
-
|
|
106
|
-
```ts
|
|
107
|
-
import { describe, expect, it } from 'vitest'
|
|
108
|
-
|
|
109
|
-
describe.only('suite', () => {
|
|
110
|
-
it('test', () => {
|
|
111
|
-
// This runs because the suite is marked with .only
|
|
112
|
-
expect(Math.sqrt(4)).toBe(2)
|
|
113
|
-
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
describe('another suite', () => {
|
|
117
|
-
it('skipped test', () => {
|
|
118
|
-
// This does not run
|
|
119
|
-
expect(Math.sqrt(4)).toBe(2)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it.only('focused test', () => {
|
|
123
|
-
// This also runs because it is marked with .only
|
|
124
|
-
expect(Math.sqrt(4)).toBe(2)
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
You can use `.only` on both `describe` blocks and individual tests. When any test or suite in a file is marked with `.only`, all unmarked tests in that file are skipped.
|
|
130
|
-
|
|
131
|
-
::: warning
|
|
132
|
-
Remember to remove `.only` before committing. By default, Vitest will fail the entire test run if it encounters `.only` in CI (when `process.env.CI` is set), preventing you from accidentally skipping tests in your pipeline. This behavior is controlled by the [`allowOnly`](/config/allowonly) option.
|
|
133
|
-
|
|
134
|
-
To catch `.only` even earlier, the [`no-focused-tests`](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-focused-tests.md) ESLint rule (also available in [oxlint](https://oxc.rs/docs/guide/usage/linter/rules/jest/no-focused-tests.html)) can flag it in your editor before you commit.
|
|
135
|
-
:::
|
|
136
|
-
|
|
137
|
-
## Skipping Tests with `.skip`
|
|
138
|
-
|
|
139
|
-
The opposite of `.only` is `.skip`. Use it to temporarily disable a test or suite without deleting it. Skipped tests still show up in the report so you don't forget about them:
|
|
140
|
-
|
|
141
|
-
```ts
|
|
142
|
-
import { describe, expect, it } from 'vitest'
|
|
143
|
-
|
|
144
|
-
describe.skip('skipped suite', () => {
|
|
145
|
-
it('test', () => {
|
|
146
|
-
// This entire suite is skipped
|
|
147
|
-
expect(Math.sqrt(4)).toBe(2)
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
describe('suite', () => {
|
|
152
|
-
it.skip('skipped test', () => {
|
|
153
|
-
// Just this one test is skipped
|
|
154
|
-
expect(Math.sqrt(4)).toBe(2)
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
This is useful when a test is flaky or depends on an external service that's temporarily down. It lets you keep the test in place as a reminder while unblocking the rest of the suite.
|
|
160
|
-
|
|
161
|
-
## Placeholder Tests with `.todo`
|
|
162
|
-
|
|
163
|
-
When planning new features, you might know what tests you'll need before you write the actual implementation. `.todo` marks a test as planned but not yet written. It shows up in the report as a reminder:
|
|
164
|
-
|
|
165
|
-
```ts
|
|
166
|
-
import { describe, it } from 'vitest'
|
|
167
|
-
|
|
168
|
-
describe.todo('unimplemented suite')
|
|
169
|
-
|
|
170
|
-
describe('suite', () => {
|
|
171
|
-
it.todo('unimplemented test')
|
|
172
|
-
})
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
Unlike `.skip`, a `.todo` test has no test body. It's purely a placeholder for future work.
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { useData } from 'vitepress'
|
|
3
|
-
const { isDark } = useData()
|
|
4
|
-
</script>
|
|
5
|
-
|
|
6
|
-
# IDE Integrations
|
|
7
|
-
|
|
8
|
-
## VS Code <Badge>Official</Badge> {#vs-code}
|
|
9
|
-
|
|
10
|
-
<p text-center>
|
|
11
|
-
<img :src="`https://raw.githubusercontent.com/vitest-dev/vscode/main/img/cover-${isDark ? 'light' : 'dark' }.png`" w-60 alt="vscode logo">
|
|
12
|
-
</p>
|
|
13
|
-
|
|
14
|
-
[GitHub](https://github.com/vitest-dev/vscode) | [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=vitest.explorer)
|
|
15
|
-
|
|
16
|
-

|
|
17
|
-
|
|
18
|
-
## JetBrains IDE
|
|
19
|
-
|
|
20
|
-
WebStorm, PhpStorm, IntelliJ IDEA Ultimate, and other JetBrains IDEs come with built-in support for Vitest.
|
|
21
|
-
|
|
22
|
-
<p text-center>
|
|
23
|
-
<img :src="`/ide/vitest-jb-${isDark ? 'light' : 'dark'}.png`" w-60 alt="webstorm logo">
|
|
24
|
-
</p>
|
|
25
|
-
|
|
26
|
-
[WebStorm Help](https://www.jetbrains.com/help/webstorm/vitest.html) | [IntelliJ IDEA Ultimate Help](https://www.jetbrains.com/help/idea/vitest.html) | [PhpStorm Help](https://www.jetbrains.com/help/phpstorm/vitest.html)
|
|
27
|
-
|
|
28
|
-

|
|
29
|
-
|
|
30
|
-
## Wallaby.js <Badge>Paid (free for OSS)</Badge>
|
|
31
|
-
|
|
32
|
-
Created by [The Wallaby Team](https://wallabyjs.com)
|
|
33
|
-
|
|
34
|
-
[Wallaby.js](https://wallabyjs.com) runs your Vitest tests immediately as you type, highlighting results in your IDE right next to your code.
|
|
35
|
-
|
|
36
|
-
<p text-left>
|
|
37
|
-
<img :src="`/ide/vitest-wallaby-${isDark ? 'light' : 'dark'}.png`" alt="Vitest + Wallaby logos" w-142>
|
|
38
|
-
</p>
|
|
39
|
-
|
|
40
|
-
[VS Code](https://marketplace.visualstudio.com/items?itemName=WallabyJs.wallaby-vscode) | [JetBrains](https://plugins.jetbrains.com/plugin/15742-wallaby) |
|
|
41
|
-
[Visual Studio](https://marketplace.visualstudio.com/items?itemName=vs-publisher-999439.WallabyjsforVisualStudio2022) | [Sublime Text](https://packagecontrol.io/packages/Wallaby)
|
|
42
|
-
|
|
43
|
-

|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
# Improving Performance
|
|
2
|
-
|
|
3
|
-
## Test Isolation
|
|
4
|
-
|
|
5
|
-
By default Vitest runs every test file in an isolated environment based on the [pool](/config/pool):
|
|
6
|
-
|
|
7
|
-
- `threads` pool runs every test file in a separate [`Worker`](https://nodejs.org/api/worker_threads.html#class-worker)
|
|
8
|
-
- `forks` pool runs every test file in a separate [forked child process](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options)
|
|
9
|
-
- `vmThreads` pool runs every test file in a separate [VM context](https://nodejs.org/api/vm.html#vmcreatecontextcontextobject-options), but it uses workers for parallelism
|
|
10
|
-
|
|
11
|
-
This greatly increases test times, which might not be desirable for projects that don't rely on side effects and properly cleanup their state (which is usually true for projects with `node` environment). In this case disabling isolation will improve the speed of your tests. To do that, you can provide `--no-isolate` flag to the CLI or set [`test.isolate`](/config/isolate) property in the config to `false`.
|
|
12
|
-
|
|
13
|
-
::: code-group
|
|
14
|
-
```bash [CLI]
|
|
15
|
-
vitest --no-isolate
|
|
16
|
-
```
|
|
17
|
-
```ts [vitest.config.js]
|
|
18
|
-
import { defineConfig } from 'vitest/config'
|
|
19
|
-
|
|
20
|
-
export default defineConfig({
|
|
21
|
-
test: {
|
|
22
|
-
isolate: false,
|
|
23
|
-
},
|
|
24
|
-
})
|
|
25
|
-
```
|
|
26
|
-
:::
|
|
27
|
-
|
|
28
|
-
You can also disable isolation for specific files only by using `projects`:
|
|
29
|
-
|
|
30
|
-
```ts [vitest.config.js]
|
|
31
|
-
import { defineConfig } from 'vitest/config'
|
|
32
|
-
|
|
33
|
-
export default defineConfig({
|
|
34
|
-
test: {
|
|
35
|
-
projects: [
|
|
36
|
-
{
|
|
37
|
-
test: {
|
|
38
|
-
name: 'Isolated',
|
|
39
|
-
isolate: true, // (default value)
|
|
40
|
-
exclude: ['**.non-isolated.test.ts'],
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
test: {
|
|
45
|
-
name: 'Non-isolated',
|
|
46
|
-
isolate: false,
|
|
47
|
-
include: ['**.non-isolated.test.ts'],
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
:::tip
|
|
56
|
-
If you are using `vmThreads` pool, you cannot disable isolation. Use `threads` pool instead to improve your tests performance.
|
|
57
|
-
:::
|
|
58
|
-
|
|
59
|
-
For some projects, it might also be desirable to disable parallelism to improve startup time. To do that, provide `--no-file-parallelism` flag to the CLI or set [`test.fileParallelism`](/config/fileparallelism) property in the config to `false`.
|
|
60
|
-
|
|
61
|
-
::: code-group
|
|
62
|
-
```bash [CLI]
|
|
63
|
-
vitest --no-file-parallelism
|
|
64
|
-
```
|
|
65
|
-
```ts [vitest.config.js]
|
|
66
|
-
import { defineConfig } from 'vitest/config'
|
|
67
|
-
|
|
68
|
-
export default defineConfig({
|
|
69
|
-
test: {
|
|
70
|
-
fileParallelism: false,
|
|
71
|
-
},
|
|
72
|
-
})
|
|
73
|
-
```
|
|
74
|
-
:::
|
|
75
|
-
|
|
76
|
-
## Limiting Directory Search
|
|
77
|
-
|
|
78
|
-
You can limit the working directory when Vitest searches for files using [`test.dir`](/config/dir) option. This should make the search faster if you have unrelated folders and files in the root directory.
|
|
79
|
-
|
|
80
|
-
## Caching Between Reruns
|
|
81
|
-
|
|
82
|
-
In watch mode, Vitest caches all transformed files in memory, which makes reruns fast. However, this cache is discarded once the test run finishes. By enabling [`experimental.fsModuleCache`](/config/experimental#experimental-fsmodulecache), Vitest persists this cache to the file system so it can be reused across reruns.
|
|
83
|
-
|
|
84
|
-
This improvement is most noticeable when rerunning a small number of tests that depend on a large module graph. For full test suites, parallelization already mitigates the cost because other tests populate the in-memory cache while earlier tests are still running. For example, running one test file with a huge module graph (>900 modules):
|
|
85
|
-
|
|
86
|
-
```shell
|
|
87
|
-
# the first run
|
|
88
|
-
Duration 8.75s (transform 4.02s, setup 629ms, import 5.52s, tests 2.52s, environment 0ms, prepare 3ms)
|
|
89
|
-
|
|
90
|
-
# the second run
|
|
91
|
-
Duration 5.90s (transform 842ms, setup 543ms, import 2.35s, tests 2.94s, environment 0ms, prepare 3ms)
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Pool
|
|
95
|
-
|
|
96
|
-
By default Vitest runs tests in `pool: 'forks'`. While `'forks'` pool is better for compatibility issues ([hanging process](/guide/common-errors.html#failed-to-terminate-worker) and [segfaults](/guide/common-errors.html#segfaults-and-native-code-errors)), it may be slightly slower than `pool: 'threads'` in larger projects.
|
|
97
|
-
|
|
98
|
-
You can try to improve test run time by switching `pool` option in configuration:
|
|
99
|
-
|
|
100
|
-
::: code-group
|
|
101
|
-
```bash [CLI]
|
|
102
|
-
vitest --pool=threads
|
|
103
|
-
```
|
|
104
|
-
```ts [vitest.config.js]
|
|
105
|
-
import { defineConfig } from 'vitest/config'
|
|
106
|
-
|
|
107
|
-
export default defineConfig({
|
|
108
|
-
test: {
|
|
109
|
-
pool: 'threads',
|
|
110
|
-
},
|
|
111
|
-
})
|
|
112
|
-
```
|
|
113
|
-
:::
|
|
114
|
-
|
|
115
|
-
## Sharding
|
|
116
|
-
|
|
117
|
-
Test sharding is a process of splitting your test suite into groups, or shards. This can be useful when you have a large test suite and multiple machines that could run subsets of that suite simultaneously.
|
|
118
|
-
|
|
119
|
-
To split Vitest tests on multiple different runs, use [`--shard`](/guide/cli#shard) option with [`--reporter=blob`](/guide/reporters#blob-reporter) option:
|
|
120
|
-
|
|
121
|
-
```sh
|
|
122
|
-
vitest run --reporter=blob --shard=1/3 # 1st machine
|
|
123
|
-
vitest run --reporter=blob --shard=2/3 # 2nd machine
|
|
124
|
-
vitest run --reporter=blob --shard=3/3 # 3rd machine
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
> Vitest splits your _test files_, not your test cases, into shards. If you've got 1000 test files, the `--shard=1/4` option will run 250 test files, no matter how many test cases individual files have.
|
|
128
|
-
|
|
129
|
-
Collect the results stored in `.vitest-reports` directory from each machine and merge them with [`--merge-reports`](/guide/cli#merge-reports) option:
|
|
130
|
-
|
|
131
|
-
```sh
|
|
132
|
-
vitest run --merge-reports
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
::: details GitHub Actions example
|
|
136
|
-
This setup is also used at https://github.com/vitest-tests/test-sharding.
|
|
137
|
-
|
|
138
|
-
```yaml
|
|
139
|
-
# Inspired from https://playwright.dev/docs/test-sharding
|
|
140
|
-
name: Tests
|
|
141
|
-
on:
|
|
142
|
-
push:
|
|
143
|
-
branches:
|
|
144
|
-
- main
|
|
145
|
-
jobs:
|
|
146
|
-
tests:
|
|
147
|
-
runs-on: ubuntu-latest
|
|
148
|
-
strategy:
|
|
149
|
-
matrix:
|
|
150
|
-
shardIndex: [1, 2, 3, 4]
|
|
151
|
-
shardTotal: [4]
|
|
152
|
-
steps:
|
|
153
|
-
- uses: actions/checkout@v4
|
|
154
|
-
- uses: actions/setup-node@v4
|
|
155
|
-
with:
|
|
156
|
-
node-version: 20
|
|
157
|
-
|
|
158
|
-
- name: Install pnpm
|
|
159
|
-
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
|
|
160
|
-
|
|
161
|
-
- name: Install dependencies
|
|
162
|
-
run: pnpm i
|
|
163
|
-
|
|
164
|
-
- name: Run tests
|
|
165
|
-
run: pnpm run test --reporter=blob --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
|
|
166
|
-
|
|
167
|
-
- name: Upload blob report to GitHub Actions Artifacts
|
|
168
|
-
if: ${{ !cancelled() }}
|
|
169
|
-
uses: actions/upload-artifact@v4
|
|
170
|
-
with:
|
|
171
|
-
name: blob-report-${{ matrix.shardIndex }}
|
|
172
|
-
path: .vitest-reports/*
|
|
173
|
-
include-hidden-files: true
|
|
174
|
-
retention-days: 1
|
|
175
|
-
|
|
176
|
-
- name: Upload attachments to GitHub Actions Artifacts
|
|
177
|
-
if: ${{ !cancelled() }}
|
|
178
|
-
uses: actions/upload-artifact@v4
|
|
179
|
-
with:
|
|
180
|
-
name: blob-attachments-${{ matrix.shardIndex }}
|
|
181
|
-
path: .vitest-attachments/**
|
|
182
|
-
include-hidden-files: true
|
|
183
|
-
retention-days: 1
|
|
184
|
-
|
|
185
|
-
merge-reports:
|
|
186
|
-
if: ${{ !cancelled() }}
|
|
187
|
-
needs: [tests]
|
|
188
|
-
|
|
189
|
-
runs-on: ubuntu-latest
|
|
190
|
-
steps:
|
|
191
|
-
- uses: actions/checkout@v4
|
|
192
|
-
- uses: actions/setup-node@v4
|
|
193
|
-
with:
|
|
194
|
-
node-version: 20
|
|
195
|
-
|
|
196
|
-
- name: Install pnpm
|
|
197
|
-
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
|
|
198
|
-
|
|
199
|
-
- name: Install dependencies
|
|
200
|
-
run: pnpm i
|
|
201
|
-
|
|
202
|
-
- name: Download blob reports from GitHub Actions Artifacts
|
|
203
|
-
uses: actions/download-artifact@v4
|
|
204
|
-
with:
|
|
205
|
-
path: .vitest-reports
|
|
206
|
-
pattern: blob-report-*
|
|
207
|
-
merge-multiple: true
|
|
208
|
-
|
|
209
|
-
- name: Download attachments from GitHub Actions Artifacts
|
|
210
|
-
uses: actions/download-artifact@v4
|
|
211
|
-
with:
|
|
212
|
-
path: .vitest-attachments
|
|
213
|
-
pattern: blob-attachments-*
|
|
214
|
-
merge-multiple: true
|
|
215
|
-
|
|
216
|
-
- name: Merge reports
|
|
217
|
-
run: npx vitest --merge-reports
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
If your tests create file-based attachments (for example via `context.annotate` or custom artifacts), upload and restore [`attachmentsDir`](/config/attachmentsdir) in the merge job as shown above.
|
|
221
|
-
|
|
222
|
-
:::
|
|
223
|
-
|
|
224
|
-
:::tip
|
|
225
|
-
Test sharding can also become useful on high CPU-count machines.
|
|
226
|
-
|
|
227
|
-
Vitest will run only a single Vite server in its main thread. Rest of the threads are used to run test files.
|
|
228
|
-
In a high CPU-count machine the main thread can become a bottleneck as it cannot handle all the requests coming from the threads. For example in 32 CPU machine the main thread is responsible to handle load coming from 31 test threads.
|
|
229
|
-
|
|
230
|
-
To reduce the load from main thread's Vite server you can use test sharding. The load can be balanced on multiple Vite server.
|
|
231
|
-
|
|
232
|
-
```sh
|
|
233
|
-
# Example for splitting tests on 32 CPU to 4 shards.
|
|
234
|
-
# As each process needs 1 main thread, there's 7 threads for test runners (1+7)*4 = 32
|
|
235
|
-
# Use VITEST_MAX_WORKERS:
|
|
236
|
-
VITEST_MAX_WORKERS=7 vitest run --reporter=blob --shard=1/4 & \
|
|
237
|
-
VITEST_MAX_WORKERS=7 vitest run --reporter=blob --shard=2/4 & \
|
|
238
|
-
VITEST_MAX_WORKERS=7 vitest run --reporter=blob --shard=3/4 & \
|
|
239
|
-
VITEST_MAX_WORKERS=7 vitest run --reporter=blob --shard=4/4 & \
|
|
240
|
-
wait # https://man7.org/linux/man-pages/man2/waitpid.2.html
|
|
241
|
-
|
|
242
|
-
vitest run --merge-reports
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
:::
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
# In-Source Testing
|
|
2
|
-
|
|
3
|
-
Vitest provides a way to run tests within your source code along side the implementation, similar to [Rust's module tests](https://doc.rust-lang.org/book/ch11-03-test-organization.html#the-tests-module-and-cfgtest).
|
|
4
|
-
|
|
5
|
-
This makes the tests share the same closure as the implementations and able to test against private states without exporting. Meanwhile, it also brings a closer feedback loop for development.
|
|
6
|
-
|
|
7
|
-
::: warning
|
|
8
|
-
This guide explains how to write tests inside your source code. If you need to write tests in separate test files, follow the ["Writing Tests" guide](/guide/#writing-tests).
|
|
9
|
-
:::
|
|
10
|
-
|
|
11
|
-
## Setup
|
|
12
|
-
|
|
13
|
-
To get started, put a `if (import.meta.vitest)` block at the end of your source file and write some tests inside it. For example:
|
|
14
|
-
|
|
15
|
-
```ts [src/index.ts]
|
|
16
|
-
// the implementation
|
|
17
|
-
export function add(...args: number[]) {
|
|
18
|
-
return args.reduce((a, b) => a + b, 0)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// in-source test suites
|
|
22
|
-
if (import.meta.vitest) {
|
|
23
|
-
const { it, expect } = import.meta.vitest
|
|
24
|
-
it('add', () => {
|
|
25
|
-
expect(add()).toBe(0)
|
|
26
|
-
expect(add(1)).toBe(1)
|
|
27
|
-
expect(add(1, 2, 3)).toBe(6)
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Update the `includeSource` config for Vitest to grab the files under `src/`:
|
|
33
|
-
|
|
34
|
-
```ts [vitest.config.ts]
|
|
35
|
-
import { defineConfig } from 'vitest/config'
|
|
36
|
-
|
|
37
|
-
export default defineConfig({
|
|
38
|
-
test: {
|
|
39
|
-
includeSource: ['src/**/*.{js,ts}'], // [!code ++]
|
|
40
|
-
},
|
|
41
|
-
})
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Then you can start to test!
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
$ npx vitest
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Production Build
|
|
51
|
-
|
|
52
|
-
For the production build, you will need to set the `define` options in your config file, letting the bundler do the dead code elimination. For example, in Vite
|
|
53
|
-
|
|
54
|
-
```ts [vite.config.ts]
|
|
55
|
-
/// <reference types="vitest/config" />
|
|
56
|
-
|
|
57
|
-
import { defineConfig } from 'vite'
|
|
58
|
-
|
|
59
|
-
export default defineConfig({
|
|
60
|
-
test: {
|
|
61
|
-
includeSource: ['src/**/*.{js,ts}'],
|
|
62
|
-
},
|
|
63
|
-
define: { // [!code ++]
|
|
64
|
-
'import.meta.vitest': 'undefined', // [!code ++]
|
|
65
|
-
}, // [!code ++]
|
|
66
|
-
})
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Other Bundlers
|
|
70
|
-
|
|
71
|
-
::: details Rolldown
|
|
72
|
-
```js [rolldown.config.js]
|
|
73
|
-
import { defineConfig } from 'rolldown/config'
|
|
74
|
-
|
|
75
|
-
export default defineConfig({
|
|
76
|
-
transform: {
|
|
77
|
-
define: { // [!code ++]
|
|
78
|
-
'import.meta.vitest': 'undefined', // [!code ++]
|
|
79
|
-
}, // [!code ++]
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Learn more: [Rolldown](https://rolldown.rs/)
|
|
85
|
-
:::
|
|
86
|
-
|
|
87
|
-
::: details Rollup
|
|
88
|
-
```js [rollup.config.js]
|
|
89
|
-
import replace from '@rollup/plugin-replace' // [!code ++]
|
|
90
|
-
|
|
91
|
-
export default {
|
|
92
|
-
plugins: [
|
|
93
|
-
replace({ // [!code ++]
|
|
94
|
-
'import.meta.vitest': 'undefined', // [!code ++]
|
|
95
|
-
}) // [!code ++]
|
|
96
|
-
],
|
|
97
|
-
// other options
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Learn more: [Rollup](https://rollupjs.org/)
|
|
102
|
-
:::
|
|
103
|
-
|
|
104
|
-
::: details unbuild
|
|
105
|
-
```js [build.config.js]
|
|
106
|
-
import { defineBuildConfig } from 'unbuild'
|
|
107
|
-
|
|
108
|
-
export default defineBuildConfig({
|
|
109
|
-
replace: { // [!code ++]
|
|
110
|
-
'import.meta.vitest': 'undefined', // [!code ++]
|
|
111
|
-
}, // [!code ++]
|
|
112
|
-
// other options
|
|
113
|
-
})
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Learn more: [unbuild](https://github.com/unjs/unbuild)
|
|
117
|
-
:::
|
|
118
|
-
|
|
119
|
-
::: details webpack
|
|
120
|
-
```js [webpack.config.js]
|
|
121
|
-
const webpack = require('webpack')
|
|
122
|
-
|
|
123
|
-
module.exports = {
|
|
124
|
-
plugins: [
|
|
125
|
-
new webpack.DefinePlugin({ // [!code ++]
|
|
126
|
-
'import.meta.vitest': 'undefined', // [!code ++]
|
|
127
|
-
})// [!code ++]
|
|
128
|
-
],
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
Learn more: [webpack](https://webpack.js.org/plugins/define-plugin/)
|
|
133
|
-
:::
|
|
134
|
-
|
|
135
|
-
## TypeScript
|
|
136
|
-
|
|
137
|
-
To get TypeScript support for `import.meta.vitest`, add `vitest/importMeta` to your `tsconfig.json`:
|
|
138
|
-
|
|
139
|
-
```json [tsconfig.json]
|
|
140
|
-
{
|
|
141
|
-
"compilerOptions": {
|
|
142
|
-
"types": [
|
|
143
|
-
"vitest/importMeta" // [!code ++]
|
|
144
|
-
]
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
Reference to [`examples/in-source-test`](https://github.com/vitest-dev/vitest/tree/main/examples/in-source-test) for the full example.
|
|
150
|
-
|
|
151
|
-
## Notes
|
|
152
|
-
|
|
153
|
-
This feature could be useful for:
|
|
154
|
-
|
|
155
|
-
- Unit testing for small-scoped functions or utilities
|
|
156
|
-
- Prototyping
|
|
157
|
-
- Inline Assertion
|
|
158
|
-
|
|
159
|
-
It's recommended to **use separate test files instead** for more complex tests like components or E2E testing.
|