@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.
Files changed (209) hide show
  1. package/README.md +1 -2
  2. package/index.d.ts +3 -2
  3. package/index.js +1 -1
  4. package/package.json +1 -1
  5. package/server.js +2 -4
  6. package/tools/run-tests.js +17 -3
  7. package/patterns/_meta.json +0 -67
  8. package/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
  9. package/patterns/known-issues-and-caveats.md +0 -52
  10. package/patterns/operating-vitest-agent-as-an-agent.md +0 -62
  11. package/patterns/running-tests-via-mcp.md +0 -103
  12. package/patterns/silencing-leaking-output-in-tests.md +0 -91
  13. package/patterns/testing-effect-schema-definitions.md +0 -71
  14. package/patterns/testing-effect-services-with-mock-layers.md +0 -63
  15. package/resources/index.js +0 -166
  16. package/resources/indexes.js +0 -77
  17. package/resources/manifest-schema.js +0 -46
  18. package/resources/paths.js +0 -20
  19. package/resources/patterns.js +0 -22
  20. package/resources/upstream-docs.js +0 -22
  21. package/vendor/vitest-docs/ATTRIBUTION.md +0 -5
  22. package/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
  23. package/vendor/vitest-docs/api/advanced/metadata.md +0 -68
  24. package/vendor/vitest-docs/api/advanced/plugin.md +0 -168
  25. package/vendor/vitest-docs/api/advanced/reporters.md +0 -342
  26. package/vendor/vitest-docs/api/advanced/runner.md +0 -334
  27. package/vendor/vitest-docs/api/advanced/test-case.md +0 -302
  28. package/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
  29. package/vendor/vitest-docs/api/advanced/test-module.md +0 -140
  30. package/vendor/vitest-docs/api/advanced/test-project.md +0 -321
  31. package/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
  32. package/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
  33. package/vendor/vitest-docs/api/advanced/vitest.md +0 -684
  34. package/vendor/vitest-docs/api/assert-type.md +0 -22
  35. package/vendor/vitest-docs/api/assert.md +0 -1960
  36. package/vendor/vitest-docs/api/browser/assertions.md +0 -1277
  37. package/vendor/vitest-docs/api/browser/commands.md +0 -154
  38. package/vendor/vitest-docs/api/browser/context.md +0 -338
  39. package/vendor/vitest-docs/api/browser/interactivity.md +0 -681
  40. package/vendor/vitest-docs/api/browser/locators.md +0 -1171
  41. package/vendor/vitest-docs/api/browser/react.md +0 -346
  42. package/vendor/vitest-docs/api/browser/svelte.md +0 -292
  43. package/vendor/vitest-docs/api/browser/vue.md +0 -222
  44. package/vendor/vitest-docs/api/describe.md +0 -374
  45. package/vendor/vitest-docs/api/expect-typeof.md +0 -571
  46. package/vendor/vitest-docs/api/expect.md +0 -2304
  47. package/vendor/vitest-docs/api/hooks.md +0 -463
  48. package/vendor/vitest-docs/api/mock.md +0 -701
  49. package/vendor/vitest-docs/api/test.md +0 -926
  50. package/vendor/vitest-docs/api/vi.md +0 -1372
  51. package/vendor/vitest-docs/config/alias.md +0 -13
  52. package/vendor/vitest-docs/config/allowonly.md +0 -32
  53. package/vendor/vitest-docs/config/api.md +0 -27
  54. package/vendor/vitest-docs/config/attachmentsdir.md +0 -6
  55. package/vendor/vitest-docs/config/bail.md +0 -9
  56. package/vendor/vitest-docs/config/benchmark.md +0 -65
  57. package/vendor/vitest-docs/config/browser/api.md +0 -23
  58. package/vendor/vitest-docs/config/browser/commands.md +0 -6
  59. package/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
  60. package/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
  61. package/vendor/vitest-docs/config/browser/enabled.md +0 -40
  62. package/vendor/vitest-docs/config/browser/expect.md +0 -250
  63. package/vendor/vitest-docs/config/browser/headless.md +0 -7
  64. package/vendor/vitest-docs/config/browser/instances.md +0 -47
  65. package/vendor/vitest-docs/config/browser/isolate.md +0 -11
  66. package/vendor/vitest-docs/config/browser/locators.md +0 -24
  67. package/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
  68. package/vendor/vitest-docs/config/browser/playwright.md +0 -214
  69. package/vendor/vitest-docs/config/browser/preview.md +0 -32
  70. package/vendor/vitest-docs/config/browser/provider.md +0 -79
  71. package/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
  72. package/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
  73. package/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
  74. package/vendor/vitest-docs/config/browser/trace.md +0 -43
  75. package/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
  76. package/vendor/vitest-docs/config/browser/ui.md +0 -7
  77. package/vendor/vitest-docs/config/browser/viewport.md +0 -6
  78. package/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
  79. package/vendor/vitest-docs/config/cache.md +0 -26
  80. package/vendor/vitest-docs/config/chaiconfig.md +0 -29
  81. package/vendor/vitest-docs/config/clearmocks.md +0 -22
  82. package/vendor/vitest-docs/config/coverage.md +0 -455
  83. package/vendor/vitest-docs/config/css.md +0 -47
  84. package/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
  85. package/vendor/vitest-docs/config/deps.md +0 -127
  86. package/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
  87. package/vendor/vitest-docs/config/diff.md +0 -96
  88. package/vendor/vitest-docs/config/dir.md +0 -7
  89. package/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
  90. package/vendor/vitest-docs/config/env.md +0 -5
  91. package/vendor/vitest-docs/config/environment.md +0 -96
  92. package/vendor/vitest-docs/config/environmentoptions.md +0 -30
  93. package/vendor/vitest-docs/config/exclude.md +0 -49
  94. package/vendor/vitest-docs/config/execargv.md +0 -10
  95. package/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
  96. package/vendor/vitest-docs/config/expect.md +0 -38
  97. package/vendor/vitest-docs/config/experimental.md +0 -510
  98. package/vendor/vitest-docs/config/faketimers.md +0 -51
  99. package/vendor/vitest-docs/config/fileparallelism.md +0 -11
  100. package/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
  101. package/vendor/vitest-docs/config/globals.md +0 -42
  102. package/vendor/vitest-docs/config/globalsetup.md +0 -72
  103. package/vendor/vitest-docs/config/hideskippedtests.md +0 -7
  104. package/vendor/vitest-docs/config/hooktimeout.md +0 -7
  105. package/vendor/vitest-docs/config/include-source.md +0 -115
  106. package/vendor/vitest-docs/config/include.md +0 -71
  107. package/vendor/vitest-docs/config/includetasklocation.md +0 -17
  108. package/vendor/vitest-docs/config/index.md +0 -85
  109. package/vendor/vitest-docs/config/isolate.md +0 -13
  110. package/vendor/vitest-docs/config/logheapusage.md +0 -7
  111. package/vendor/vitest-docs/config/maxconcurrency.md +0 -9
  112. package/vendor/vitest-docs/config/maxworkers.md +0 -49
  113. package/vendor/vitest-docs/config/mockreset.md +0 -22
  114. package/vendor/vitest-docs/config/mode.md +0 -7
  115. package/vendor/vitest-docs/config/name.md +0 -111
  116. package/vendor/vitest-docs/config/onconsolelog.md +0 -25
  117. package/vendor/vitest-docs/config/onstacktrace.md +0 -32
  118. package/vendor/vitest-docs/config/onunhandlederror.md +0 -35
  119. package/vendor/vitest-docs/config/open.md +0 -7
  120. package/vendor/vitest-docs/config/outputfile.md +0 -7
  121. package/vendor/vitest-docs/config/passwithnotests.md +0 -7
  122. package/vendor/vitest-docs/config/pool.md +0 -45
  123. package/vendor/vitest-docs/config/printconsoletrace.md +0 -6
  124. package/vendor/vitest-docs/config/projects.md +0 -6
  125. package/vendor/vitest-docs/config/provide.md +0 -45
  126. package/vendor/vitest-docs/config/reporters.md +0 -69
  127. package/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
  128. package/vendor/vitest-docs/config/restoremocks.md +0 -22
  129. package/vendor/vitest-docs/config/retry.md +0 -140
  130. package/vendor/vitest-docs/config/root.md +0 -6
  131. package/vendor/vitest-docs/config/runner.md +0 -6
  132. package/vendor/vitest-docs/config/sequence.md +0 -158
  133. package/vendor/vitest-docs/config/server.md +0 -68
  134. package/vendor/vitest-docs/config/setupfiles.md +0 -40
  135. package/vendor/vitest-docs/config/silent.md +0 -9
  136. package/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
  137. package/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
  138. package/vendor/vitest-docs/config/snapshotformat.md +0 -28
  139. package/vendor/vitest-docs/config/snapshotserializers.md +0 -6
  140. package/vendor/vitest-docs/config/stricttags.md +0 -30
  141. package/vendor/vitest-docs/config/tags.md +0 -141
  142. package/vendor/vitest-docs/config/teardowntimeout.md +0 -7
  143. package/vendor/vitest-docs/config/testnamepattern.md +0 -21
  144. package/vendor/vitest-docs/config/testtimeout.md +0 -7
  145. package/vendor/vitest-docs/config/typecheck.md +0 -77
  146. package/vendor/vitest-docs/config/ui.md +0 -15
  147. package/vendor/vitest-docs/config/unstubenvs.md +0 -20
  148. package/vendor/vitest-docs/config/unstubglobals.md +0 -20
  149. package/vendor/vitest-docs/config/update.md +0 -16
  150. package/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
  151. package/vendor/vitest-docs/config/watch.md +0 -11
  152. package/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
  153. package/vendor/vitest-docs/guide/advanced/index.md +0 -147
  154. package/vendor/vitest-docs/guide/advanced/pool.md +0 -148
  155. package/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
  156. package/vendor/vitest-docs/guide/advanced/tests.md +0 -125
  157. package/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
  158. package/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
  159. package/vendor/vitest-docs/guide/browser/index.md +0 -630
  160. package/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
  161. package/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
  162. package/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
  163. package/vendor/vitest-docs/guide/cli-generated.md +0 -972
  164. package/vendor/vitest-docs/guide/cli.md +0 -234
  165. package/vendor/vitest-docs/guide/common-errors.md +0 -163
  166. package/vendor/vitest-docs/guide/coverage.md +0 -515
  167. package/vendor/vitest-docs/guide/debugging.md +0 -127
  168. package/vendor/vitest-docs/guide/environment.md +0 -101
  169. package/vendor/vitest-docs/guide/extending-matchers.md +0 -160
  170. package/vendor/vitest-docs/guide/features.md +0 -310
  171. package/vendor/vitest-docs/guide/filtering.md +0 -175
  172. package/vendor/vitest-docs/guide/ide.md +0 -43
  173. package/vendor/vitest-docs/guide/improving-performance.md +0 -245
  174. package/vendor/vitest-docs/guide/in-source.md +0 -159
  175. package/vendor/vitest-docs/guide/index.md +0 -128
  176. package/vendor/vitest-docs/guide/learn/async.md +0 -147
  177. package/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
  178. package/vendor/vitest-docs/guide/learn/matchers.md +0 -277
  179. package/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
  180. package/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
  181. package/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
  182. package/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
  183. package/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
  184. package/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
  185. package/vendor/vitest-docs/guide/lifecycle.md +0 -379
  186. package/vendor/vitest-docs/guide/migration.md +0 -863
  187. package/vendor/vitest-docs/guide/mocking/classes.md +0 -158
  188. package/vendor/vitest-docs/guide/mocking/dates.md +0 -52
  189. package/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
  190. package/vendor/vitest-docs/guide/mocking/functions.md +0 -61
  191. package/vendor/vitest-docs/guide/mocking/globals.md +0 -20
  192. package/vendor/vitest-docs/guide/mocking/modules.md +0 -414
  193. package/vendor/vitest-docs/guide/mocking/requests.md +0 -114
  194. package/vendor/vitest-docs/guide/mocking/timers.md +0 -48
  195. package/vendor/vitest-docs/guide/mocking.md +0 -239
  196. package/vendor/vitest-docs/guide/open-telemetry.md +0 -156
  197. package/vendor/vitest-docs/guide/parallelism.md +0 -82
  198. package/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
  199. package/vendor/vitest-docs/guide/projects.md +0 -291
  200. package/vendor/vitest-docs/guide/recipes.md +0 -59
  201. package/vendor/vitest-docs/guide/reporters.md +0 -723
  202. package/vendor/vitest-docs/guide/snapshot.md +0 -620
  203. package/vendor/vitest-docs/guide/test-annotations.md +0 -103
  204. package/vendor/vitest-docs/guide/test-context.md +0 -902
  205. package/vendor/vitest-docs/guide/test-tags.md +0 -314
  206. package/vendor/vitest-docs/guide/testing-types.md +0 -149
  207. package/vendor/vitest-docs/guide/ui.md +0 -160
  208. package/vendor/vitest-docs/guide/using-plugins.md +0 -5
  209. package/vendor/vitest-docs/manifest.json +0 -1691
