@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,321 +0,0 @@
1
- # TestProject <Version>3.0.0</Version> {#testproject}
2
-
3
- ::: warning
4
- This guide describes the advanced Node.js API. If you just want to define projects, follow the ["Test Projects"](/guide/projects) guide.
5
- :::
6
-
7
- ## name
8
-
9
- The name is a unique string assigned by the user or interpreted by Vitest. If user did not provide a name, Vitest tries to load a `package.json` in the root of the project and takes the `name` property from there. If there is no `package.json`, Vitest uses the name of the folder by default. Inline projects use numbers as the name (converted to string).
10
-
11
- ::: code-group
12
- ```ts [node.js]
13
- import { createVitest } from 'vitest/node'
14
-
15
- const vitest = await createVitest('test')
16
- vitest.projects.map(p => p.name) === [
17
- '@pkg/server',
18
- 'utils',
19
- '2',
20
- 'custom'
21
- ]
22
- ```
23
- ```ts [vitest.config.js]
24
- import { defineConfig } from 'vitest/config'
25
-
26
- export default defineConfig({
27
- test: {
28
- projects: [
29
- './packages/server', // has package.json with "@pkg/server"
30
- './utils', // doesn't have a package.json file
31
- {
32
- // doesn't customize the name
33
- test: {
34
- pool: 'threads',
35
- },
36
- },
37
- {
38
- // customized the name
39
- test: {
40
- name: 'custom',
41
- },
42
- },
43
- ],
44
- },
45
- })
46
- ```
47
- :::
48
-
49
- ::: info
50
- If the [root project](/api/advanced/vitest#getrootproject) is not part of user projects, its `name` will not be resolved.
51
- :::
52
-
53
- ## vitest
54
-
55
- `vitest` references the global [`Vitest`](/api/advanced/vitest) process.
56
-
57
- ## serializedConfig
58
-
59
- This is the config that test processes receive. Vitest [serializes config](https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/config/serializeConfig.ts) manually by removing all functions and properties that are not possible to serialize. Since this value is available in both tests and node, its type is exported from the main entry point.
60
-
61
- ```ts
62
- import type { SerializedConfig } from 'vitest'
63
-
64
- const config: SerializedConfig = vitest.projects[0].serializedConfig
65
- ```
66
-
67
- ::: warning
68
- The `serializedConfig` property is a getter. Every time it's accessed Vitest serializes the config again in case it was changed. This also means that it always returns a different reference:
69
-
70
- ```ts
71
- project.serializedConfig === project.serializedConfig // ❌
72
- ```
73
- :::
74
-
75
- ## globalConfig
76
-
77
- The test config that [`Vitest`](/api/advanced/vitest) was initialized with. If this is the [root project](/api/advanced/vitest#getrootproject), `globalConfig` and `config` will reference the same object. This config is useful for values that cannot be set on the project level, like `coverage` or `reporters`.
78
-
79
- ```ts
80
- import type { ResolvedConfig } from 'vitest/node'
81
-
82
- vitest.config === vitest.projects[0].globalConfig
83
- ```
84
-
85
- ## config
86
-
87
- This is the project's resolved test config.
88
-
89
- ## hash <Version>3.2.0</Version> {#hash}
90
-
91
- The unique hash of this project. This value is consistent between the reruns.
92
-
93
- It is based on the root of the project and its name. Note that the root path is not consistent between different OS, so the hash will also be different.
94
-
95
- ## vite
96
-
97
- This is project's [`ViteDevServer`](https://vite.dev/guide/api-javascript#vitedevserver). All projects have their own Vite servers.
98
-
99
- ## browser
100
-
101
- This value will be set only if tests are running in the browser. If `browser` is enabled, but tests didn't run yet, this will be `undefined`. If you need to check if the project supports browser tests, use `project.isBrowserEnabled()` method.
102
-
103
- ::: warning
104
- The browser API is even more experimental and doesn't follow SemVer. The browser API will be standardized separately from the rest of the APIs.
105
- :::
106
-
107
- ## provide
108
-
109
- ```ts
110
- function provide<T extends keyof ProvidedContext & string>(
111
- key: T,
112
- value: ProvidedContext[T],
113
- ): void
114
- ```
115
-
116
- A way to provide custom values to tests in addition to [`config.provide`](/config/provide) field. All values are validated with [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone) before they are stored, but the values on `providedContext` themselves are not cloned.
117
-
118
- ::: code-group
119
- ```ts [node.js]
120
- import { createVitest } from 'vitest/node'
121
-
122
- const vitest = await createVitest('test')
123
- const project = vitest.projects.find(p => p.name === 'custom')
124
- project.provide('key', 'value')
125
- await vitest.start()
126
- ```
127
- ```ts [test.spec.js]
128
- import { inject } from 'vitest'
129
- const value = inject('key')
130
- ```
131
- :::
132
-
133
- The values can be provided dynamically. Provided value in tests will be updated on their next run.
134
-
135
- ::: tip
136
- This method is also available to [global setup files](/config/globalsetup) for cases where you cannot use the public API:
137
-
138
- ```js
139
- export default function setup({ provide }) {
140
- provide('wsPort', 3000)
141
- }
142
- ```
143
- :::
144
-
145
- ## getProvidedContext
146
-
147
- ```ts
148
- function getProvidedContext(): ProvidedContext
149
- ```
150
-
151
- This returns the context object. Every project also inherits the global context set by `vitest.provide`.
152
-
153
- ```ts
154
- import { createVitest } from 'vitest/node'
155
-
156
- const vitest = await createVitest('test')
157
- vitest.provide('global', true)
158
- const project = vitest.projects.find(p => p.name === 'custom')
159
- project.provide('key', 'value')
160
-
161
- // { global: true, key: 'value' }
162
- const context = project.getProvidedContext()
163
- ```
164
-
165
- ::: tip
166
- Project context values will always override root project's context.
167
- :::
168
-
169
- ## createSpecification
170
-
171
- ```ts
172
- function createSpecification(
173
- moduleId: string,
174
- locations?: number[],
175
- ): TestSpecification
176
- ```
177
-
178
- Create a [test specification](/api/advanced/test-specification) that can be used in [`vitest.runTestSpecifications`](/api/advanced/vitest#runtestspecifications). Specification scopes the test file to a specific `project` and test `locations` (optional). Test [locations](/api/advanced/test-case#location) are code lines where the test is defined in the source code. If locations are provided, Vitest will only run tests defined on those lines. Note that if [`testNamePattern`](/config/testnamepattern) is defined, then it will also be applied.
179
-
180
- ```ts
181
- import { createVitest } from 'vitest/node'
182
- import { resolve } from 'node:path/posix'
183
-
184
- const vitest = await createVitest('test')
185
- const project = vitest.projects[0]
186
- const specification = project.createSpecification(
187
- resolve('./example.test.ts'),
188
- [20, 40], // optional test lines
189
- )
190
- await vitest.runTestSpecifications([specification])
191
- ```
192
-
193
- ::: warning
194
- `createSpecification` expects resolved [module ID](/api/advanced/test-specification#moduleid). It doesn't auto-resolve the file or check that it exists on the file system.
195
-
196
- Also note that `project.createSpecification` always returns a new instance.
197
- :::
198
-
199
- ## isRootProject
200
-
201
- ```ts
202
- function isRootProject(): boolean
203
- ```
204
-
205
- Checks if the current project is the root project. You can also get the root project by calling [`vitest.getRootProject()`](/api/advanced/vitest#getrootproject).
206
-
207
- ## globTestFiles
208
-
209
- ```ts
210
- function globTestFiles(filters?: string[]): {
211
- /**
212
- * Test files that match the filters.
213
- */
214
- testFiles: string[]
215
- /**
216
- * Typecheck test files that match the filters. This will be empty unless `typecheck.enabled` is `true`.
217
- */
218
- typecheckTestFiles: string[]
219
- }
220
- ```
221
-
222
- Globs all test files. This function returns an object with regular tests and typecheck tests.
223
-
224
- This method accepts `filters`. Filters can only a part of the file path, unlike in other methods on the [`Vitest`](/api/advanced/vitest) instance:
225
-
226
- ```js
227
- project.globTestFiles(['foo']) // ✅
228
- project.globTestFiles(['basic/foo.js:10']) // ❌
229
- ```
230
-
231
- ::: tip
232
- Vitest uses [fast-glob](https://npmx.dev/package/fast-glob) to find test files. `test.dir`, `test.root`, `root` or `process.cwd()` define the `cwd` option.
233
-
234
- This method looks at several config options:
235
-
236
- - `test.include`, `test.exclude` to find regular test files
237
- - `test.includeSource`, `test.exclude` to find in-source tests
238
- - `test.typecheck.include`, `test.typecheck.exclude` to find typecheck tests
239
- :::
240
-
241
- ## matchesTestGlob
242
-
243
- ```ts
244
- function matchesTestGlob(
245
- moduleId: string,
246
- source?: () => string
247
- ): boolean
248
- ```
249
-
250
- This method checks if the file is a regular test file. It uses the same config properties that `globTestFiles` uses for validation.
251
-
252
- This method also accepts a second parameter, which is the source code. This is used to validate if the file is an in-source test. If you are calling this method several times for several projects it is recommended to read the file once and pass it down directly. If the file is not a test file, but matches the `includeSource` glob, Vitest will synchronously read the file unless the `source` is provided.
253
-
254
- ```ts
255
- import { createVitest } from 'vitest/node'
256
- import { resolve } from 'node:path/posix'
257
-
258
- const vitest = await createVitest('test')
259
- const project = vitest.projects[0]
260
-
261
- project.matchesTestGlob(resolve('./basic.test.ts')) // true
262
- project.matchesTestGlob(resolve('./basic.ts')) // false
263
- project.matchesTestGlob(resolve('./basic.ts'), () => `
264
- if (import.meta.vitest) {
265
- // ...
266
- }
267
- `) // true if `includeSource` is set
268
- ```
269
-
270
- ## import
271
-
272
- <!--@include: ./import-example.md-->
273
-
274
- Import a file using Vite module runner. The file will be transformed by Vite with provided project's config and executed in a separate context. Note that `moduleId` will be relative to the `config.root`.
275
-
276
- ::: danger
277
- `project.import` reuses Vite's module graph, so importing the same module using a regular import will return a different module:
278
-
279
- ```ts
280
- import * as staticExample from './example.js'
281
- const dynamicExample = await project.import('./example.js')
282
-
283
- dynamicExample !== staticExample // ✅
284
- ```
285
- :::
286
-
287
- ::: info
288
- Internally, Vitest uses this method to import global setups, custom coverage providers and custom reporters, meaning all of them share the same module graph as long as they belong to the same Vite server.
289
- :::
290
-
291
- ## onTestsRerun
292
-
293
- ```ts
294
- function onTestsRerun(cb: OnTestsRerunHandler): void
295
- ```
296
-
297
- This is a shorthand for [`project.vitest.onTestsRerun`](/api/advanced/vitest#ontestsrerun). It accepts a callback that will be awaited when the tests have been scheduled to rerun (usually, due to a file change).
298
-
299
- ```ts
300
- project.onTestsRerun((specs) => {
301
- console.log(specs)
302
- })
303
- ```
304
-
305
- ## isBrowserEnabled
306
-
307
- ```ts
308
- function isBrowserEnabled(): boolean
309
- ```
310
-
311
- Returns `true` if this project runs tests in the browser.
312
-
313
- ## close
314
-
315
- ```ts
316
- function close(): Promise<void>
317
- ```
318
-
319
- Closes the project and all associated resources. This can only be called once; the closing promise is cached until the server restarts. If the resources are needed again, create a new project.
320
-
321
- In detail, this method closes the Vite server, stops the typechecker service, closes the browser if it's running, deletes the temporary directory that holds the source code, and resets the provided context.
@@ -1,96 +0,0 @@
1
- # TestSpecification
2
-
3
- The `TestSpecification` class describes what module to run as a test and its parameters.
4
-
5
- You can only create a specification by calling [`createSpecification`](/api/advanced/test-project#createspecification) method on a test project:
6
-
7
- ```ts
8
- const specification = project.createSpecification(
9
- resolve('./example.test.ts'),
10
- {
11
- testLines: [20, 40],
12
- testNamePattern: /hello world/,
13
- testIds: ['1223128da3_0_0_0', '1223128da3_0_0'],
14
- testTagsFilter: ['frontend and backend'],
15
- } // optional test filters
16
- )
17
- ```
18
-
19
- `createSpecification` expects resolved module identifier. It doesn't auto-resolve the file or check that it exists on the file system.
20
-
21
- ## taskId
22
-
23
- [Test module's](/api/advanced/test-suite#id) identifier.
24
-
25
- ## project
26
-
27
- This references the [`TestProject`](/api/advanced/test-project) that the test module belongs to.
28
-
29
- ## moduleId
30
-
31
- The ID of the module in Vite's module graph. Usually, it's an absolute file path using posix separator:
32
-
33
- ```ts
34
- 'C:/Users/Documents/project/example.test.ts' // ✅
35
- '/Users/mac/project/example.test.ts' // ✅
36
- 'C:\\Users\\Documents\\project\\example.test.ts' // ❌
37
- ```
38
-
39
- ## testModule
40
-
41
- Instance of [`TestModule`](/api/advanced/test-module) associated with the specification. If test wasn't queued yet, this will be `undefined`.
42
-
43
- ## pool {#pool}
44
-
45
- The [`pool`](/config/pool) in which the test module will run.
46
-
47
- ::: danger
48
- It's possible to have multiple pools in a single test project with [`typecheck.enabled`](/config/typecheck#typecheck-enabled). This means it's possible to have several specifications with the same `moduleId` but different `pool`. In later versions, the project will only support a single pool.
49
- :::
50
-
51
- ## testLines
52
-
53
- This is an array of lines in the source code where the test files are defined. This field is defined only if the `createSpecification` method received an array.
54
-
55
- Note that if there is no test on at least one of the lines, the whole suite will fail. An example of a correct `testLines` configuration:
56
-
57
- ::: code-group
58
- ```ts [script.js]
59
- const specification = project.createSpecification(
60
- resolve('./example.test.ts'),
61
- [3, 8, 9],
62
- )
63
- ```
64
- ```ts:line-numbers{3,8,9} [example.test.js]
65
- import { test, describe } from 'vitest'
66
-
67
- test('verification works')
68
-
69
- describe('a group of tests', () => { // [!code error]
70
- // ...
71
-
72
- test('nested test')
73
- test.skip('skipped test')
74
- })
75
- ```
76
- :::
77
-
78
- ## testNamePattern <Version>4.1.0</Version> {#testnamepattern}
79
-
80
- A regexp that matches the name of the test in this module. This value will override the global [`testNamePattern`](/config/testnamepattern) option if it's set.
81
-
82
- ## testIds <Version>4.1.0</Version> {#testids}
83
-
84
- The ids of tasks inside of this specification to run.
85
-
86
- ## testTagsFilter <Version>4.1.0</Version> {#testtagsfilter}
87
-
88
- The [tags filter](/guide/test-tags#syntax) that a test must pass in order to be included in the run. Multiple filters are treated as `AND`.
89
-
90
- ## toJSON
91
-
92
- ```ts
93
- function toJSON(): SerializedTestSpecification
94
- ```
95
-
96
- `toJSON` generates a JSON-friendly object that can be consumed by the [Browser Mode](/guide/browser/) or [Vitest UI](/guide/ui).
@@ -1,230 +0,0 @@
1
- # TestSuite
2
-
3
- The `TestSuite` class represents a single suite. This class is only available in the main thread. Refer to the ["Runner API"](/api/advanced/runner#tasks) if you are working with runtime tasks.
4
-
5
- The `TestSuite` instance always has a `type` property with the value of `suite`. You can use it to distinguish between different task types:
6
-
7
- ```ts
8
- if (task.type === 'suite') {
9
- task // TestSuite
10
- }
11
- ```
12
-
13
- ## project
14
-
15
- This references the [`TestProject`](/api/advanced/test-project) that the test belongs to.
16
-
17
- ## module
18
-
19
- This is a direct reference to the [`TestModule`](/api/advanced/test-module) where the test is defined.
20
-
21
- ## name
22
-
23
- This is a suite name that was passed to the `describe` function.
24
-
25
- ```ts
26
- import { describe } from 'vitest'
27
-
28
- // [!code word:'the validation logic']
29
- describe('the validation logic', () => {
30
- // ...
31
- })
32
- ```
33
-
34
- ## fullName
35
-
36
- The name of the suite including all parent suites separated with `>` symbol. This suite has a full name "the validation logic > validating cities":
37
-
38
- ```ts
39
- import { describe, test } from 'vitest'
40
-
41
- // [!code word:'the validation logic']
42
- // [!code word:'validating cities']
43
- describe('the validation logic', () => {
44
- describe('validating cities', () => {
45
- // ...
46
- })
47
- })
48
- ```
49
-
50
- ## id
51
-
52
- This is suite's unique identifier. This ID is deterministic and will be the same for the same suite across multiple runs. The ID is based on the [project](/api/advanced/test-project) name, module ID and suite order.
53
-
54
- The ID looks like this:
55
-
56
- ```
57
- 1223128da3_0_0_0
58
- ^^^^^^^^^^ the file hash
59
- ^ suite index
60
- ^ nested suite index
61
- ^ test index
62
- ```
63
-
64
- ::: tip
65
- You can generate file hash with `generateFileHash` function from `vitest/node` which is available since Vitest 3:
66
-
67
- ```ts
68
- import { generateFileHash } from 'vitest/node'
69
-
70
- const hash = generateFileHash(
71
- '/file/path.js', // relative path
72
- undefined, // the project name or `undefined` is not set
73
- )
74
- ```
75
- :::
76
-
77
- ::: danger
78
- Don't try to parse the ID. It can have a minus at the start: `-1223128da3_0_0_0`.
79
- :::
80
-
81
- ## location
82
-
83
- The location in the module where the suite was defined. Locations are collected only if [`includeTaskLocation`](/config/includetasklocation) is enabled in the config. Note that this option is automatically enabled if `--reporter=html`, `--ui` or `--browser` flags are used.
84
-
85
- The location of this suite will be equal to `{ line: 3, column: 1 }`:
86
-
87
- ```ts:line-numbers {3}
88
- import { describe } from 'vitest'
89
-
90
- describe('the validation works correctly', () => {
91
- // ...
92
- })
93
- ```
94
-
95
- ## parent
96
-
97
- Parent suite. If the suite was called directly inside the [module](/api/advanced/test-module), the parent will be the module itself.
98
-
99
- ## options
100
-
101
- ```ts
102
- interface TaskOptions {
103
- readonly each: boolean | undefined
104
- readonly fails: boolean | undefined
105
- readonly concurrent: boolean | undefined
106
- readonly shuffle: boolean | undefined
107
- readonly retry: number | undefined
108
- readonly repeats: number | undefined
109
- readonly tags: string[] | undefined
110
- readonly mode: 'run' | 'only' | 'skip' | 'todo'
111
- }
112
- ```
113
-
114
- The options that suite was collected with.
115
-
116
- ## children
117
-
118
- This is a [collection](/api/advanced/test-collection) of all suites and tests inside the current suite.
119
-
120
- ```ts
121
- for (const task of suite.children) {
122
- if (task.type === 'test') {
123
- console.log('test', task.fullName)
124
- }
125
- else {
126
- // task is TaskSuite
127
- console.log('suite', task.name)
128
- }
129
- }
130
- ```
131
-
132
- ::: warning
133
- Note that `suite.children` will only iterate the first level of nesting, it won't go deeper. If you need to iterate over all tests or suites, use [`children.allTests()`](/api/advanced/test-collection#alltests) or [`children.allSuites()`](/api/advanced/test-collection#allsuites). If you need to iterate over everything, use recursive function:
134
-
135
- ```ts
136
- function visit(collection: TestCollection) {
137
- for (const task of collection) {
138
- if (task.type === 'suite') {
139
- // report a suite
140
- visit(task.children)
141
- }
142
- else {
143
- // report a test
144
- }
145
- }
146
- }
147
- ```
148
- :::
149
-
150
- ## ok
151
-
152
- ```ts
153
- function ok(): boolean
154
- ```
155
-
156
- Checks if the suite has any failed tests. This will also return `false` if suite failed during collection. In that case, check the [`errors()`](#errors) for thrown errors.
157
-
158
- ## state
159
-
160
- ```ts
161
- function state(): TestSuiteState
162
- ```
163
-
164
- Checks the running state of the suite. Possible return values:
165
-
166
- - **pending**: the tests in this suite did not finish running yet.
167
- - **failed**: this suite has failed tests or they couldn't be collected. If [`errors()`](#errors) is not empty, it means the suite failed to collect tests.
168
- - **passed**: every test inside this suite has passed.
169
- - **skipped**: this suite was skipped during collection.
170
-
171
- ::: warning
172
- Note that [test module](/api/advanced/test-module) also has a `state` method that returns the same values, but it can also return an additional `queued` state if the module wasn't executed yet.
173
- :::
174
-
175
- ## errors
176
-
177
- ```ts
178
- function errors(): TestError[]
179
- ```
180
-
181
- Errors that happened outside of the test run during collection, like syntax errors.
182
-
183
- ```ts {4}
184
- import { describe } from 'vitest'
185
-
186
- describe('collection failed', () => {
187
- throw new Error('a custom error')
188
- })
189
- ```
190
-
191
- ::: warning
192
- Note that errors are serialized into simple objects: `instanceof Error` will always return `false`.
193
- :::
194
-
195
- ## meta <Version>3.1.0</Version> {#meta}
196
-
197
- ```ts
198
- function meta(): TaskMeta
199
- ```
200
-
201
- Custom [metadata](/api/advanced/metadata) that was attached to the suite during its execution or collection. Since Vitest 4.1, the meta can be attached by providing a `meta` object during test collection:
202
-
203
- ```ts {7,10}
204
- import { describe, test, TestRunner } from 'vitest'
205
-
206
- describe('the validation works correctly', { meta: { decorated: true } }, () => {
207
- test('some test', ({ task }) => {
208
- // assign "decorated" during test run, it will be available
209
- // only in onTestCaseReady hook
210
- task.suite.meta.decorated = false
211
-
212
- // tests inherit suite's metadata
213
- task.meta.decorated === true
214
- })
215
- })
216
- ```
217
-
218
- Note that suite metadata will be inherited by tests since Vitest 4.1.
219
-
220
- :::tip
221
- If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter.
222
- :::
223
-
224
- ## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
225
-
226
- ```ts
227
- function toTestSpecification(): TestSpecification
228
- ```
229
-
230
- Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test suite.