@vitest-agent/mcp 1.0.1 → 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.
Files changed (229) hide show
  1. package/README.md +1 -2
  2. package/bin/vitest-agent-mcp.js +1 -17
  3. package/index.d.ts +324 -315
  4. package/index.js +2 -4
  5. package/middleware/idempotency.js +1 -1
  6. package/package.json +2 -2
  7. package/server.js +2 -4
  8. package/tools/acceptance-metrics.js +1 -1
  9. package/tools/cache-health.js +1 -1
  10. package/tools/commit-changes.js +1 -1
  11. package/tools/configure.js +1 -1
  12. package/tools/coverage.js +1 -1
  13. package/tools/errors.js +1 -1
  14. package/tools/failure-signature-get.js +1 -1
  15. package/tools/file-coverage.js +1 -1
  16. package/tools/history.js +1 -1
  17. package/tools/inventory.js +1 -1
  18. package/tools/overview.js +1 -1
  19. package/tools/run-tests.js +15 -3
  20. package/tools/settings-list.js +1 -1
  21. package/tools/status.js +1 -1
  22. package/tools/tdd-artifact.js +1 -1
  23. package/tools/tdd-task.js +1 -1
  24. package/tools/test.js +1 -1
  25. package/tools/trends.js +1 -1
  26. package/tools/turn-search.js +1 -1
  27. package/public/patterns/_meta.json +0 -67
  28. package/public/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
  29. package/public/patterns/known-issues-and-caveats.md +0 -52
  30. package/public/patterns/operating-vitest-agent-as-an-agent.md +0 -53
  31. package/public/patterns/running-tests-via-mcp.md +0 -58
  32. package/public/patterns/silencing-leaking-output-in-tests.md +0 -91
  33. package/public/patterns/testing-effect-schema-definitions.md +0 -71
  34. package/public/patterns/testing-effect-services-with-mock-layers.md +0 -63
  35. package/public/vendor/vitest-docs/ATTRIBUTION.md +0 -5
  36. package/public/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
  37. package/public/vendor/vitest-docs/api/advanced/metadata.md +0 -68
  38. package/public/vendor/vitest-docs/api/advanced/plugin.md +0 -168
  39. package/public/vendor/vitest-docs/api/advanced/reporters.md +0 -342
  40. package/public/vendor/vitest-docs/api/advanced/runner.md +0 -334
  41. package/public/vendor/vitest-docs/api/advanced/test-case.md +0 -302
  42. package/public/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
  43. package/public/vendor/vitest-docs/api/advanced/test-module.md +0 -140
  44. package/public/vendor/vitest-docs/api/advanced/test-project.md +0 -321
  45. package/public/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
  46. package/public/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
  47. package/public/vendor/vitest-docs/api/advanced/vitest.md +0 -684
  48. package/public/vendor/vitest-docs/api/assert-type.md +0 -22
  49. package/public/vendor/vitest-docs/api/assert.md +0 -1960
  50. package/public/vendor/vitest-docs/api/browser/assertions.md +0 -1277
  51. package/public/vendor/vitest-docs/api/browser/commands.md +0 -154
  52. package/public/vendor/vitest-docs/api/browser/context.md +0 -338
  53. package/public/vendor/vitest-docs/api/browser/interactivity.md +0 -681
  54. package/public/vendor/vitest-docs/api/browser/locators.md +0 -1171
  55. package/public/vendor/vitest-docs/api/browser/react.md +0 -346
  56. package/public/vendor/vitest-docs/api/browser/svelte.md +0 -292
  57. package/public/vendor/vitest-docs/api/browser/vue.md +0 -222
  58. package/public/vendor/vitest-docs/api/describe.md +0 -374
  59. package/public/vendor/vitest-docs/api/expect-typeof.md +0 -571
  60. package/public/vendor/vitest-docs/api/expect.md +0 -2304
  61. package/public/vendor/vitest-docs/api/hooks.md +0 -463
  62. package/public/vendor/vitest-docs/api/mock.md +0 -701
  63. package/public/vendor/vitest-docs/api/test.md +0 -926
  64. package/public/vendor/vitest-docs/api/vi.md +0 -1372
  65. package/public/vendor/vitest-docs/config/alias.md +0 -13
  66. package/public/vendor/vitest-docs/config/allowonly.md +0 -32
  67. package/public/vendor/vitest-docs/config/api.md +0 -27
  68. package/public/vendor/vitest-docs/config/attachmentsdir.md +0 -6
  69. package/public/vendor/vitest-docs/config/bail.md +0 -9
  70. package/public/vendor/vitest-docs/config/benchmark.md +0 -65
  71. package/public/vendor/vitest-docs/config/browser/api.md +0 -23
  72. package/public/vendor/vitest-docs/config/browser/commands.md +0 -6
  73. package/public/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
  74. package/public/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
  75. package/public/vendor/vitest-docs/config/browser/enabled.md +0 -40
  76. package/public/vendor/vitest-docs/config/browser/expect.md +0 -250
  77. package/public/vendor/vitest-docs/config/browser/headless.md +0 -7
  78. package/public/vendor/vitest-docs/config/browser/instances.md +0 -47
  79. package/public/vendor/vitest-docs/config/browser/isolate.md +0 -11
  80. package/public/vendor/vitest-docs/config/browser/locators.md +0 -24
  81. package/public/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
  82. package/public/vendor/vitest-docs/config/browser/playwright.md +0 -214
  83. package/public/vendor/vitest-docs/config/browser/preview.md +0 -32
  84. package/public/vendor/vitest-docs/config/browser/provider.md +0 -79
  85. package/public/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
  86. package/public/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
  87. package/public/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
  88. package/public/vendor/vitest-docs/config/browser/trace.md +0 -43
  89. package/public/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
  90. package/public/vendor/vitest-docs/config/browser/ui.md +0 -7
  91. package/public/vendor/vitest-docs/config/browser/viewport.md +0 -6
  92. package/public/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
  93. package/public/vendor/vitest-docs/config/cache.md +0 -26
  94. package/public/vendor/vitest-docs/config/chaiconfig.md +0 -29
  95. package/public/vendor/vitest-docs/config/clearmocks.md +0 -22
  96. package/public/vendor/vitest-docs/config/coverage.md +0 -455
  97. package/public/vendor/vitest-docs/config/css.md +0 -47
  98. package/public/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
  99. package/public/vendor/vitest-docs/config/deps.md +0 -127
  100. package/public/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
  101. package/public/vendor/vitest-docs/config/diff.md +0 -96
  102. package/public/vendor/vitest-docs/config/dir.md +0 -7
  103. package/public/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
  104. package/public/vendor/vitest-docs/config/env.md +0 -5
  105. package/public/vendor/vitest-docs/config/environment.md +0 -96
  106. package/public/vendor/vitest-docs/config/environmentoptions.md +0 -30
  107. package/public/vendor/vitest-docs/config/exclude.md +0 -49
  108. package/public/vendor/vitest-docs/config/execargv.md +0 -10
  109. package/public/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
  110. package/public/vendor/vitest-docs/config/expect.md +0 -38
  111. package/public/vendor/vitest-docs/config/experimental.md +0 -510
  112. package/public/vendor/vitest-docs/config/faketimers.md +0 -51
  113. package/public/vendor/vitest-docs/config/fileparallelism.md +0 -11
  114. package/public/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
  115. package/public/vendor/vitest-docs/config/globals.md +0 -42
  116. package/public/vendor/vitest-docs/config/globalsetup.md +0 -72
  117. package/public/vendor/vitest-docs/config/hideskippedtests.md +0 -7
  118. package/public/vendor/vitest-docs/config/hooktimeout.md +0 -7
  119. package/public/vendor/vitest-docs/config/include-source.md +0 -115
  120. package/public/vendor/vitest-docs/config/include.md +0 -71
  121. package/public/vendor/vitest-docs/config/includetasklocation.md +0 -17
  122. package/public/vendor/vitest-docs/config/index.md +0 -85
  123. package/public/vendor/vitest-docs/config/isolate.md +0 -13
  124. package/public/vendor/vitest-docs/config/logheapusage.md +0 -7
  125. package/public/vendor/vitest-docs/config/maxconcurrency.md +0 -9
  126. package/public/vendor/vitest-docs/config/maxworkers.md +0 -49
  127. package/public/vendor/vitest-docs/config/mockreset.md +0 -22
  128. package/public/vendor/vitest-docs/config/mode.md +0 -7
  129. package/public/vendor/vitest-docs/config/name.md +0 -111
  130. package/public/vendor/vitest-docs/config/onconsolelog.md +0 -25
  131. package/public/vendor/vitest-docs/config/onstacktrace.md +0 -32
  132. package/public/vendor/vitest-docs/config/onunhandlederror.md +0 -35
  133. package/public/vendor/vitest-docs/config/open.md +0 -7
  134. package/public/vendor/vitest-docs/config/outputfile.md +0 -7
  135. package/public/vendor/vitest-docs/config/passwithnotests.md +0 -7
  136. package/public/vendor/vitest-docs/config/pool.md +0 -45
  137. package/public/vendor/vitest-docs/config/printconsoletrace.md +0 -6
  138. package/public/vendor/vitest-docs/config/projects.md +0 -6
  139. package/public/vendor/vitest-docs/config/provide.md +0 -45
  140. package/public/vendor/vitest-docs/config/reporters.md +0 -69
  141. package/public/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
  142. package/public/vendor/vitest-docs/config/restoremocks.md +0 -22
  143. package/public/vendor/vitest-docs/config/retry.md +0 -140
  144. package/public/vendor/vitest-docs/config/root.md +0 -6
  145. package/public/vendor/vitest-docs/config/runner.md +0 -6
  146. package/public/vendor/vitest-docs/config/sequence.md +0 -158
  147. package/public/vendor/vitest-docs/config/server.md +0 -68
  148. package/public/vendor/vitest-docs/config/setupfiles.md +0 -40
  149. package/public/vendor/vitest-docs/config/silent.md +0 -9
  150. package/public/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
  151. package/public/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
  152. package/public/vendor/vitest-docs/config/snapshotformat.md +0 -28
  153. package/public/vendor/vitest-docs/config/snapshotserializers.md +0 -6
  154. package/public/vendor/vitest-docs/config/stricttags.md +0 -30
  155. package/public/vendor/vitest-docs/config/tags.md +0 -141
  156. package/public/vendor/vitest-docs/config/teardowntimeout.md +0 -7
  157. package/public/vendor/vitest-docs/config/testnamepattern.md +0 -21
  158. package/public/vendor/vitest-docs/config/testtimeout.md +0 -7
  159. package/public/vendor/vitest-docs/config/typecheck.md +0 -77
  160. package/public/vendor/vitest-docs/config/ui.md +0 -15
  161. package/public/vendor/vitest-docs/config/unstubenvs.md +0 -20
  162. package/public/vendor/vitest-docs/config/unstubglobals.md +0 -20
  163. package/public/vendor/vitest-docs/config/update.md +0 -16
  164. package/public/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
  165. package/public/vendor/vitest-docs/config/watch.md +0 -11
  166. package/public/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
  167. package/public/vendor/vitest-docs/guide/advanced/index.md +0 -147
  168. package/public/vendor/vitest-docs/guide/advanced/pool.md +0 -148
  169. package/public/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
  170. package/public/vendor/vitest-docs/guide/advanced/tests.md +0 -125
  171. package/public/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
  172. package/public/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
  173. package/public/vendor/vitest-docs/guide/browser/index.md +0 -630
  174. package/public/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
  175. package/public/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
  176. package/public/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
  177. package/public/vendor/vitest-docs/guide/cli-generated.md +0 -972
  178. package/public/vendor/vitest-docs/guide/cli.md +0 -234
  179. package/public/vendor/vitest-docs/guide/common-errors.md +0 -163
  180. package/public/vendor/vitest-docs/guide/coverage.md +0 -515
  181. package/public/vendor/vitest-docs/guide/debugging.md +0 -127
  182. package/public/vendor/vitest-docs/guide/environment.md +0 -101
  183. package/public/vendor/vitest-docs/guide/extending-matchers.md +0 -160
  184. package/public/vendor/vitest-docs/guide/features.md +0 -310
  185. package/public/vendor/vitest-docs/guide/filtering.md +0 -175
  186. package/public/vendor/vitest-docs/guide/ide.md +0 -43
  187. package/public/vendor/vitest-docs/guide/improving-performance.md +0 -245
  188. package/public/vendor/vitest-docs/guide/in-source.md +0 -159
  189. package/public/vendor/vitest-docs/guide/index.md +0 -128
  190. package/public/vendor/vitest-docs/guide/learn/async.md +0 -147
  191. package/public/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
  192. package/public/vendor/vitest-docs/guide/learn/matchers.md +0 -277
  193. package/public/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
  194. package/public/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
  195. package/public/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
  196. package/public/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
  197. package/public/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
  198. package/public/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
  199. package/public/vendor/vitest-docs/guide/lifecycle.md +0 -379
  200. package/public/vendor/vitest-docs/guide/migration.md +0 -863
  201. package/public/vendor/vitest-docs/guide/mocking/classes.md +0 -158
  202. package/public/vendor/vitest-docs/guide/mocking/dates.md +0 -52
  203. package/public/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
  204. package/public/vendor/vitest-docs/guide/mocking/functions.md +0 -61
  205. package/public/vendor/vitest-docs/guide/mocking/globals.md +0 -20
  206. package/public/vendor/vitest-docs/guide/mocking/modules.md +0 -414
  207. package/public/vendor/vitest-docs/guide/mocking/requests.md +0 -114
  208. package/public/vendor/vitest-docs/guide/mocking/timers.md +0 -48
  209. package/public/vendor/vitest-docs/guide/mocking.md +0 -239
  210. package/public/vendor/vitest-docs/guide/open-telemetry.md +0 -156
  211. package/public/vendor/vitest-docs/guide/parallelism.md +0 -82
  212. package/public/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
  213. package/public/vendor/vitest-docs/guide/projects.md +0 -291
  214. package/public/vendor/vitest-docs/guide/recipes.md +0 -59
  215. package/public/vendor/vitest-docs/guide/reporters.md +0 -723
  216. package/public/vendor/vitest-docs/guide/snapshot.md +0 -620
  217. package/public/vendor/vitest-docs/guide/test-annotations.md +0 -103
  218. package/public/vendor/vitest-docs/guide/test-context.md +0 -902
  219. package/public/vendor/vitest-docs/guide/test-tags.md +0 -314
  220. package/public/vendor/vitest-docs/guide/testing-types.md +0 -149
  221. package/public/vendor/vitest-docs/guide/ui.md +0 -160
  222. package/public/vendor/vitest-docs/guide/using-plugins.md +0 -5
  223. package/public/vendor/vitest-docs/manifest.json +0 -1691
  224. package/resources/index.js +0 -166
  225. package/resources/indexes.js +0 -77
  226. package/resources/manifest-schema.js +0 -46
  227. package/resources/paths.js +0 -20
  228. package/resources/patterns.js +0 -22
  229. package/resources/upstream-docs.js +0 -22