@@ -1,510 +0,0 @@
1
- # experimental
2
-
3
- ## experimental.fsModuleCache <Version type="experimental">4.0.11</Version> {#experimental-fsmodulecache}
4
-
5
- ::: tip FEEDBACK
6
- Please leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9221).
7
- :::
8
-
9
- - **Type:** `boolean`
10
- - **Default:** `false`
11
-
12
- Enabling this option allows Vitest to keep cached modules on the file system, making tests run faster between reruns.
13
-
14
- You can delete the old cache by running [`vitest --clearCache`](/guide/cli#clearcache).
15
-
16
- ::: warning BROWSER SUPPORT
17
- At the moment, this option does not affect [the browser](/guide/browser/).
18
- :::
19
-
20
- You can debug if your modules are cached by running vitest with a `DEBUG=vitest:cache:fs` environment variable:
21
-
22
- ```shell
23
- DEBUG=vitest:cache:fs vitest --experimental.fsModuleCache
24
- ```
25
-
26
- ### Known Issues
27
-
28
- Vitest creates a persistent file hash based on file content, its id, Vite's environment configuration and coverage status. Vitest tries to use as much information as it has about the configuration, but it is still incomplete. At the moment, it is not possible to track your plugin options because there is no standard interface for it.
29
-
30
- If you have a plugin that relies on things outside the file content or the public configuration (like reading another file or a folder), it's possible that the cache will get stale. To work around that, you can define a [cache key generator](/api/advanced/plugin#definecachekeygenerator) to specify a dynamic option or to opt out of caching for that module:
31
-
32
- ```js [vitest.config.js]
33
- import { defineConfig } from 'vitest/config'
34
-
35
- export default defineConfig({
36
- plugins: [
37
- {
38
- name: 'vitest-cache',
39
- configureVitest({ experimental_defineCacheKeyGenerator }) {
40
- experimental_defineCacheKeyGenerator(({ id, sourceCode }) => {
41
- // never cache this id
42
- if (id.includes('do-not-cache')) {
43
- return false
44
- }
45
-
46
- // cache this file based on the value of a dynamic variable
47
- if (sourceCode.includes('myDynamicVar')) {
48
- return process.env.DYNAMIC_VAR_VALUE
49
- }
50
- })
51
- }
52
- }
53
- ],
54
- test: {
55
- experimental: {
56
- fsModuleCache: true,
57
- },
58
- },
59
- })
60
- ```
61
-
62
- If you are a plugin author, consider defining a [cache key generator](/api/advanced/plugin#definecachekeygenerator) in your plugin if it can be registered with different options that affect the transform result.
63
-
64
- On the other hand, if your plugin should not affect the cache key, you can opt out by setting `api.vitest.experimental.ignoreFsModuleCache` to `true`:
65
-
66
- ```js [vitest.config.js]
67
- import { defineConfig } from 'vitest/config'
68
-
69
- export default defineConfig({
70
- plugins: [
71
- {
72
- name: 'vitest-cache',
73
- api: {
74
- vitest: {
75
- experimental: {
76
- ignoreFsModuleCache: true,
77
- },
78
- },
79
- },
80
- },
81
- ],
82
- test: {
83
- experimental: {
84
- fsModuleCache: true,
85
- },
86
- },
87
- })
88
- ```
89
-
90
- Note that you can still define the cache key generator even if the plugin opts out of module caching.
91
-
92
- ## experimental.fsModuleCachePath <Version type="experimental">4.0.11</Version> {#experimental-fsmodulecachepath}
93
-
94
- - **Type:** `string`
95
- - **Default:** `'node_modules/.experimental-vitest-cache'`
96
-
97
- Directory where the file system cache is located.
98
-
99
- By default, Vitest will try to find the workspace root and store the cache inside the `node_modules` folder. The root is based on your package manager's lockfile (for example, `.package-lock.json`, `.yarn-state.yml`, `.pnpm/lock.yaml` and so on).
100
-
101
- At the moment, Vitest ignores the [test.cache.dir](/config/cache) or [cacheDir](https://vite.dev/config/shared-options#cachedir) options completely and creates a separate folder.
102
-
103
- ## experimental.openTelemetry <Version type="experimental">4.0.11</Version> {#experimental-opentelemetry}
104
-
105
- ::: tip FEEDBACK
106
- Please leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9222).
107
- :::
108
-
109
- - **Type:**
110
-
111
- ```ts
112
- interface OpenTelemetryOptions {
113
- enabled: boolean
114
- /**
115
- * A path to a file that exposes an OpenTelemetry SDK for Node.js.
116
- */
117
- sdkPath?: string
118
- /**
119
- * A path to a file that exposes an OpenTelemetry SDK for the browser.
120
- */
121
- browserSdkPath?: string
122
- }
123
- ```
124
-
125
- - **Default:** `{ enabled: false }`
126
-
127
- This option controls [OpenTelemetry](https://opentelemetry.io/) support. Vitest imports the SDK file in the main thread and before every test file, if `enabled` is set to `true`.
128
-
129
- ::: danger PERFORMANCE CONCERNS
130
- OpenTelemetry may significantly impact Vitest performance; enable it only for local debugging.
131
- :::
132
-
133
- You can use a [custom service](/guide/open-telemetry) together with Vitest to pinpoint which tests or files are slowing down your test suite.
134
-
135
- For browser mode, see the [Browser Mode](/guide/open-telemetry#browser-mode) section of the OpenTelemetry guide.
136
-
137
- An `sdkPath` is resolved relative to the [`root`](/config/root) of the project and should point to a module that exposes a started SDK instance as a default export. For example:
138
-
139
- ::: code-group
140
- ```js [otel.js]
141
- import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
142
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
143
- import { NodeSDK } from '@opentelemetry/sdk-node'
144
-
145
- const sdk = new NodeSDK({
146
- serviceName: 'vitest',
147
- traceExporter: new OTLPTraceExporter(),
148
- instrumentations: [getNodeAutoInstrumentations()],
149
- })
150
-
151
- sdk.start()
152
- export default sdk
153
- ```
154
- ```js [vitest.config.js]
155
- import { defineConfig } from 'vitest/config'
156
-
157
- export default defineConfig({
158
- test: {
159
- experimental: {
160
- openTelemetry: {
161
- enabled: true,
162
- sdkPath: './otel.js',
163
- },
164
- },
165
- },
166
- })
167
- ```
168
- :::
169
-
170
- ::: warning
171
- It's important that Node can process `sdkPath` content because it is not transformed by Vitest. See [the guide](/guide/open-telemetry) on how to work with OpenTelemetry inside of Vitest.
172
- :::
173
-
174
- ## experimental.importDurations <Version type="experimental">4.1.0</Version> {#experimental-importdurations}
175
-
176
- ::: tip FEEDBACK
177
- Please leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9224).
178
- :::
179
-
180
- - **Type:**
181
-
182
- ```ts
183
- interface ImportDurationsOptions {
184
- /**
185
- * When to print import breakdown to CLI terminal.
186
- * - false: Never print (default)
187
- * - true: Always print
188
- * - 'on-warn': Print only when any import exceeds warn threshold
189
- */
190
- print?: boolean | 'on-warn'
191
- /**
192
- * Fail the test run if any import exceeds the danger threshold.
193
- * When enabled and threshold exceeded, breakdown is always printed.
194
- * @default false
195
- */
196
- failOnDanger?: boolean
197
- /**
198
- * Maximum number of imports to collect and display.
199
- */
200
- limit?: number
201
- /**
202
- * Duration thresholds in milliseconds for coloring and warnings.
203
- */
204
- thresholds?: {
205
- /** Threshold for yellow/warning color. @default 100 */
206
- warn?: number
207
- /** Threshold for red/danger color and failOnDanger. @default 500 */
208
- danger?: number
209
- }
210
- }
211
- ```
212
-
213
- - **Default:** `{ print: false, failOnDanger: false, limit: 0, thresholds: { warn: 100, danger: 500 } }` (`limit` is 10 if `print` or UI is enabled)
214
-
215
- Configure import duration collection and display.
216
-
217
- The `print` option controls CLI terminal output. The `limit` option controls how many imports to collect and display. [Vitest UI](/guide/ui#import-breakdown) can always toggle the breakdown display regardless of the `print` setting.
218
-
219
- - Self: the time it took to import the module, excluding static imports;
220
- - Total: the time it took to import the module, including static imports. Note that this does not include `transform` time of the current module.
221
-
222
- <img alt="An example of import breakdown in the terminal" src="/reporter-import-breakdown.png" img-dark />
223
- <img alt="An example of import breakdown in the terminal" src="/reporter-import-breakdown-light.png" img-light />
224
-
225
- Note that if the file path is too long, Vitest will truncate it at the start until it fits 45 character limit.
226
-
227
- ### experimental.importDurations.print {#experimental-importdurationsprint}
228
-
229
- - **Type:** `boolean | 'on-warn'`
230
- - **Default:** `false`
231
-
232
- Controls when to print import breakdown to CLI terminal after tests finish. This only works with [`default`](/guide/reporters#default), [`verbose`](/guide/reporters#verbose), or [`tree`](/guide/reporters#tree) reporters.
233
-
234
- - `false`: Never print breakdown
235
- - `true`: Always print breakdown
236
- - `'on-warn'`: Print only when any import exceeds the `thresholds.warn` value
237
-
238
- ### experimental.importDurations.failOnDanger {#experimental-importdurationsfailondanger}
239
-
240
- - **Type:** `boolean`
241
- - **Default:** `false`
242
-
243
- Fail the test run if any import exceeds the `thresholds.danger` value. When enabled and the threshold is exceeded, the breakdown is always printed regardless of the `print` setting.
244
-
245
- This is useful for enforcing import performance budgets in CI:
246
-
247
- ```bash
248
- vitest --experimental.importDurations.failOnDanger
249
- ```
250
-
251
- ### experimental.importDurations.limit {#experimental-importdurationslimit}
252
-
253
- - **Type:** `number`
254
- - **Default:** `0` (or `10` if `print`, `failOnDanger`, or UI is enabled)
255
-
256
- Maximum number of imports to collect and display in CLI output, [Vitest UI](/guide/ui#import-breakdown), and third-party reporters.
257
-
258
- ### experimental.importDurations.thresholds {#experimental-importdurationsthresholds}
259
-
260
- - **Type:** `{ warn?: number; danger?: number }`
261
- - **Default:** `{ warn: 100, danger: 500 }`
262
-
263
- Duration thresholds in milliseconds for coloring and warnings:
264
-
265
- - `warn`: Threshold for yellow/warning color (default: 100ms)
266
- - `danger`: Threshold for red/danger color and `failOnDanger` (default: 500ms)
267
-
268
- ::: info
269
- [Vitest UI](/guide/ui#import-breakdown) shows a breakdown of imports automatically if at least one file took longer than the `danger` threshold to load.
270
- :::
271
-
272
- ## experimental.viteModuleRunner <Version type="experimental">4.1.0</Version> {#experimental-vitemodulerunner}
273
-
274
- ::: tip FEEDBACK
275
- Please leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9501).
276
- :::
277
-
278
- - **Type:** `boolean`
279
- - **Default:** `true`
280
-
281
- Controls whether Vitest uses Vite's [module runner](https://vite.dev/guide/api-environment-runtimes#modulerunner) to run the code or fallback to the native `import`.
282
-
283
- If this option is defined in the root config, all [projects](/guide/projects) will inherit it automatically.
284
-
285
- Consider disabling the module runner if you are running tests in the same environment as your code (server backend or simple scripts, for example). However, we still recommend running `jsdom`/`happy-dom` tests with Vite's module runner or in [the browser](/guide/browser/) since it doesn't require any additional configuration.
286
-
287
- Disabling this flag will disable _all_ file transforms:
288
-
289
- - test files and your source code are not processed by Vite
290
- - your global setup files are not processed
291
- - your custom runner/pool/environment files are not processed
292
- - your config file is still processed by Vite (this happens before Vitest knows the `viteModuleRunner` flag)
293
-
294
- ::: warning
295
- At the moment, Vitest still requires Vite for certain functionality like the module graph or watch mode.
296
-
297
- Also note that this option only works with `forks` or `threads` [pools](/config/pool).
298
- :::
299
-
300
- ### Module Runner
301
-
302
- By default, Vitest runs tests in a very permissive module runner sandbox powered by Vite's [Environment API](https://vite.dev/guide/api-environment.html#environment-api). Every file is categorized as either an "inline" module or an "external" module.
303
-
304
- Module runner runs all "inlined" modules. It provides `import.meta.env`, `require`, `__dirname`, `__filename`, static `import`, and has its own module resolution mechanism. This makes it very easy to run code when you don't want to configure the environment and just need to test that the bare JavaScript logic you wrote works as intended.
305
-
306
- All "external" modules run in native mode, meaning they are executed outside of the module runner sandbox. If you are running tests in Node.js, these files are imported with the native `import` keyword and processed by Node.js directly.
307
-
308
- While running JSDOM/happy-dom tests in a permissive fake environment might be justified, running Node.js tests in a non-Node.js environment can hide and silence potential errors you may encounter in production, especially if your code doesn't require any additional transformations provided by Vite plugins.
309
-
310
- ### Known Limitations
311
-
312
- Some Vitest features rely on files being transformed. Vitest uses synchronous [Node.js Loaders API](https://nodejs.org/api/module.html#customization-hooks) to transform test files and setup files to support these features:
313
-
314
- - [`import.meta.vitest`](/guide/in-source)
315
- - [`vi.mock`](/api/vi#vi-mock)
316
- - [`vi.hoisted`](/api/vi#vi-hoisted)
317
-
318
- ::: warning
319
- This means that Vitest requires at least Node 22.15 for those features to work. At the moment, they also do not work in Deno or Bun.
320
-
321
- Vitest will only detect `vi.mock` and `vi.hoisted` inside of test files, they will not be hoisted inside imported modules.
322
- :::
323
-
324
- This could affect performance because Vitest needs to read the file and process it. If you do not use these features, you can disable the transforms by setting `experimental.nodeLoader` to `false`. Vitest only reads test files and setup files while looking for `vi.mock` or `vi.hoisted`. Using these in other files won't hoist them to the top of the file and can lead to unexpected behavior.
325
-
326
- Some features will not work due to the nature of `viteModuleRunner`, including:
327
-
328
- - no `import.meta.env`: `import.meta.env` is a Vite feature, use `process.env` instead
329
- - no `plugins`: plugins are not applied because there is no transformation phase, use [customization hooks](https://nodejs.org/api/module.html#customization-hooks) via [`execArgv`](/config/execargv) instead
330
- - no `alias`: aliases are not applied because there is no transformation phase
331
- - `istanbul` coverage provider doesn't work because there is no transformation phase, use `v8` instead
332
- - `vi.resetModules()`: there is no API to invalidate ES modules from the module cache
333
-
334
- ::: warning Coverage Support
335
- At the moment Vitest supports coverage via `v8` provider as long as files can be transformed into JavaScript. To transform TypeScript, Vitest uses [`module.stripTypeScriptTypes`](https://nodejs.org/api/module.html#modulestriptypescripttypescode-options) which is available in Node.js since v22.13. If you are using a custom [module loader](https://nodejs.org/api/module.html#customization-hooks), Vitest is not able to reuse it to transform files for analysis.
336
- :::
337
-
338
- With regards to mocking, it is also important to point out that ES modules do not support property override. This means that code like this won't work anymore:
339
-
340
- ```ts
341
- import * as fs from 'node:fs'
342
- import { vi } from 'vitest'
343
-
344
- vi.spyOn(fs, 'readFileSync').mockImplementation(() => '42') // ❌
345
- ```
346
-
347
- However, Vitest supports auto-spying on modules without overriding their implementation. When `vi.mock` is called with a `spy: true` argument, the module is mocked in a way that preserves original implementations, but all exported functions are wrapped in a `vi.fn()` spy:
348
-
349
- ```ts
350
- import * as fs from 'node:fs'
351
- import { vi } from 'vitest'
352
-
353
- vi.mock('node:fs', { spy: true })
354
-
355
- fs.readFileSync.mockImplementation(() => '42') // ✅
356
- ```
357
-
358
- Factory mocking is implemented using a top-level await. This means that mocked modules cannot be loaded with `require()` in your source code:
359
-
360
- ```ts
361
- vi.mock('node:fs', async (importOriginal) => {
362
- return {
363
- ...await importOriginal(),
364
- readFileSync: vi.fn(),
365
- }
366
- })
367
-
368
- const fs = require('node:fs') // throws an error
369
- ```
370
-
371
- This limitation exists because factories can be asynchronous. This should not be a problem because Vitest doesn't mock builtin modules inside `node_modules`, which is similar to how Vitest works by default.
372
-
373
- ### TypeScript
374
-
375
- If you are using Node.js 22.18/23.6 or higher, TypeScript will be [transformed natively](https://nodejs.org/en/learn/typescript/run-natively) by Node.js.
376
-
377
- ::: warning TypeScript with Node.js 22.6-22.18
378
- If you are using Node.js version between 22.6 and 22.18, you can also enable native TypeScript support via `--experimental-strip-types` flag:
379
-
380
- ```shell
381
- NODE_OPTIONS="--experimental-strip-types" vitest
382
- ```
383
-
384
- If you are using TypeScript and Node.js version lower than 22.6, then you will need to either:
385
-
386
- - build your test files and source code and run those files directly
387
- - import a [custom loader](https://nodejs.org/api/module.html#customization-hooks) via `execArgv` flag
388
-
389
- ```ts
390
- import { defineConfig } from 'vitest/config'
391
-
392
- const tsxApi = import.meta.resolve('tsx/esm/api')
393
-
394
- export default defineConfig({
395
- test: {
396
- execArgv: [
397
- `--import=data:text/javascript,import * as tsx from "${tsxApi}";tsx.register()`,
398
- ],
399
- experimental: {
400
- viteModuleRunner: false,
401
- },
402
- },
403
- })
404
- ```
405
-
406
- If you are running tests in Deno, TypeScript files are processed by the runtime without any additional configurations.
407
- :::
408
-
409
- ## experimental.vcsProvider <Version type="experimental">4.1.1</Version> {#experimental-vcsprovider}
410
-
411
- - **Type:** `VCSProvider | string`
412
-
413
- ```ts
414
- interface VCSProvider {
415
- findChangedFiles(options: VCSProviderOptions): Promise<string[]>
416
- }
417
-
418
- interface VCSProviderOptions {
419
- root: string
420
- changedSince?: string | boolean
421
- }
422
- ```
423
-
424
- - **Default:** `'git'`
425
-
426
- Custom provider for detecting changed files. Used with the [`--changed`](/guide/cli#changed) flag to determine which files have been modified.
427
-
428
- By default, Vitest uses Git to detect changed files. You can provide a custom implementation of the `VCSProvider` interface to use a different version control system:
429
-
430
- ```ts [vitest.config.ts]
431
- import { defineConfig } from 'vitest/config'
432
-
433
- export default defineConfig({
434
- test: {
435
- experimental: {
436
- vcsProvider: {
437
- async findChangedFiles({ root, changedSince }) {
438
- // return paths of changed files
439
- return []
440
- },
441
- },
442
- },
443
- },
444
- })
445
- ```
446
-
447
- You can also pass a string path to a module with a default export that implements the `VCSProvider` interface:
448
-
449
- ```js [vitest.config.js]
450
- import { defineConfig } from 'vitest/config'
451
-
452
- export default defineConfig({
453
- test: {
454
- experimental: {
455
- vcsProvider: './my-vcs-provider.js',
456
- },
457
- },
458
- })
459
- ```
460
-
461
- ```js [my-vcs-provider.js]
462
- export default {
463
- async findChangedFiles({ root, changedSince }) {
464
- // return paths of changed files
465
- return []
466
- },
467
- }
468
- ```
469
-
470
- ## experimental.nodeLoader <Version type="experimental">4.1.0</Version> {#experimental-nodeloader}
471
-
472
- - **Type:** `boolean`
473
- - **Default:** `true`
474
-
475
- If module runner is disabled, Vitest uses a native [Node.js module loader](https://nodejs.org/api/module.html#customization-hooks) to transform files to support `import.meta.vitest`, `vi.mock` and `vi.hoisted`.
476
-
477
- If you don't use these features, you can disable this to improve performance.
478
-
479
- ## experimental.preParse <Version type="experimental">4.1.3</Version> {#experimental-preparse}
480
-
481
- - **Type:** `boolean`
482
- - **Default:** `false`
483
-
484
- Parses test specifications before running them. This applies the [`.only`](/api/test#test-only) modifier, the [`-t`](/config/testnamepattern) test name pattern, [`--tags-filter`](/guide/test-tags#syntax), [test lines](/api/advanced/test-specification#testlines), and [test IDs](/api/advanced/test-specification#testids) across all files without executing them. For example, if only a single test is marked with `.only`, Vitest will skip all other tests in all files.
485
-
486
- ::: tip
487
- This option is recommended when using [`.only`](/api/test#test-only), the [`-t`](/config/testnamepattern) flag, or [`--tags-filter`](/guide/test-tags#syntax).
488
-
489
- Enabling it unconditionally may slow down your test runs due to the additional parsing step.
490
- :::
491
-
492
- ::: warning
493
- Pre-parsing uses static analysis (AST parsing) instead of executing your test files. This means that test names, tags, and modifiers (`.only`, `.skip`, `.todo`) must be statically analyzable. Dynamic test names (e.g., names stored in variables or returned from function calls) and non-literal tags will not be resolved correctly.
494
-
495
- ```ts
496
- // ✅ works — static string literal
497
- test('adds numbers', () => {})
498
-
499
- // ✅ works — static tags
500
- test('my test', { tags: ['unit'] }, () => {})
501
-
502
- // ❌ won't match correctly — dynamic name
503
- const name = getName()
504
- test(name, () => {})
505
-
506
- // ❌ won't match correctly — dynamic tags
507
- const tags = getTags()
508
- test('my test', { tags }, () => {})
509
- ```
510
- :::
@@ -1,51 +0,0 @@
1
- # fakeTimers
2
-
3
- - **Type:** `FakeTimerInstallOpts`
4
-
5
- Options that Vitest will pass down to [`@sinon/fake-timers`](https://npmx.dev/package/@sinonjs/fake-timers) when using [`vi.useFakeTimers()`](/api/vi#vi-usefaketimers).
6
-
7
- ## fakeTimers.now
8
-
9
- - **Type:** `number | Date`
10
- - **Default:** `Date.now()`
11
-
12
- Installs fake timers with the specified Unix epoch.
13
-
14
- ## fakeTimers.toFake
15
-
16
- - **Type:** `('setTimeout' | 'clearTimeout' | 'setImmediate' | 'clearImmediate' | 'setInterval' | 'clearInterval' | 'Date' | 'nextTick' | 'hrtime' | 'requestAnimationFrame' | 'cancelAnimationFrame' | 'requestIdleCallback' | 'cancelIdleCallback' | 'performance' | 'queueMicrotask')[]`
17
- - **Default:** everything available globally except `nextTick` and `queueMicrotask`
18
-
19
- An array with names of global methods and APIs to fake.
20
-
21
- To only mock `setTimeout()` and `nextTick()`, specify this property as `['setTimeout', 'nextTick']`.
22
-
23
- Mocking `nextTick` is not supported when running Vitest inside `node:child_process` by using `--pool=forks`. NodeJS uses `process.nextTick` internally in `node:child_process` and hangs when it is mocked. Mocking `nextTick` is supported when running Vitest with `--pool=threads`.
24
-
25
- ## fakeTimers.loopLimit
26
-
27
- - **Type:** `number`
28
- - **Default:** `10_000`
29
-
30
- The maximum number of timers that will be run when calling [`vi.runAllTimers()`](/api/vi#vi-runalltimers).
31
-
32
- ## fakeTimers.shouldAdvanceTime
33
-
34
- - **Type:** `boolean`
35
- - **Default:** `false`
36
-
37
- Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by 20ms for every 20ms change in the real system time).
38
-
39
- ## fakeTimers.advanceTimeDelta
40
-
41
- - **Type:** `number`
42
- - **Default:** `20`
43
-
44
- Relevant only when using with `shouldAdvanceTime: true`. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change in the real system time.
45
-
46
- ## fakeTimers.shouldClearNativeTimers
47
-
48
- - **Type:** `boolean`
49
- - **Default:** `true`
50
-
51
- Tells fake timers to clear "native" (i.e. not fake) timers by delegating to their respective handlers. When disabled, it can lead to potentially unexpected behavior if timers existed prior to starting fake timers session.
@@ -1,11 +0,0 @@
1
- # fileParallelism
2
-
3
- - **Type:** `boolean`
4
- - **Default:** `true`
5
- - **CLI:** `--no-file-parallelism`, `--fileParallelism=false`
6
-
7
- Should all test files run in parallel. Setting this to `false` will override `maxWorkers` option to `1`.
8
-
9
- ::: tip
10
- This option doesn't affect tests running in the same file. If you want to run those in parallel, use `concurrent` option on [describe](/api/describe#describe-concurrent) or via [a config](/config/sequence#sequence-concurrent).
11
- :::
@@ -1,19 +0,0 @@
1
- # forceRerunTriggers <CRoot />
2
-
3
- - **Type:** `string[]`
4
- - **Default:** `['**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**']`
5
-
6
- Glob pattern of file paths that will trigger the whole suite rerun. When paired with the `--changed` argument will run the whole test suite if the trigger is found in the git diff.
7
-
8
- Useful if you are testing calling CLI commands, because Vite cannot construct a module graph:
9
-
10
- ```ts
11
- test('execute a script', async () => {
12
- // Vitest cannot rerun this test, if content of `dist/index.js` changes
13
- await execa('node', ['dist/index.js'])
14
- })
15
- ```
16
-
17
- ::: tip
18
- Make sure that your files are not excluded by [`server.watch.ignored`](https://vitejs.dev/config/server-options.html#server-watch).
19
- :::
@@ -1,42 +0,0 @@
1
- # globals
2
-
3
- - **Type:** `boolean`
4
- - **Default:** `false`
5
- - **CLI:** `--globals`, `--no-globals`, `--globals=false`
6
-
7
- By default, `vitest` does not provide global APIs for explicitness. If you prefer to use the APIs globally like Jest, you can pass the `--globals` option to CLI or add `globals: true` in the config.
8
-
9
- ```js
10
- import { defineConfig } from 'vitest/config'
11
-
12
- export default defineConfig({
13
- test: {
14
- globals: true,
15
- },
16
- })
17
- ```
18
-
19
- ::: tip
20
- Note that some libraries, e.g., `@testing-library/react`, rely on globals being present to perform auto cleanup.
21
- :::
22
-
23
- To get TypeScript working with the global APIs, add `vitest/globals` to the `types` field in your `tsconfig.json`:
24
-
25
- ```json [tsconfig.json]
26
- {
27
- "compilerOptions": {
28
- "types": ["vitest/globals"]
29
- }
30
- }
31
- ```
32
-
33
- If you have redefined your [`typeRoots`](https://www.typescriptlang.org/tsconfig/#typeRoots) to include additional types in your compilation, you will need to add back the `node_modules` to make `vitest/globals` discoverable:
34
-
35
- ```json [tsconfig.json]
36
- {
37
- "compilerOptions": {
38
- "typeRoots": ["./types", "./node_modules/@types", "./node_modules"],
39
- "types": ["vitest/globals"]
40
- }
41
- }
42
- ```