@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,334 +0,0 @@
1
- # Runner API <Badge type="danger">advanced</Badge>
2
-
3
- ::: warning
4
- This is advanced API. If you just want to [run tests](/guide/), you probably don't need this. It is primarily used by library authors.
5
- :::
6
-
7
- You can specify a path to your test runner with the `runner` option in your configuration file. This file should have a default export with a class constructor implementing these methods:
8
-
9
- ```ts
10
- export interface VitestRunner {
11
- /**
12
- * First thing that's getting called before actually collecting and running tests.
13
- */
14
- onBeforeCollect?: (paths: string[]) => unknown
15
- /**
16
- * Called after collecting tests and before "onBeforeRun".
17
- */
18
- onCollected?: (files: File[]) => unknown
19
-
20
- /**
21
- * Called when test runner should cancel next test runs.
22
- * Runner should listen for this method and mark tests and suites as skipped in
23
- * "onBeforeRunSuite" and "onBeforeRunTask" when called.
24
- */
25
- onCancel?: (reason: CancelReason) => unknown
26
-
27
- /**
28
- * Called before running a single test. Doesn't have "result" yet.
29
- */
30
- onBeforeRunTask?: (test: Test) => unknown
31
- /**
32
- * Called before actually running the test function. Already has "result" with "state" and "startTime".
33
- */
34
- onBeforeTryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
35
- /**
36
- * Called after result and state are set.
37
- */
38
- onAfterRunTask?: (test: Test) => unknown
39
- /**
40
- * Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
41
- */
42
- onAfterTryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
43
- /**
44
- * Called after the retry resolution happened. Unlike `onAfterTryTask`, the test now has a new state.
45
- * All `after` hooks were also called by this point.
46
- */
47
- onAfterRetryTask?: (test: Test, options: { retry: number; repeats: number }) => unknown
48
-
49
- /**
50
- * Called before running a single suite. Doesn't have "result" yet.
51
- */
52
- onBeforeRunSuite?: (suite: Suite) => unknown
53
- /**
54
- * Called after running a single suite. Has state and result.
55
- */
56
- onAfterRunSuite?: (suite: Suite) => unknown
57
-
58
- /**
59
- * If defined, will be called instead of usual Vitest suite partition and handling.
60
- * "before" and "after" hooks will not be ignored.
61
- */
62
- runSuite?: (suite: Suite) => Promise<void>
63
- /**
64
- * If defined, will be called instead of usual Vitest handling. Useful, if you have your custom test function.
65
- * "before" and "after" hooks will not be ignored.
66
- */
67
- runTask?: (test: TaskPopulated) => Promise<void>
68
-
69
- /**
70
- * Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.
71
- */
72
- onTaskUpdate?: (task: [string, TaskResult | undefined, TaskMeta | undefined][]) => Promise<void>
73
-
74
- /**
75
- * Called before running all tests in collected paths.
76
- */
77
- onBeforeRunFiles?: (files: File[]) => unknown
78
- /**
79
- * Called right after running all tests in collected paths.
80
- */
81
- onAfterRunFiles?: (files: File[]) => unknown
82
- /**
83
- * Called when new context for a test is defined. Useful, if you want to add custom properties to the context.
84
- * If you only want to define custom context with a runner, consider using "beforeAll" in "setupFiles" instead.
85
- */
86
- extendTaskContext?: (context: TestContext) => TestContext
87
- /**
88
- * Called when certain files are imported. Can be called in two situations: to collect tests and to import setup files.
89
- */
90
- importFile: (filepath: string, source: VitestRunnerImportSource) => unknown
91
- /**
92
- * Function that is called when the runner attempts to get the value when `test.extend` is used with `{ injected: true }`
93
- */
94
- injectValue?: (key: string) => unknown
95
- /**
96
- * Publicly available configuration.
97
- */
98
- config: VitestRunnerConfig
99
- /**
100
- * The name of the current pool. Can affect how stack trace is inferred on the server side.
101
- */
102
- pool?: string
103
- }
104
- ```
105
-
106
- When initiating this class, Vitest passes down Vitest config, - you should expose it as a `config` property:
107
-
108
- ```ts [runner.ts]
109
- import type { RunnerTestFile, SerializedConfig, TestRunner, VitestTestRunner } from 'vitest'
110
-
111
- class CustomRunner extends TestRunner implements VitestTestRunner {
112
- public config: SerializedConfig
113
-
114
- constructor(config: SerializedConfig) {
115
- this.config = config
116
- }
117
-
118
- onAfterRunFiles(files: RunnerTestFile[]) {
119
- console.log('finished running', files)
120
- }
121
- }
122
-
123
- export default CustomRunner
124
- ```
125
-
126
- ::: warning
127
- Vitest also injects an instance of `ModuleRunner` from `vite/module-runner` as `moduleRunner` property. You can use it to process files in `importFile` method (this is default behavior of `TestRunner` and `BenchmarkRunner`).
128
-
129
- `ModuleRunner` exposes `import` method, which is used to import test files in a Vite-friendly environment. Meaning, it will resolve imports and transform file content at runtime so that Node can understand it:
130
-
131
- ```ts
132
- export default class Runner {
133
- async importFile(filepath: string) {
134
- await this.moduleRunner.import(filepath)
135
- }
136
- }
137
- ```
138
- :::
139
-
140
- ::: warning
141
- If you don't have a custom runner or didn't define `runTest` method, Vitest will try to retrieve a task automatically. If you didn't add a function with `setFn`, it will fail.
142
- :::
143
-
144
- ::: tip
145
- Snapshot support and some other features depend on the runner. If you don't want to lose it, you can extend your runner from `VitestTestRunner` imported from `vitest/runners`. It also exposes `NodeBenchmarkRunner`, if you want to extend benchmark functionality.
146
- :::
147
-
148
- ## Tasks
149
-
150
- ::: warning
151
- The "Runner Tasks API" is experimental and should primarily be used only in the test runtime. Vitest also exposes the ["Reported Tasks API"](/api/advanced/test-module), which should be preferred when working in the main thread (inside the reporter, for example).
152
-
153
- The team is currently discussing if "Runner Tasks" should be replaced by "Reported Tasks" in the future.
154
- :::
155
-
156
- Suites and tests are called `tasks` internally. Vitest runner initiates a `File` task before collecting any tests - this is a superset of `Suite` with a few additional properties. It is available on every task (including `File`) as a `file` property.
157
-
158
- ```ts
159
- interface File extends Suite {
160
- /**
161
- * The name of the pool that the file belongs to.
162
- * @default 'forks'
163
- */
164
- pool?: string
165
- /**
166
- * The path to the file in UNIX format.
167
- */
168
- filepath: string
169
- /**
170
- * The name of the test project the file belongs to.
171
- */
172
- projectName: string | undefined
173
- /**
174
- * The time it took to collect all tests in the file.
175
- * This time also includes importing all the file dependencies.
176
- */
177
- collectDuration?: number
178
- /**
179
- * The time it took to import the setup file.
180
- */
181
- setupDuration?: number
182
- }
183
- ```
184
-
185
- Every suite has a `tasks` property that is populated during collection phase. It is useful to traverse the task tree from the top down.
186
-
187
- ```ts
188
- interface Suite extends TaskBase {
189
- type: 'suite'
190
- /**
191
- * File task. It's the root task of the file.
192
- */
193
- file: File
194
- /**
195
- * An array of tasks that are part of the suite.
196
- */
197
- tasks: Task[]
198
- }
199
- ```
200
-
201
- Every task has a `suite` property that references a suite it is located in. If `test` or `describe` are initiated at the top level, they will not have a `suite` property (it will **not** be equal to `file`!). `File` also never has a `suite` property. It is useful to traverse the tasks from the bottom up.
202
-
203
- ```ts
204
- interface Test<ExtraContext = object> extends TaskBase {
205
- type: 'test'
206
- /**
207
- * Test context that will be passed to the test function.
208
- */
209
- context: TestContext & ExtraContext
210
- /**
211
- * File task. It's the root task of the file.
212
- */
213
- file: File
214
- /**
215
- * Whether the task was skipped by calling `context.skip()`.
216
- */
217
- pending?: boolean
218
- /**
219
- * Whether the task should succeed if it fails. If the task fails, it will be marked as passed.
220
- */
221
- fails?: boolean
222
- /**
223
- * Store promises (from async expects) to wait for them before finishing the test
224
- */
225
- promises?: Promise<any>[]
226
- }
227
- ```
228
-
229
- Every task can have a `result` field. Suites can only have this field if an error thrown within a suite callback or `beforeAll`/`afterAll` callbacks prevents them from collecting tests. Tests always have this field after their callbacks are called - the `state` and `errors` fields are present depending on the outcome. If an error was thrown in `beforeEach` or `afterEach` callbacks, the thrown error will be present in `task.result.errors`.
230
-
231
- ```ts
232
- export interface TaskResult {
233
- /**
234
- * State of the task. Inherits the `task.mode` during collection.
235
- * When the task has finished, it will be changed to `pass` or `fail`.
236
- * - **pass**: task ran successfully
237
- * - **fail**: task failed
238
- */
239
- state: TaskState
240
- /**
241
- * Errors that occurred during the task execution. It is possible to have several errors
242
- * if `expect.soft()` failed multiple times.
243
- */
244
- errors?: TestError[]
245
- /**
246
- * How long in milliseconds the task took to run.
247
- */
248
- duration?: number
249
- /**
250
- * Time in milliseconds when the task started running.
251
- */
252
- startTime?: number
253
- /**
254
- * Heap size in bytes after the task finished.
255
- * Only available if `logHeapUsage` option is set and `process.memoryUsage` is defined.
256
- */
257
- heap?: number
258
- /**
259
- * State of related to this task hooks. Useful during reporting.
260
- */
261
- hooks?: Partial<Record<'afterAll' | 'beforeAll' | 'beforeEach' | 'afterEach', TaskState>>
262
- /**
263
- * The amount of times the task was retried. The task is retried only if it
264
- * failed and `retry` option is set.
265
- */
266
- retryCount?: number
267
- /**
268
- * The amount of times the task was repeated. The task is repeated only if
269
- * `repeats` option is set. This number also contains `retryCount`.
270
- */
271
- repeatCount?: number
272
- }
273
- ```
274
-
275
- ## Your Task Function
276
-
277
- Vitest exposes `createTaskCollector` utility to create your own `test` method. It behaves the same way as a test, but calls a custom method during collection.
278
-
279
- A task is an object that is part of a suite. It is automatically added to the current suite with a `suite.task` method:
280
-
281
- ```js [custom.js]
282
- export { afterAll, beforeAll, describe, TestRunner } from 'vitest'
283
-
284
- // this function will be called during collection phase:
285
- // don't call function handler here, add it to suite tasks
286
- // with "getCurrentSuite().task()" method
287
- // note: createTaskCollector provides support for "todo"/"each"/...
288
- export const myCustomTask = TestRunner.createTaskCollector(
289
- function (name, fn, timeout) {
290
- TestRunner.getCurrentSuite().task(name, {
291
- ...this, // so "todo"/"skip"/... is tracked correctly
292
- meta: {
293
- customPropertyToDifferentiateTask: true
294
- },
295
- handler: fn,
296
- timeout,
297
- })
298
- }
299
- )
300
- ```
301
-
302
- ```js [tasks.test.js]
303
- import {
304
- afterAll,
305
- beforeAll,
306
- describe,
307
- myCustomTask
308
- } from './custom.js'
309
- import { gardener } from './gardener.js'
310
-
311
- describe('take care of the garden', () => {
312
- beforeAll(() => {
313
- gardener.putWorkingClothes()
314
- })
315
-
316
- myCustomTask('weed the grass', () => {
317
- gardener.weedTheGrass()
318
- })
319
- myCustomTask.todo('mow the lawn', () => {
320
- gardener.mowerTheLawn()
321
- })
322
- myCustomTask('water flowers', () => {
323
- gardener.waterFlowers()
324
- })
325
-
326
- afterAll(() => {
327
- gardener.goHome()
328
- })
329
- })
330
- ```
331
-
332
- ```bash
333
- vitest ./garden/tasks.test.js
334
- ```
@@ -1,302 +0,0 @@
1
- # TestCase
2
-
3
- The `TestCase` class represents a single test. 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 `TestCase` instance always has a `type` property with the value of `test`. You can use it to distinguish between different task types:
6
-
7
- ```ts
8
- if (task.type === 'test') {
9
- task // TestCase
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 test name that was passed to the `test` function.
24
-
25
- ```ts
26
- import { test } from 'vitest'
27
-
28
- // [!code word:'the validation works correctly']
29
- test('the validation works correctly', () => {
30
- // ...
31
- })
32
- ```
33
-
34
- ## fullName
35
-
36
- The name of the test including all parent suites separated with `>` symbol. This test has a full name "the validation logic > the validation works correctly":
37
-
38
- ```ts
39
- import { describe, test } from 'vitest'
40
-
41
- // [!code word:'the validation works correctly']
42
- // [!code word:'the validation logic']
43
- describe('the validation logic', () => {
44
- test('the validation works correctly', () => {
45
- // ...
46
- })
47
- })
48
- ```
49
-
50
- ## id
51
-
52
- This is test's unique identifier. This ID is deterministic and will be the same for the same test across multiple runs. The ID is based on the [project](/api/advanced/test-project) name, module ID and test order.
53
-
54
- The ID looks like this:
55
-
56
- ```
57
- 1223128da3_0_0
58
- ^^^^^^^^^^ the file hash
59
- ^ suite index
60
- ^ test index
61
- ```
62
-
63
- ::: tip
64
- You can generate file hash with `generateFileHash` function from `vitest/node` which is available since Vitest 3:
65
-
66
- ```ts
67
- import { generateFileHash } from 'vitest/node'
68
-
69
- const hash = generateFileHash(
70
- '/file/path.js', // relative path
71
- undefined, // the project name or `undefined` is not set
72
- )
73
- ```
74
- :::
75
-
76
- ::: danger
77
- Don't try to parse the ID. It can have a minus at the start: `-1223128da3_0_0_0`.
78
- :::
79
-
80
- ## location
81
-
82
- The location in the module where the test 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.
83
-
84
- The location of this test will be equal to `{ line: 3, column: 1 }`:
85
-
86
- ```ts:line-numbers {3}
87
- import { test } from 'vitest'
88
-
89
- test('the validation works correctly', () => {
90
- // ...
91
- })
92
- ```
93
-
94
- ## parent
95
-
96
- Parent [suite](/api/advanced/test-suite). If the test was called directly inside the [module](/api/advanced/test-module), the parent will be the module itself.
97
-
98
- ## options
99
-
100
- ```ts
101
- interface TaskOptions {
102
- readonly each: boolean | undefined
103
- readonly fails: boolean | undefined
104
- readonly concurrent: boolean | undefined
105
- readonly shuffle: boolean | undefined
106
- readonly retry: number | undefined
107
- readonly repeats: number | undefined
108
- readonly tags: string[] | undefined
109
- readonly timeout: number | undefined
110
- readonly mode: 'run' | 'only' | 'skip' | 'todo'
111
- }
112
- ```
113
-
114
- The options that test was collected with.
115
-
116
- ## tags <Version>4.1.0</Version> {#tags}
117
-
118
- [Tags](/guide/test-tags) that were implicitly or explicitly assigned to the test.
119
-
120
- ## ok
121
-
122
- ```ts
123
- function ok(): boolean
124
- ```
125
-
126
- Checks if the test did not fail the suite. If the test is not finished yet or was skipped, it will return `true`.
127
-
128
- ## meta
129
-
130
- ```ts
131
- function meta(): TaskMeta
132
- ```
133
-
134
- Custom [metadata](/api/advanced/metadata) that was attached to the test during its execution. The meta can be attached by assigning a property to the `ctx.task.meta` object during a test run:
135
-
136
- ```ts {3,6}
137
- import { test } from 'vitest'
138
-
139
- test('the validation works correctly', ({ task }) => {
140
- // ...
141
-
142
- task.meta.decorated = false
143
- })
144
- ```
145
-
146
- If the test did not finish running yet, the meta will be an empty object, unless it has static meta:
147
-
148
- ```ts
149
- test('the validation works correctly', { meta: { decorated: true } })
150
- ```
151
-
152
- Since Vitest 4.1, Vitest inherits [`meta`](/api/advanced/test-suite#meta) property defined on the [suite](/api/advanced/test-suite).
153
-
154
- ## result
155
-
156
- ```ts
157
- function result(): TestResult
158
- ```
159
-
160
- Test results. If test is not finished yet or was just collected, it will be equal to `TestResultPending`:
161
-
162
- ```ts
163
- export interface TestResultPending {
164
- /**
165
- * The test was collected, but didn't finish running yet.
166
- */
167
- readonly state: 'pending'
168
- /**
169
- * Pending tests have no errors.
170
- */
171
- readonly errors: undefined
172
- }
173
- ```
174
-
175
- If the test was skipped, the return value will be `TestResultSkipped`:
176
-
177
- ```ts
178
- interface TestResultSkipped {
179
- /**
180
- * The test was skipped with `skip` or `todo` flag.
181
- * You can see which one was used in the `options.mode` option.
182
- */
183
- readonly state: 'skipped'
184
- /**
185
- * Skipped tests have no errors.
186
- */
187
- readonly errors: undefined
188
- /**
189
- * A custom note passed down to `ctx.skip(note)`.
190
- */
191
- readonly note: string | undefined
192
- }
193
- ```
194
-
195
- ::: tip
196
- If the test was skipped because another test has `only` flag, the `options.mode` will be equal to `skip`.
197
- :::
198
-
199
- If the test failed, the return value will be `TestResultFailed`:
200
-
201
- ```ts
202
- interface TestResultFailed {
203
- /**
204
- * The test failed to execute.
205
- */
206
- readonly state: 'failed'
207
- /**
208
- * Errors that were thrown during the test execution.
209
- */
210
- readonly errors: ReadonlyArray<TestError>
211
- }
212
- ```
213
-
214
- If the test passed, the return value will be `TestResultPassed`:
215
-
216
- ```ts
217
- interface TestResultPassed {
218
- /**
219
- * The test passed successfully.
220
- */
221
- readonly state: 'passed'
222
- /**
223
- * Errors that were thrown during the test execution.
224
- */
225
- readonly errors: ReadonlyArray<TestError> | undefined
226
- }
227
- ```
228
-
229
- ::: warning
230
- Note that the test with `passed` state can still have errors attached - this can happen if `retry` was triggered at least once.
231
- :::
232
-
233
- ## diagnostic
234
-
235
- ```ts
236
- function diagnostic(): TestDiagnostic | undefined
237
- ```
238
-
239
- Useful information about the test like duration, memory usage, etc:
240
-
241
- ```ts
242
- interface TestDiagnostic {
243
- /**
244
- * If the duration of the test is above `slowTestThreshold`.
245
- */
246
- readonly slow: boolean
247
- /**
248
- * The amount of memory used by the test in bytes.
249
- * This value is only available if the test was executed with `logHeapUsage` flag.
250
- */
251
- readonly heap: number | undefined
252
- /**
253
- * The time it takes to execute the test in ms.
254
- */
255
- readonly duration: number
256
- /**
257
- * The time in ms when the test started.
258
- */
259
- readonly startTime: number
260
- /**
261
- * The amount of times the test was retried.
262
- */
263
- readonly retryCount: number
264
- /**
265
- * The amount of times the test was repeated as configured by `repeats` option.
266
- * This value can be lower if the test failed during the repeat and no `retry` is configured.
267
- */
268
- readonly repeatCount: number
269
- /**
270
- * If test passed on a second retry.
271
- */
272
- readonly flaky: boolean
273
- }
274
- ```
275
-
276
- ::: info
277
- `diagnostic()` will return `undefined` if the test was not scheduled to run yet.
278
- :::
279
-
280
- ## annotations
281
-
282
- ```ts
283
- function annotations(): ReadonlyArray<TestAnnotation>
284
- ```
285
-
286
- [Test annotations](/guide/test-annotations) added via the [`task.annotate`](/guide/test-context#annotate) API during the test execution.
287
-
288
- ## artifacts <Version type="experimental">4.0.11</Version> <Experimental /> {#artifacts}
289
-
290
- ```ts
291
- function artifacts(): ReadonlyArray<TestArtifact>
292
- ```
293
-
294
- [Test artifacts](/api/advanced/artifacts) recorded via the `recordArtifact` API during the test execution.
295
-
296
- ## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
297
-
298
- ```ts
299
- function toTestSpecification(): TestSpecification
300
- ```
301
-
302
- Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test case.