@@ -1,314 +0,0 @@
1
- # Test Tags <Version>4.1.0</Version> {#test-tags}
2
-
3
- [`Tags`](/config/tags) let you label tests so you can filter what runs and override their options when needed.
4
-
5
- ## Defining Tags
6
-
7
- Tags must be defined in your configuration file — Vitest does not provide any built-in tags. If a test uses a tag that isn't defined in the config, the test runner will throw an error. This prevents unexpected behavior from mistyped tag names. You can disable this check with the [`strictTags`](/config/stricttags) option.
8
-
9
- You must define a `name` of the tag, and you may define additional options that will be applied to every test marked with the tag, e.g., a `timeout`, or `retry`. For the full list of available options, see [`tags`](/config/tags).
10
-
11
- ```ts [vitest.config.js]
12
- import { defineConfig } from 'vitest/config'
13
-
14
- export default defineConfig({
15
- test: {
16
- tags: [
17
- {
18
- name: 'frontend',
19
- description: 'Tests written for frontend.',
20
- },
21
- {
22
- name: 'backend',
23
- description: 'Tests written for backend.',
24
- },
25
- {
26
- name: 'db',
27
- description: 'Tests for database queries.',
28
- timeout: 60_000,
29
- },
30
- {
31
- name: 'flaky',
32
- description: 'Flaky CI tests.',
33
- retry: process.env.CI ? 3 : 0,
34
- timeout: 30_000,
35
- priority: 1,
36
- },
37
- ],
38
- },
39
- })
40
- ```
41
-
42
- ::: warning
43
- If several tags have the same options and are used on the same test, they will be resolved in the order they were specified, or sorted by priority first (the lower the number, the higher the priority). Tags without a defined priority are merged first and will be overridden by higher priority ones:
44
-
45
- ```ts
46
- test('flaky database test', { tags: ['flaky', 'db'] })
47
- // { timeout: 30_000, retry: 3 }
48
- ```
49
-
50
- Note that the `timeout` is 30 seconds (and not 60) because `flaky` tag has a priority of `1` while `db` (that defines 60 second timeout) has no priority.
51
-
52
- If test defines its own options, they will have the highest priority:
53
-
54
- ```ts
55
- test('flaky database test', { tags: ['flaky', 'db'], timeout: 120_000 })
56
- // { timeout: 120_000, retry: 3 }
57
- ```
58
- :::
59
-
60
- If you are using TypeScript, you can enforce what tags are available by augmenting the `TestTags` type with a property that contains a union of strings (make sure this file is included by your `tsconfig`):
61
-
62
- ```ts [vitest.shims.ts]
63
- import 'vitest'
64
-
65
- declare module 'vitest' {
66
- interface TestTags {
67
- tags:
68
- | 'frontend'
69
- | 'backend'
70
- | 'db'
71
- | 'flaky'
72
- }
73
- }
74
- ```
75
-
76
- To see all your tags, you can use [`--list-tags`](/guide/cli#listtags) command:
77
-
78
- ```shell
79
- vitest --list-tags
80
-
81
- frontend: Tests written for frontend.
82
- backend: Tests written for backend.
83
- db: Tests for database queries.
84
- flaky: Flaky CI tests.
85
- ```
86
-
87
- To print it in JSON, pass down `--list-tags=json`:
88
-
89
- ```json
90
- {
91
- "tags": [
92
- {
93
- "name": "frontend",
94
- "description": "Tests written for frontend."
95
- },
96
- {
97
- "name": "backend",
98
- "description": "Tests written for backend."
99
- },
100
- {
101
- "name": "db",
102
- "description": "Tests for database queries.",
103
- "timeout": 60000
104
- },
105
- {
106
- "name": "flaky",
107
- "description": "Flaky CI tests.",
108
- "retry": 0,
109
- "timeout": 30000,
110
- "priority": 1
111
- }
112
- ],
113
- "projects": []
114
- }
115
- ```
116
-
117
- ## Using Tags in Tests
118
-
119
- You can apply tags to individual tests or entire suites using the `tags` option:
120
-
121
- ```ts
122
- import { describe, test } from 'vitest'
123
-
124
- test('renders homepage', { tags: ['frontend'] }, () => {
125
- // ...
126
- })
127
-
128
- describe('API endpoints', { tags: ['backend'] }, () => {
129
- test('returns user data', () => {
130
- // This test inherits the "backend" tag from the parent suite
131
- })
132
-
133
- test('validates input', { tags: ['validation'] }, () => {
134
- // This test has both "backend" (inherited) and "validation" tags
135
- })
136
- })
137
- ```
138
-
139
- Tags are inherited from parent suites, so all tests inside a tagged `describe` block will automatically have that tag.
140
-
141
- It's also possible to define `tags` for every test in the file by using JSDoc's `@module-tag` at the top of the file:
142
-
143
- ```ts
144
- /**
145
- * Auth tests
146
- * @module-tag admin/pages/dashboard
147
- * @module-tag acceptance
148
- */
149
-
150
- test('dashboard renders items', () => {
151
- // ...
152
- })
153
- ```
154
-
155
- ::: danger
156
- A `@module-tag` in a JSDoc comment applies to all tests in that file, not just the test it precedes.
157
-
158
- Consider this example:
159
-
160
- ```js{3,10}
161
- describe('forms', () => {
162
- /**
163
- * @module-tag frontend
164
- */
165
- test('renders a form', () => {
166
- // ...
167
- })
168
-
169
- /**
170
- * @module-tag db
171
- */
172
- test('db returns users', () => {
173
- // ...
174
- })
175
- })
176
- ```
177
-
178
- In this example, every test in the file will have both the `frontend` and `db` tags. To tag individual tests, use the options argument instead:
179
-
180
- ```js{2,6}
181
- describe('forms', () => {
182
- test('renders a form', { tags: 'frontend' }, () => {
183
- // ...
184
- })
185
-
186
- test('db returns users', { tags: 'db' }, () => {
187
- // ...
188
- })
189
- })
190
- ```
191
- :::
192
-
193
- ## Filtering Tests by Tag
194
-
195
- To run only tests with specific tags, use the [`--tags-filter`](/guide/cli#tagsfilter) CLI option:
196
-
197
- ```shell
198
- vitest --tags-filter=frontend
199
- vitest --tags-filter="frontend and backend"
200
- ```
201
-
202
- If you are running Vitest UI, you can start a filter with a `tag:` prefix to filter out tests by tags using the same tags expression syntax:
203
-
204
- <img alt="The tags filter in Vitest UI" img-light src="/ui/light-ui-tags.png">
205
- <img alt="The tags filter in Vitest UI" img-dark src="/ui/dark-ui-tags.png">
206
-
207
- If you are using a programmatic API, you can pass down a `tagsFilter` option to [`startVitest`](/guide/advanced/#startvitest) or [`createVitest`](/guide/advanced/#createvitest):
208
-
209
- ```ts
210
- import { startVitest } from 'vitest/node'
211
-
212
- await startVitest('test', [], {
213
- tagsFilter: ['frontend and backend'],
214
- })
215
- ```
216
-
217
- Or you can create a [test specification](/api/advanced/test-specification) with your custom filters:
218
-
219
- ```ts
220
- const specification = vitest.getRootProject().createSpecification(
221
- '/path-to-file.js',
222
- {
223
- testTagsFilter: ['frontend and backend'],
224
- },
225
- )
226
- ```
227
-
228
- ### Syntax
229
-
230
- You can combine tags in different ways. Vitest supports these keywords:
231
-
232
- - `and` or `&&` to include both expressions
233
- - `or` or `||` to include at least one expression
234
- - `not` or `!` to exclude the expression
235
- - `*` to match any number of characters (0 or more)
236
- - `()` to group expressions and override precedence
237
-
238
- The parser follows standard [operator precedence](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence): `not`/`!` has the highest priority, then `and`/`&&`, then `or`/`||`. Use parentheses to override default precedence.
239
-
240
- ::: warning Reserved Names
241
- Tag names cannot be `and`, `or`, or `not` (case-insensitive) as these are reserved keywords. Tag names also cannot contain special characters (`(`, `)`, `&`, `|`, `!`, `*`, spaces) as these are used by the expression parser.
242
- :::
243
-
244
- ### Wildcards
245
-
246
- You can use a wildcard (`*`) to match any number of characters:
247
-
248
- ```shell
249
- vitest --tags-filter="unit/*"
250
- ```
251
-
252
- This will match tags like `unit/components`, `unit/utils`, etc.
253
-
254
- ### Excluding Tags
255
-
256
- To exclude tests with a specific tag, add an exclamation mark (`!`) at the start or a "not" keyword:
257
-
258
- ```shell
259
- vitest --tags-filter="!slow and not flaky"
260
- ```
261
-
262
- ### Examples
263
-
264
- Here are some common filtering patterns:
265
-
266
- ```shell
267
- # Run only unit tests
268
- vitest --tags-filter="unit"
269
-
270
- # Run tests that are both frontend AND fast
271
- vitest --tags-filter="frontend and fast"
272
-
273
- # Run tests that are either unit OR e2e
274
- vitest --tags-filter="unit or e2e"
275
-
276
- # Run all tests except slow ones
277
- vitest --tags-filter="!slow"
278
-
279
- # Run frontend tests that are not flaky
280
- vitest --tags-filter="frontend && !flaky"
281
-
282
- # Run tests matching a wildcard pattern
283
- vitest --tags-filter="api/*"
284
-
285
- # Complex expression with parentheses
286
- vitest --tags-filter="(unit || e2e) && !slow"
287
-
288
- # Run database tests that are either postgres or mysql, but not slow
289
- vitest --tags-filter="db && (postgres || mysql) && !slow"
290
- ```
291
-
292
- You can also pass multiple `--tags-filter` flags. They are combined with AND logic:
293
-
294
- ```shell
295
- # Run tests that match (unit OR e2e) AND are NOT slow
296
- vitest --tags-filter="unit || e2e" --tags-filter="!slow"
297
- ```
298
-
299
- ### Checking Tags Filter at Runtime
300
-
301
- You can use `TestRunner.matchesTags` (since Vitest 4.1.1) to check whether the current tags filter matches a set of tags. This is useful for conditionally running expensive setup logic only when relevant tests are included:
302
-
303
- ```ts
304
- import { beforeAll, TestRunner } from 'vitest'
305
-
306
- beforeAll(async () => {
307
- // Seed database when "vitest --tags-filter db" is used
308
- if (TestRunner.matchesTags(['db'])) {
309
- await seedDatabase()
310
- }
311
- })
312
- ```
313
-
314
- The method accepts an array of tags and returns `true` if the current `--tags-filter` would include a test with those tags. If no tags filter is active, it always returns `true`.
@@ -1,149 +0,0 @@
1
- # Testing Types
2
-
3
- ::: tip Sample Project
4
-
5
- [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/typecheck) - [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/typecheck?initialPath=__vitest__/)
6
-
7
- :::
8
-
9
- Vitest allows you to write tests for your types, using `expectTypeOf` or `assertType` syntaxes. By default all tests inside `*.test-d.ts` files are considered type tests, but you can change it with [`typecheck.include`](/config/typecheck#typecheck-include) config option.
10
-
11
- Under the hood Vitest calls `tsc` or `vue-tsc`, depending on your config, and parses results. Vitest will also print out type errors in your source code, if it finds any. You can disable it with [`typecheck.ignoreSourceErrors`](/config/typecheck#typecheck-ignoresourceerrors) config option.
12
-
13
- Keep in mind that Vitest doesn't run these files, they are only statically analyzed by the compiler. Meaning, that if you use a dynamic name or `test.each` or `test.for`, the test name will not be evaluated - it will be displayed as is.
14
-
15
- ::: warning
16
- Before Vitest 2.1, your `typecheck.include` overrode the `include` pattern, so your runtime tests did not actually run; they were only type-checked.
17
-
18
- Since Vitest 2.1, if your `include` and `typecheck.include` overlap, Vitest will report type tests and runtime tests as separate entries.
19
- :::
20
-
21
- Using CLI flags, like `--allowOnly` and `-t` are also supported for type checking.
22
-
23
- ```ts [mount.test-d.ts]
24
- import { assertType, expectTypeOf } from 'vitest'
25
- import { mount } from './mount.js'
26
-
27
- test('my types work properly', () => {
28
- expectTypeOf(mount).toBeFunction()
29
- expectTypeOf(mount).parameter(0).toExtend<{ name: string }>()
30
-
31
- // @ts-expect-error name is a string
32
- assertType(mount({ name: 42 }))
33
- })
34
- ```
35
-
36
- Any type error triggered inside a test file will be treated as a test error, so you can use any type trick you want to test types of your project.
37
-
38
- You can see a list of possible matchers in [API section](/api/expect-typeof).
39
-
40
- ## Reading Errors
41
-
42
- If you are using `expectTypeOf` API, refer to the [expect-type documentation on its error messages](https://github.com/mmkal/expect-type#error-messages).
43
-
44
- When types don't match, `.toEqualTypeOf` and `.toExtend` use a special helper type to produce error messages that are as actionable as possible. But there's a bit of an nuance to understanding them. Since the assertions are written "fluently", the failure should be on the "expected" type, not the "actual" type (`expect<Actual>().toEqualTypeOf<Expected>()`). This means that type errors can be a little confusing - so this library produces a `MismatchInfo` type to try to make explicit what the expectation is. For example:
45
-
46
- ```ts
47
- expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: string }>()
48
- ```
49
-
50
- Is an assertion that will fail, since `{a: 1}` has type `{a: number}` and not `{a: string}`. The error message in this case will read something like this:
51
-
52
- ```
53
- test/test.ts:999:999 - error TS2344: Type '{ a: string; }' does not satisfy the constraint '{ a: \\"Expected: string, Actual: number\\"; }'.
54
- Types of property 'a' are incompatible.
55
- Type 'string' is not assignable to type '\\"Expected: string, Actual: number\\"'.
56
-
57
- 999 expectTypeOf({a: 1}).toEqualTypeOf<{a: string}>()
58
- ```
59
-
60
- Note that the type constraint reported is a human-readable messaging specifying both the "expected" and "actual" types. Rather than taking the sentence `Types of property 'a' are incompatible // Type 'string' is not assignable to type "Expected: string, Actual: number"` literally - just look at the property name (`'a'`) and the message: `Expected: string, Actual: number`. This will tell you what's wrong, in most cases. Extremely complex types will of course be more effort to debug, and may require some experimentation. Please [raise an issue](https://github.com/mmkal/expect-type) if the error messages are actually misleading.
61
-
62
- The `toBe...` methods (like `toBeString`, `toBeNumber`, `toBeVoid` etc.) fail by resolving to a non-callable type when the `Actual` type under test doesn't match up. For example, the failure for an assertion like `expectTypeOf(1).toBeString()` will look something like this:
63
-
64
- ```
65
- test/test.ts:999:999 - error TS2349: This expression is not callable.
66
- Type 'ExpectString<number>' has no call signatures.
67
-
68
- 999 expectTypeOf(1).toBeString()
69
- ~~~~~~~~~~
70
- ```
71
-
72
- The `This expression is not callable` part isn't all that helpful - the meaningful error is the next line, `Type 'ExpectString<number> has no call signatures`. This essentially means you passed a number but asserted it should be a string.
73
-
74
- If TypeScript added support for ["throw" types](https://github.com/microsoft/TypeScript/pull/40468) these error messages could be improved significantly. Until then they will take a certain amount of squinting.
75
-
76
- ### Concrete "expected" objects vs typeargs
77
-
78
- Error messages for an assertion like this:
79
-
80
- ```ts
81
- expectTypeOf({ a: 1 }).toEqualTypeOf({ a: '' })
82
- ```
83
-
84
- Will be less helpful than for an assertion like this:
85
-
86
- ```ts
87
- expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: string }>()
88
- ```
89
-
90
- This is because the TypeScript compiler needs to infer the typearg for the `.toEqualTypeOf({a: ''})` style, and this library can only mark it as a failure by comparing it against a generic `Mismatch` type. So, where possible, use a typearg rather than a concrete type for `.toEqualTypeOf` and `.toExtend`. If it's much more convenient to compare two concrete types, you can use `typeof`:
91
-
92
- ```ts
93
- const one = valueFromFunctionOne({ some: { complex: inputs } })
94
- const two = valueFromFunctionTwo({ some: { other: inputs } })
95
-
96
- expectTypeOf(one).toEqualTypeOf<typeof two>()
97
- ```
98
-
99
- If you find it hard working with `expectTypeOf` API and figuring out errors, you can always use more simple `assertType` API:
100
-
101
- ```ts
102
- const answer = 42
103
-
104
- assertType<number>(answer)
105
- // @ts-expect-error answer is not a string
106
- assertType<string>(answer)
107
- ```
108
-
109
- ::: tip
110
- When using `@ts-expect-error` syntax, you might want to make sure that you didn't make a typo. You can do that by including your type files in [`test.include`](/config/include) config option, so Vitest will also actually *run* these tests and fail with `ReferenceError`.
111
-
112
- This will pass, because it expects an error, but the word “answer” has a typo, so it's a false positive error:
113
-
114
- ```ts
115
- // @ts-expect-error answer is not a string
116
- assertType<string>(answr)
117
- ```
118
- :::
119
-
120
- ## Run Typechecking
121
-
122
- To enable typechecking, just add [`--typecheck`](/config/typecheck) flag to your Vitest command in `package.json`:
123
-
124
- ```json [package.json]
125
- {
126
- "scripts": {
127
- "test": "vitest --typecheck"
128
- }
129
- }
130
- ```
131
-
132
- Now you can run typecheck:
133
-
134
- ::: code-group
135
- ```bash [npm]
136
- npm run test
137
- ```
138
- ```bash [yarn]
139
- yarn test
140
- ```
141
- ```bash [pnpm]
142
- pnpm run test
143
- ```
144
- ```bash [bun]
145
- bun test
146
- ```
147
- :::
148
-
149
- Vitest uses `tsc --noEmit` or `vue-tsc --noEmit`, depending on your configuration, so you can remove these scripts from your pipeline.
@@ -1,160 +0,0 @@
1
- # Vitest UI
2
-
3
- Powered by Vite, Vitest also has a dev server under the hood when running the tests. This allows Vitest to provide a beautiful UI to view and interact with your tests. The Vitest UI is optional, so you'll need to install it with:
4
-
5
- ```bash
6
- npm i -D @vitest/ui
7
- ```
8
-
9
- Then you can start the tests with UI by passing the `--ui` flag:
10
-
11
- ```bash
12
- vitest --ui
13
- ```
14
-
15
- Then you can visit the Vitest UI at <a href="http://localhost:51204/__vitest__/">`http://localhost:51204/__vitest__/`</a>
16
-
17
- ::: warning
18
- The UI is interactive and requires a running Vite server, so make sure to run Vitest in `watch` mode (the default). Alternatively, you can generate a static HTML report that looks identical to the Vitest UI by specifying `html` in config's `reporters` option.
19
- :::
20
-
21
- <img alt="Vitest UI" img-light src="/ui-1-light.png">
22
- <img alt="Vitest UI" img-dark src="/ui-1-dark.png">
23
-
24
- UI can also be used as a reporter. Use `'html'` reporter in your Vitest configuration to generate HTML output and preview the results of your tests:
25
-
26
- ```ts [vitest.config.ts]
27
- import { defineConfig } from 'vitest/config'
28
-
29
- export default defineConfig({
30
- test: {
31
- reporters: ['html'],
32
- },
33
- })
34
- ```
35
-
36
- You can check your coverage report in Vitest UI: see [Vitest UI Coverage](/guide/coverage#vitest-ui) for more details.
37
-
38
- ::: warning
39
- If you still want to see how your tests are running in real time in the terminal, don't forget to add `default` reporter to `reporters` option: `['default', 'html']`.
40
- :::
41
-
42
- ::: tip
43
- To preview your HTML report, you can use the [vite preview](https://vitejs.dev/guide/cli.html#vite-preview) command:
44
-
45
- ```sh
46
- npx vite preview --outDir ./html
47
- ```
48
-
49
- You can configure output with [`outputFile`](/config/outputfile) config option. You need to specify `.html` path there. For example, `./html/index.html` is the default value.
50
- :::
51
-
52
- ::: tip
53
- To view the HTML report from CI, for example in GitHub Actions, upload the output directory as an artifact:
54
-
55
- ```yaml
56
- - uses: actions/upload-artifact@v4
57
- id: upload-report
58
- with:
59
- name: vitest-report
60
- path: html/
61
-
62
- - name: Viewer link in summary
63
- run: echo "[View HTML report](https://viewer.vitest.dev/?url=${{ steps.upload-report.outputs.artifact-url }})" >> $GITHUB_STEP_SUMMARY
64
- ```
65
-
66
- This adds a link to the job summary. Click it to open the report in [Vitest Viewer](https://viewer.vitest.dev/) directly in the browser. You can also download the artifact manually and extract it, then run `vite preview` locally as above.
67
- :::
68
-
69
- ## Module Graph
70
-
71
- Module Graph's tab displays the module graph of the selected test file.
72
-
73
- ::: info
74
- All of the provided images use [Zammad](https://github.com/zammad/zammad) repository as an example.
75
- :::
76
-
77
- <img alt="The module graph view" img-light src="/ui/light-module-graph.png">
78
- <img alt="The module graph view" img-dark src="/ui/dark-module-graph.png">
79
-
80
- If there are more than 50 modules, the module graph displays only the first two levels of the graph to reduce the visual clutter. You can always click on "Show Full Graph" icon to preview the full graph.
81
-
82
- <center>
83
- <img alt="The 'Show Full Graph' button located close to the legend" img-light src="/ui/light-ui-show-graph.png">
84
- <img alt="The 'Show Full Graph' button located close to the legend" img-dark src="/ui/dark-ui-show-graph.png">
85
- </center>
86
-
87
- ::: warning
88
- Note that if your graph is too big, it may take some time before the node positions are stabilized.
89
- :::
90
-
91
- You can always restore the entry module graph by clicking on "Reset". To expand the module graph, right-click or hold <kbd>Shift</kbd> while clicking the node that interests you. It will display all nodes related to the selected one.
92
-
93
- By default, Vitest doesn't show the modules from `node_modules`. Usually, these modules are externalized. You can enable them by deselecting "Hide node_modules".
94
-
95
- ### Module Info
96
-
97
- By left-clicking on the module node, you open the Module Info view.
98
-
99
- <img alt="The module info view for an inlined module" img-light src="/ui/light-module-info.png">
100
- <img alt="The module info view for an inlined module" img-dark src="/ui/dark-module-info.png">
101
-
102
- This view is separated into two parts. The top part shows the full module ID and some diagnostics about the module. If [`experimental.fsModuleCache`](/config/experimental#experimental-fsmodulecache) is enabled, there will be a "cached" or "not cached" badge. On the right you can see time diagnostics:
103
-
104
- - Self Time: the time it took to import the module, excluding static imports.
105
- - Total Time: the time it took to import the module, including static imports. Note that this does not include `transform` time of the current module.
106
- - Transform: the time it took to transform the module.
107
-
108
- If you opened this view by clicking on an import, you will also see a "Back" button at the start that will take you to the previous module.
109
-
110
- The bottom part depends on the module type. If the module is external, you will only see the source code of that file. You will not be able to traverse the module graph any further, and you won't see how long it took to import static imports.
111
-
112
- <img alt="The module info view for an external module" img-light src="/ui/light-module-info-external.png">
113
- <img alt="The module info view for an external module" img-dark src="/ui/dark-module-info-external.png">
114
-
115
- If the module was inlined, you will see three more windows:
116
-
117
- - Source: unchanged source code of the module
118
- - Transformed: the transformed code that Vitest executes using Vite's [module runner](https://vite.dev/guide/api-environment-runtimes#modulerunner)
119
- - Source Map (v3): source map mappings
120
-
121
- All static imports in the "Source" window show a total time it took to evaluate them by the current module. If the import was already evaluated in the module graph, it will show `0ms` because it is cached by that point.
122
-
123
- If the module took longer than the [`danger` threshold](/config/experimental#experimental-importdurations-thresholds) (default: 500ms) to load, the time will be displayed in red. If the module took longer than the [`warn` threshold](/config/experimental#experimental-importdurations-thresholds) (default: 100ms), the time will be displayed in orange.
124
-
125
- You can click on an import source to jump into that module and traverse the graph further (note `./support/assertions/index.ts` below).
126
-
127
- <img alt="The module info view for an internal module" img-light src="/ui/light-module-info-traverse.png">
128
- <img alt="The module info view for an internal module" img-dark src="/ui/dark-module-info-traverse.png">
129
-
130
- ::: warning
131
- Note that type-only imports are not executed at runtime and do not display a total duration. They also cannot be opened.
132
- :::
133
-
134
- If another plugin injects a module import during transformation, those imports will be displayed at the start of the module in gray colour (for example, modules injected by `import.meta.glob`). They also show the total time and can be traversed further.
135
-
136
- <img alt="The module info view for an internal module" img-light src="/ui/light-module-info-shadow.png">
137
- <img alt="The module info view for an internal module" img-dark src="/ui/dark-module-info-shadow.png">
138
-
139
- ::: tip
140
- If you are developing a custom integration on top of Vitest, you can use [`vitest.experimental_getSourceModuleDiagnostic`](/api/advanced/vitest#getsourcemodulediagnostic) to retrieve this information.
141
- :::
142
-
143
- ### Import Breakdown
144
-
145
- ::: tip FEEDBACK
146
- Please, leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9224).
147
- :::
148
-
149
- The Module Graph tab also provides an Import Breakdown with a list of modules that take the longest time to load (top 10 by default), sorted by Total Time.
150
-
151
- <img alt="Import breakdown with a list of top 10 modules that take the longest time to load" img-light src="/ui/light-import-breakdown.png">
152
- <img alt="Import breakdown with a list of top 10 modules that take the longest time to load" img-dark src="/ui/dark-import-breakdown.png">
153
-
154
- You can click on the module to see the Module Info. If the module is external, it will have the yellow color (the same color in the module graph).
155
-
156
- The breakdown shows a list of modules with self time, total time, and a percentage relative to the time it took to load the whole test file.
157
-
158
- The "Show Import Breakdown" icon will have a red color if there is at least one file that took longer than the [`danger` threshold](/config/experimental#experimental-importdurations-thresholds) (default: 500ms) to load, and it will be orange if there is at least one file that took longer than the [`warn` threshold](/config/experimental#experimental-importdurations-thresholds) (default: 100ms).
159
-
160
- You can use [`experimental.importDurations.limit`](/config/experimental#experimental-importdurationslimit) to control the number of imports displayed.
@@ -1,5 +0,0 @@
1
- # Using Plugins
2
-
3
- Vitest can be extended using plugins, similar to how Vite plugins work. This allows you to enhance and customize Vitest's functionality by using the same API and concepts of Vite plugins.
4
-
5
- For detailed guidance on how to write plugins, you can refer to the [Vite plugin documentation](https://vitejs.dev/guide/api-plugin).