@vitest-agent/mcp 1.1.0 → 1.2.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 +2 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/server.js +2 -4
- 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,234 +0,0 @@
|
|
|
1
|
-
# Command Line Interface
|
|
2
|
-
|
|
3
|
-
## Commands
|
|
4
|
-
|
|
5
|
-
### `vitest`
|
|
6
|
-
|
|
7
|
-
Start Vitest in the current directory. Will enter the watch mode in development environment and run mode in CI (or non-interactive terminal) automatically.
|
|
8
|
-
|
|
9
|
-
You can pass an additional argument as the filter of the test files to run. For example:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
vitest foobar
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Will run only the test file that contains `foobar` in their paths. This filter only checks inclusion and doesn't support regexp or glob patterns (unless your terminal processes it before Vitest receives the filter).
|
|
16
|
-
|
|
17
|
-
Since Vitest 3, you can also specify the test by filename and line number:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
$ vitest basic/foo.test.ts:10
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
::: warning
|
|
24
|
-
Note that Vitest requires the full filename for this feature to work. It can be relative to the current working directory or an absolute file path.
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
$ vitest basic/foo.js:10 # ✅
|
|
28
|
-
$ vitest ./basic/foo.js:10 # ✅
|
|
29
|
-
$ vitest /users/project/basic/foo.js:10 # ✅
|
|
30
|
-
$ vitest foo:10 # ❌
|
|
31
|
-
$ vitest ./basic/foo:10 # ❌
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
At the moment Vitest also doesn't support ranges:
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
$ vitest basic/foo.test.ts:10, basic/foo.test.ts:25 # ✅
|
|
38
|
-
$ vitest basic/foo.test.ts:10-25 # ❌
|
|
39
|
-
```
|
|
40
|
-
:::
|
|
41
|
-
|
|
42
|
-
### `vitest run`
|
|
43
|
-
|
|
44
|
-
Perform a single run without watch mode.
|
|
45
|
-
|
|
46
|
-
### `vitest watch`
|
|
47
|
-
|
|
48
|
-
Run all test suites but watch for changes and rerun tests when they change. Same as calling `vitest` without an argument. Will fallback to `vitest run` in CI or when stdin is not a TTY (non-interactive environment).
|
|
49
|
-
|
|
50
|
-
### `vitest dev`
|
|
51
|
-
|
|
52
|
-
Alias to `vitest watch`.
|
|
53
|
-
|
|
54
|
-
### `vitest related`
|
|
55
|
-
|
|
56
|
-
Run only tests that cover a list of source files. Works with static imports (e.g., `import('./index.js')` or `import index from './index.js`), but not the dynamic ones (e.g., `import(filepath)`). All files should be relative to root folder.
|
|
57
|
-
|
|
58
|
-
Useful to run with [`lint-staged`](https://github.com/okonet/lint-staged) or with your CI setup.
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
vitest related /src/index.ts /src/hello-world.js
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
::: tip
|
|
65
|
-
Don't forget that Vitest runs with enabled watch mode by default. If you are using tools like `lint-staged`, you should also pass `--run` option, so that command can exit normally.
|
|
66
|
-
|
|
67
|
-
```js [.lintstagedrc.js]
|
|
68
|
-
export default {
|
|
69
|
-
'*.{js,ts}': 'vitest related --run',
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
:::
|
|
73
|
-
|
|
74
|
-
### `vitest bench`
|
|
75
|
-
|
|
76
|
-
Run only [benchmark](/guide/features.html#benchmarking) tests, which compare performance results.
|
|
77
|
-
|
|
78
|
-
### `vitest init`
|
|
79
|
-
|
|
80
|
-
`vitest init <name>` can be used to setup project configuration. At the moment, it only supports [`browser`](/guide/browser/) value:
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
vitest init browser
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### `vitest list`
|
|
87
|
-
|
|
88
|
-
`vitest list` command inherits all `vitest` options to print the list of all matching tests. This command ignores `reporters` option. By default, it will print the names of all tests that matched the file filter and name pattern:
|
|
89
|
-
|
|
90
|
-
```shell
|
|
91
|
-
vitest list filename.spec.ts -t="some-test"
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
```txt
|
|
95
|
-
describe > some-test
|
|
96
|
-
describe > some-test > test 1
|
|
97
|
-
describe > some-test > test 2
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
You can pass down `--json` flag to print tests in JSON format or save it in a separate file:
|
|
101
|
-
|
|
102
|
-
```bash
|
|
103
|
-
vitest list filename.spec.ts -t="some-test" --json=./file.json
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
If `--json` flag doesn't receive a value, it will output the JSON into stdout.
|
|
107
|
-
|
|
108
|
-
You also can pass down `--filesOnly` flag to print the test files only:
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
vitest list --filesOnly
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
```txt
|
|
115
|
-
tests/test1.test.ts
|
|
116
|
-
tests/test2.test.ts
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
Since Vitest 4.1, you may pass `--static-parse` to [parse test files](/api/advanced/vitest#parsespecifications) instead of running them to collect tests. Vitest parses test files with limited concurrency, defaulting to `os.availableParallelism()`. You can change it via the `--static-parse-concurrency` option.
|
|
120
|
-
|
|
121
|
-
## Shell Autocompletions
|
|
122
|
-
|
|
123
|
-
Vitest provides shell autocompletions for commands, options, and option values powered by [`@bomb.sh/tab`](https://github.com/bombshell-dev/tab).
|
|
124
|
-
|
|
125
|
-
### Setup
|
|
126
|
-
|
|
127
|
-
For permanent setup in zsh, add this to your `~/.zshrc`:
|
|
128
|
-
|
|
129
|
-
```bash
|
|
130
|
-
# Add to ~/.zshrc for permanent autocompletions (same can be done for other shells)
|
|
131
|
-
source <(vitest complete zsh)
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Package Manager Integration
|
|
135
|
-
|
|
136
|
-
`@bomb.sh/tab` integrates with [package managers](https://github.com/bombshell-dev/tab?tab=readme-ov-file#package-manager-completions). Autocompletions work when running vitest directly:
|
|
137
|
-
|
|
138
|
-
::: code-group
|
|
139
|
-
|
|
140
|
-
```bash [npm]
|
|
141
|
-
npm vitest <Tab>
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
```bash [npm]
|
|
145
|
-
npm exec vitest <Tab>
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
```bash [pnpm]
|
|
149
|
-
pnpm vitest <Tab>
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
```bash [yarn]
|
|
153
|
-
yarn vitest <Tab>
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
```bash [bun]
|
|
157
|
-
bun vitest <Tab>
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
:::
|
|
161
|
-
|
|
162
|
-
For package manager autocompletions, you should install [tab's package manager completions](https://github.com/bombshell-dev/tab?tab=readme-ov-file#package-manager-completions) separately.
|
|
163
|
-
|
|
164
|
-
## Options
|
|
165
|
-
|
|
166
|
-
::: tip
|
|
167
|
-
Vitest supports both camel case and kebab case for [CLI arguments](https://github.com/cacjs/cac#dot-nested-options). For example, `--passWithNoTests` and `--pass-with-no-tests` will both work (`--no-color` and `--inspect-brk` are the exceptions).
|
|
168
|
-
|
|
169
|
-
Vitest also supports different ways of specifying the value: `--reporter dot` and `--reporter=dot` are both valid.
|
|
170
|
-
|
|
171
|
-
If option supports an array of values, you need to pass the option multiple times:
|
|
172
|
-
|
|
173
|
-
```
|
|
174
|
-
vitest --reporter=dot --reporter=default
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
Boolean options can be negated with `no-` prefix. Specifying the value as `false` also works:
|
|
178
|
-
|
|
179
|
-
```
|
|
180
|
-
vitest --no-api
|
|
181
|
-
vitest --api=false
|
|
182
|
-
```
|
|
183
|
-
:::
|
|
184
|
-
|
|
185
|
-
<!--@include: ./cli-generated.md-->
|
|
186
|
-
|
|
187
|
-
### changed
|
|
188
|
-
|
|
189
|
-
- **Type:** `boolean | string`
|
|
190
|
-
- **Default:** false
|
|
191
|
-
|
|
192
|
-
Run tests only against changed files. If no value is provided, it will run tests against uncommitted changes (including staged and unstaged).
|
|
193
|
-
|
|
194
|
-
To run tests against changes made in the last commit, you can use `--changed HEAD~1`. You can also pass commit hash (e.g. `--changed 09a9920`) or branch name (e.g. `--changed origin/develop`).
|
|
195
|
-
|
|
196
|
-
When used with code coverage the report will contain only the files that were related to the changes.
|
|
197
|
-
|
|
198
|
-
If paired with the [`forceRerunTriggers`](/config/forcereruntriggers) config option it will run the whole test suite if at least one of the files listed in the `forceRerunTriggers` list changes. By default, changes to the Vitest config file and `package.json` will always rerun the whole suite.
|
|
199
|
-
|
|
200
|
-
### shard
|
|
201
|
-
|
|
202
|
-
- **Type:** `string`
|
|
203
|
-
- **Default:** disabled
|
|
204
|
-
|
|
205
|
-
Test suite shard to execute in a format of `<index>`/`<count>`, where
|
|
206
|
-
|
|
207
|
-
- `count` is a positive integer, count of divided parts
|
|
208
|
-
- `index` is a positive integer, index of divided part
|
|
209
|
-
|
|
210
|
-
This command will divide all tests into `count` equal parts, and will run only those that happen to be in an `index` part. For example, to split your tests suite into three parts, use this:
|
|
211
|
-
|
|
212
|
-
```sh
|
|
213
|
-
vitest run --shard=1/3
|
|
214
|
-
vitest run --shard=2/3
|
|
215
|
-
vitest run --shard=3/3
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
:::warning
|
|
219
|
-
You cannot use this option with `--watch` enabled (enabled in dev by default).
|
|
220
|
-
:::
|
|
221
|
-
|
|
222
|
-
::: tip
|
|
223
|
-
If `--reporter=blob` is used without an output file, the default path will include the current shard config to avoid collisions with other Vitest processes.
|
|
224
|
-
:::
|
|
225
|
-
|
|
226
|
-
### merge-reports
|
|
227
|
-
|
|
228
|
-
- **Type:** `boolean | string`
|
|
229
|
-
|
|
230
|
-
Merges every blob report located in the specified folder (`.vitest-reports` by default). You can use any reporters with this command (except [`blob`](/guide/reporters#blob-reporter)):
|
|
231
|
-
|
|
232
|
-
```sh
|
|
233
|
-
vitest --merge-reports --reporter=junit
|
|
234
|
-
```
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
# Common Errors
|
|
2
|
-
|
|
3
|
-
## Cannot find module './relative-path'
|
|
4
|
-
|
|
5
|
-
If you receive an error that module cannot be found, it might mean several different things:
|
|
6
|
-
|
|
7
|
-
1. You misspelled the path. Make sure the path is correct.
|
|
8
|
-
|
|
9
|
-
2. It's possible that you rely on `baseUrl` in your `tsconfig.json`. Vite doesn't take into account `tsconfig.json` by default, so you might need to install [`vite-tsconfig-paths`](https://npmx.dev/package/vite-tsconfig-paths) yourself, if you rely on this behavior.
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { defineConfig } from 'vitest/config'
|
|
13
|
-
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
14
|
-
|
|
15
|
-
export default defineConfig({
|
|
16
|
-
plugins: [tsconfigPaths()]
|
|
17
|
-
})
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Or rewrite your path to not be relative to root:
|
|
21
|
-
|
|
22
|
-
```diff
|
|
23
|
-
- import helpers from 'src/helpers'
|
|
24
|
-
+ import helpers from '../src/helpers'
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
3. Make sure you don't have relative [aliases](/config/alias). Vite treats them as relative to the file where the import is instead of the root.
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
import { defineConfig } from 'vitest/config'
|
|
31
|
-
|
|
32
|
-
export default defineConfig({
|
|
33
|
-
test: {
|
|
34
|
-
alias: {
|
|
35
|
-
'@/': './src/', // [!code --]
|
|
36
|
-
'@/': new URL('./src/', import.meta.url).pathname, // [!code ++]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Failed to Terminate Worker
|
|
43
|
-
|
|
44
|
-
This error can happen when NodeJS's `fetch` is used with [`pool: 'threads'`](/config/pool#threads). See [#3077](https://github.com/vitest-dev/vitest/issues/3077) for details.
|
|
45
|
-
|
|
46
|
-
The default [`pool: 'forks'`](/config/pool#forks) does not have this issue. If you've explicitly set `pool: 'threads'`, switching back to `'forks'` or using [`'vmForks'`](/config/pool#vmforks) will resolve it.
|
|
47
|
-
|
|
48
|
-
## Custom package conditions are not resolved
|
|
49
|
-
|
|
50
|
-
If you are using custom conditions in your `package.json` [exports](https://nodejs.org/api/packages.html#package-entry-points) or [subpath imports](https://nodejs.org/api/packages.html#subpath-imports), you may find that Vitest does not respect these conditions by default.
|
|
51
|
-
|
|
52
|
-
For example, if you have the following in your `package.json`:
|
|
53
|
-
|
|
54
|
-
```json
|
|
55
|
-
{
|
|
56
|
-
"exports": {
|
|
57
|
-
".": {
|
|
58
|
-
"custom": "./lib/custom.js",
|
|
59
|
-
"import": "./lib/index.js"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"imports": {
|
|
63
|
-
"#internal": {
|
|
64
|
-
"custom": "./src/internal.js",
|
|
65
|
-
"default": "./lib/internal.js"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
By default, Vitest will only use the `import` and `default` conditions. To make Vitest respect custom conditions, you need to configure [`ssr.resolve.conditions`](https://vite.dev/config/ssr-options#ssr-resolve-conditions) in your Vitest config:
|
|
72
|
-
|
|
73
|
-
```ts [vitest.config.js]
|
|
74
|
-
import { defineConfig } from 'vitest/config'
|
|
75
|
-
|
|
76
|
-
export default defineConfig({
|
|
77
|
-
ssr: {
|
|
78
|
-
resolve: {
|
|
79
|
-
conditions: ['custom', 'import', 'default'],
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
})
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
::: tip Why `ssr.resolve.conditions` and not `resolve.conditions`?
|
|
86
|
-
Vitest follows Vite's configuration convention:
|
|
87
|
-
- [`resolve.conditions`](https://vite.dev/config/shared-options#resolve-conditions) applies to Vite's `client` environment, which corresponds to Vitest's browser mode, jsdom, happy-dom, or custom environments with `viteEnvironment: 'client'`.
|
|
88
|
-
- [`ssr.resolve.conditions`](https://vite.dev/config/ssr-options#ssr-resolve-conditions) applies to Vite's `ssr` environment, which corresponds to Vitest's node environment or custom environments with `viteEnvironment: 'ssr'`.
|
|
89
|
-
|
|
90
|
-
Since Vitest defaults to the `node` environment (which uses `viteEnvironment: 'ssr'`), module resolution uses `ssr.resolve.conditions`. This applies to both package exports and subpath imports.
|
|
91
|
-
|
|
92
|
-
You can learn more about Vite environments and Vitest environments in [`environment`](/config/environment).
|
|
93
|
-
:::
|
|
94
|
-
|
|
95
|
-
## Segfaults and Native Code Errors
|
|
96
|
-
|
|
97
|
-
Running [native NodeJS modules](https://nodejs.org/api/addons.html) in `pool: 'threads'` can run into cryptic errors coming from the native code.
|
|
98
|
-
|
|
99
|
-
- `Segmentation fault (core dumped)`
|
|
100
|
-
- `thread '<unnamed>' panicked at 'assertion failed`
|
|
101
|
-
- `Abort trap: 6`
|
|
102
|
-
- `internal error: entered unreachable code`
|
|
103
|
-
|
|
104
|
-
In these cases the native module is likely not built to be multi-thread safe. As a workaround, you can switch to `pool: 'forks'` which runs the test cases in multiple `node:child_process` instead of multiple `node:worker_threads`.
|
|
105
|
-
|
|
106
|
-
::: code-group
|
|
107
|
-
```ts [vitest.config.js]
|
|
108
|
-
import { defineConfig } from 'vitest/config'
|
|
109
|
-
|
|
110
|
-
export default defineConfig({
|
|
111
|
-
test: {
|
|
112
|
-
pool: 'forks',
|
|
113
|
-
},
|
|
114
|
-
})
|
|
115
|
-
```
|
|
116
|
-
```bash [CLI]
|
|
117
|
-
vitest --pool=forks
|
|
118
|
-
```
|
|
119
|
-
:::
|
|
120
|
-
|
|
121
|
-
## Unhandled Promise Rejection
|
|
122
|
-
|
|
123
|
-
This error happens when a Promise rejects but no `.catch()` handler or `await` is attached to it before the microtask queue flushes. This behavior comes from JavaScript itself and is not specific to Vitest. Learn more in the [Node.js documentation](https://nodejs.org/api/process.html#event-unhandledrejection).
|
|
124
|
-
|
|
125
|
-
A common cause is calling an async function without `await`ing it:
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
async function fetchUser(id) {
|
|
129
|
-
const res = await fetch(`/api/users/${id}`)
|
|
130
|
-
if (!res.ok) {
|
|
131
|
-
throw new Error(`User ${id} not found`) // [!code highlight]
|
|
132
|
-
}
|
|
133
|
-
return res.json()
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
test('fetches user', async () => {
|
|
137
|
-
fetchUser(123) // [!code error]
|
|
138
|
-
})
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
Because `fetchUser()` is not `await`ed, its rejection has no handler and Vitest reports:
|
|
142
|
-
|
|
143
|
-
```
|
|
144
|
-
Unhandled Rejection: Error: User 123 not found
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Fix
|
|
148
|
-
|
|
149
|
-
`await` the promise so Vitest can catch the error:
|
|
150
|
-
|
|
151
|
-
```ts
|
|
152
|
-
test('fetches user', async () => {
|
|
153
|
-
await fetchUser(123) // [!code ++]
|
|
154
|
-
})
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
If you expect the call to throw, use [`expect().rejects`](/api/expect#rejects):
|
|
158
|
-
|
|
159
|
-
```ts
|
|
160
|
-
test('rejects for missing user', async () => {
|
|
161
|
-
await expect(fetchUser(123)).rejects.toThrow('User 123 not found')
|
|
162
|
-
})
|
|
163
|
-
```
|